From 142c1c7dd632671e07356e62df6235331f27273a Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 11:32:02 -0400 Subject: [PATCH] add simple accessor methods --- src/data.ts | 41 +++++++++++++++++++++++++++++++++++++++-- src/index.ts | 2 +- src/types.ts | 7 +++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/data.ts b/src/data.ts index a9497ce..7654e5e 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1,9 +1,46 @@ /** * Records users by id */ -let users: Record = {}; +export const users: Record = {}; /** * Records groups by id */ -let groups: Record = {}; +export const groups: Record = {}; + +/** + * Records posts by id + */ +export const posts: Record = {}; + +/** + * + * @param userID The userID to find + * @returns The group IDs with that userID as a member + */ +export function getGroupsWithUser(userID: string) { + let groupIDs = []; + for (let group of Object.values(groups)) { + if (group.member_ids.includes(userID)) { + groupIDs.push(group.id); + } + } + + return groupIDs; +} + +/** + * + * @param userID The userID to find + * @returns The post IDs with that userID as the author + */ +export function getPostsByUser(userID: string) { + let postIDs = []; + for (let post of Object.values(posts)) { + if (post.author_id == userID) { + postIDs.push(post.id); + } + } + + return postIDs; +} diff --git a/src/index.ts b/src/index.ts index 2f735e3..9e4608d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,4 +6,4 @@ app.get('/', (req, res) => { res.send('Hello!'); }); -app.listen(8080, () => void console.log('Listening on port 80')); +app.listen(8080, () => void console.log('Listening on port 8080')); diff --git a/src/types.ts b/src/types.ts index f03185b..e0e9966 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,7 +16,7 @@ namespace Carpool { author_id: string; } - export type Status = "pending" | "cancelled" | "completed" | "interrupted"; + export type Status = 'pending' | 'cancelled' | 'completed' | 'interrupted'; export interface Post { id: string; @@ -30,5 +30,8 @@ namespace Carpool { group_id: string; status: Status; capacity: number; + direction: 'pickup' | 'dropoff'; + author_id: string; + type: 'request' | 'offer'; } -} \ No newline at end of file +}