wheelshare-old-backend/src/data.ts
2021-04-10 13:14:12 -04:00

65 lines
1.3 KiB
TypeScript

/**
* Records users by id
*/
export const users: Record<string, Carpool.User> = {
myfatemi04: {
id: 'myfatemi04',
first_name: 'Michael',
last_name: 'Fatemi',
},
};
/**
* Records groups by id
*/
export const groups: Record<string, Carpool.Group> = {};
/**
* Records pools by id
*/
export const pools: Record<string, Carpool.Pool> = {};
/**
*
* @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 getPoolsWithUser(userID: string) {
let poolIDs: string[] = [];
for (let post of Object.values(pools)) {
if (post.author_id == userID) {
poolIDs.push(post.id);
}
}
return poolIDs;
}
export function getUserByID(userID: string): Carpool.User | undefined {
return users[userID];
}
export function getPoolByID(poolID: string): Carpool.Pool | undefined {
return pools[poolID];
}
export function getGroupByID(groupID: string): Carpool.Group | undefined {
return groups[groupID];
}