From f106ad8a77dd0e6f8f7e447729f04cfa2f8fe837 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 13:14:12 -0400 Subject: [PATCH] add GET /my_pools --- src/api.ts | 13 +++++++++- src/data.ts | 8 +++--- src/index.ts | 72 +++++++++++++--------------------------------------- 3 files changed, 34 insertions(+), 59 deletions(-) diff --git a/src/api.ts b/src/api.ts index dbfc7ba..301cd1a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,5 +1,10 @@ import { Router } from 'express'; -import { getGroupByID, getPoolByID, getUserByID } from './data'; +import { + getGroupByID, + getPoolByID, + getPoolsWithUser, + getUserByID, +} from './data'; export const router = Router(); @@ -33,6 +38,12 @@ router.get('/pool', (req, res) => { } }); +router.get('/my_pools', (req, res) => { + let userID = 'myfatemi04'; + let poolIDs = getPoolsWithUser(userID); + res.json({ status: 'success', data: poolIDs.map((id) => getPoolByID(id)) }); +}); + router.get('/group', (req, res) => { if (typeof req.query.groupID != 'string') { return; diff --git a/src/data.ts b/src/data.ts index 36b3426..e49acac 100644 --- a/src/data.ts +++ b/src/data.ts @@ -40,15 +40,15 @@ export function getGroupsWithUser(userID: string) { * @param userID The userID to find * @returns The post IDs with that userID as the author */ -export function getPostsByUser(userID: string) { - let postIDs = []; +export function getPoolsWithUser(userID: string) { + let poolIDs: string[] = []; for (let post of Object.values(pools)) { if (post.author_id == userID) { - postIDs.push(post.id); + poolIDs.push(post.id); } } - return postIDs; + return poolIDs; } export function getUserByID(userID: string): Carpool.User | undefined { diff --git a/src/index.ts b/src/index.ts index 2451ee0..965494c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,73 +1,37 @@ -import * as express from "express"; +import * as express from 'express'; const app = express(); +app.get('/user', (req, res) => {}); -app.get("/user", (req, res) => { - -}); +app.post('/user', (req, res) => {}); -app.post('/user', (req, res) => { +app.patch('/user', (req, res) => {}); -}); +app.delete('/user', (req, res) => {}); -app.patch('/user', (req, res) => { +app.get('/pool', (req, res) => {}); -}); +app.post('/pool', (req, res) => {}); -app.delete('/user', (req, res) => { +app.patch('/pool', (req, res) => {}); -}); +app.delete('/pool', (req, res) => {}); +app.get('/group', (req, res) => {}); -app.get("/pool", (req, res) => { - -}); +app.post('/group', (req, res) => {}); -app.post('/pool', (req, res) => { +app.patch('/group', (req, res) => {}); -}); +app.delete('/group', (req, res) => {}); -app.patch('/pool', (req, res) => { +app.get('/join_pool', (req, res) => {}); -}); +app.post('/join_pool', (req, res) => {}); -app.delete('/pool', (req, res) => { +app.patch('/join_pool', (req, res) => {}); -}); +app.delete('/join_pool', (req, res) => {}); - -app.get("/group", (req, res) => { - -}); - -app.post('/group', (req, res) => { - -}); - -app.patch('/group', (req, res) => { - -}); - -app.delete('/group', (req, res) => { - -}); - - -app.get("/join_pool", (req, res) => { - -}); - -app.post('/join_pool', (req, res) => { - -}); - -app.patch('/join_pool', (req, res) => { - -}); - -app.delete('/join_pool', (req, res) => { - -}); - -app.listen(80, () => void console.log("Listening on port 80")); +app.listen(80, () => void console.log('Listening on port 80'));