add simple accessor methods

This commit is contained in:
Michael Fatemi 2021-04-10 11:32:02 -04:00
parent 8d453e7ba9
commit 142c1c7dd6
3 changed files with 45 additions and 5 deletions

View File

@ -1,9 +1,46 @@
/**
* Records users by id
*/
let users: Record<string, Carpool.User> = {};
export const users: Record<string, Carpool.User> = {};
/**
* Records groups by id
*/
let groups: Record<string, Carpool.Group> = {};
export const groups: Record<string, Carpool.Group> = {};
/**
* Records posts by id
*/
export const posts: Record<string, Carpool.Post> = {};
/**
*
* @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;
}

View File

@ -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'));

View File

@ -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';
}
}