add GET /my_pools

This commit is contained in:
Michael Fatemi 2021-04-10 13:14:12 -04:00
parent 8c77b33061
commit f106ad8a77
3 changed files with 34 additions and 59 deletions

View File

@ -1,5 +1,10 @@
import { Router } from 'express'; import { Router } from 'express';
import { getGroupByID, getPoolByID, getUserByID } from './data'; import {
getGroupByID,
getPoolByID,
getPoolsWithUser,
getUserByID,
} from './data';
export const router = Router(); 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) => { router.get('/group', (req, res) => {
if (typeof req.query.groupID != 'string') { if (typeof req.query.groupID != 'string') {
return; return;

View File

@ -40,15 +40,15 @@ export function getGroupsWithUser(userID: string) {
* @param userID The userID to find * @param userID The userID to find
* @returns The post IDs with that userID as the author * @returns The post IDs with that userID as the author
*/ */
export function getPostsByUser(userID: string) { export function getPoolsWithUser(userID: string) {
let postIDs = []; let poolIDs: string[] = [];
for (let post of Object.values(pools)) { for (let post of Object.values(pools)) {
if (post.author_id == userID) { 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 { export function getUserByID(userID: string): Carpool.User | undefined {

View File

@ -1,73 +1,37 @@
import * as express from "express"; import * as express from 'express';
const app = 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.listen(80, () => void console.log('Listening on port 80'));
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"));