mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 12:10:17 -04:00
add simple accessor methods
This commit is contained in:
parent
8d453e7ba9
commit
142c1c7dd6
41
src/data.ts
41
src/data.ts
|
@ -1,9 +1,46 @@
|
||||||
/**
|
/**
|
||||||
* Records users by id
|
* Records users by id
|
||||||
*/
|
*/
|
||||||
let users: Record<string, Carpool.User> = {};
|
export const users: Record<string, Carpool.User> = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records groups by id
|
* 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;
|
||||||
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ app.get('/', (req, res) => {
|
||||||
res.send('Hello!');
|
res.send('Hello!');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(8080, () => void console.log('Listening on port 80'));
|
app.listen(8080, () => void console.log('Listening on port 8080'));
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Carpool {
|
||||||
author_id: string;
|
author_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Status = "pending" | "cancelled" | "completed" | "interrupted";
|
export type Status = 'pending' | 'cancelled' | 'completed' | 'interrupted';
|
||||||
|
|
||||||
export interface Post {
|
export interface Post {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -30,5 +30,8 @@ namespace Carpool {
|
||||||
group_id: string;
|
group_id: string;
|
||||||
status: Status;
|
status: Status;
|
||||||
capacity: number;
|
capacity: number;
|
||||||
|
direction: 'pickup' | 'dropoff';
|
||||||
|
author_id: string;
|
||||||
|
type: 'request' | 'offer';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user