Add files via upload

This commit is contained in:
nkanchinadam 2021-04-10 14:32:25 -04:00 committed by GitHub
parent 7184974ab6
commit 1ddba82810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,117 +1,163 @@
import { Router } from 'express'; import { Router } from 'express';
import { import {
getGroupByID, getGroupByID,
getPoolByID, getPoolByID,
getPoolsWithUser, getPoolsWithUser,
getUserByID, getUserByID,
groups, groups,
users, users,
} from './data'; pools
} from './data';
export const router = Router();
export const router = Router();
router.get('/user/:userID', (req, res) => {
if (typeof req.query.userID != 'string') { router.get('/user', (req, res) => {
return; if (typeof req.query.userID != 'string') {
} return;
}
let userID = req.query.userID;
let user = getUserByID(userID); let userID = req.query.userID;
let user = getUserByID(userID);
if (user) {
res.json({ status: 'success', data: user }); if (user) {
} else { res.json({ status: 'success', data: user });
res.json({ status: 'error', error: 'not_found' }); } else {
} res.json({ status: 'error', error: 'not_found' });
}); }
});
router.post('/user', (req, res) => {
if (typeof req.query.userID != 'string') { router.post('/user', (req, res) => {
return; if (req.body.userID in users) {
} res.json({ status: 'error', error: 'already_exists' });
} else {
let userID = req.query.userID; users[req.body.userID] = {
let user = getUserByID(userID); id: req.body.userID,
username: req.body.username,
if (user) { first_name: req.body.first_name,
res.json({ status: 'success', data: user }); last_name: req.body.last_name,
} else { };
res.json({ status: 'error', error: 'not_found' }); res.json({ status: 'success' });
} }
}); });
router.post('/user', (req, res) => { router.delete('/user', (req, res) => {
if (req.body.userID in users) { delete users[req.body.userID];
res.json({ status: 'error', error: 'already_exists' }); res.json({ status: 'success' });
} else { });
users[req.body.userID] = {
id: req.body.userID, router.get('/pool', (req, res) => {
username: req.body.username, if (typeof req.query.poolID != 'string') {
first_name: req.body.first_name, return;
last_name: req.body.last_name, }
};
res.json({ status: 'success' }); let poolID = req.query.poolID;
} let pool = getPoolByID(poolID);
});
if (pool) {
router.delete('/user', (req, res) => { res.json({ status: 'success', data: pool });
delete users[req.body.userID]; } else {
res.json({ status: 'success' }); res.json({ status: 'error', error: 'not_found' });
}); }
});
router.get('/pool', (req, res) => {
if (typeof req.query.poolID != 'string') { router.post('/pool', (req, res) => {
return; if(req.body.poolID in pools) {
} res.json({status: 'error', error: 'already_exists'});
}
let poolID = req.query.poolID; else {
let pool = getPoolByID(poolID); pools[req.body.poolID] = {
id: req.body.poolID,
if (pool) { title: req.body.title,
res.json({ status: 'success', data: pool }); description: req.body.description,
} else { participant_ids: [],
res.json({ status: 'error', error: 'not_found' }); driver_id: 'no driver',
} create_time: 'create time',
}); update_time: 'update time',
comments: [],
router.get('/group/:groupID', (req, res) => { group_id: 'no group',
if (!(req.params.groupID in groups)) { status: 'pending',
res.send('invalid group id'); capacity: 0,
return; direction: 'pickup',
} author_id: 'no author',
res.json(groups[req.params.groupID]); type: 'request'
}); }
res.json({status: 'success'});
router.post('/group', (req, res) => { }
groups[req.body.title] = { });
id: 'temp id 0',
member_ids: [], router.delete('/pool', (req, res) => {
}; delete pools[req.body.poolID];
}); res.json({status: 'success'});
});
router.patch('/group', (req, res) => {});
router.get('/group', (req, res) => {
router.delete('/group', (req, res) => { if (typeof req.query.groupID != 'string') {
delete groups[req.body.groupID]; return;
}); }
router.get('/my_pools', (req, res) => { let groupID = req.query.groupID;
let userID = 'myfatemi04'; let group = getGroupByID(groupID);
let poolIDs = getPoolsWithUser(userID);
res.json({ status: 'success', data: poolIDs.map((id) => getPoolByID(id)) }); if (group) {
}); res.json({ status: 'success', data: group });
} else {
router.get('/group', (req, res) => { res.json({ status: 'error', error: 'not_found' });
if (typeof req.query.groupID != 'string') { }
return; });
}
router.post('/group', (req, res) => {
let groupID = req.query.groupID; if(req.body.groupID in groups) {
let group = getGroupByID(groupID); res.json({status: 'error', error: 'already_exists'});
}
if (group) { else {
res.json({ status: 'success', data: group }); groups[req.body.groupID] = {
} else { id: req.body.groupID,
res.json({ status: 'error', error: 'not_found' }); member_ids: []
} }
}); res.json({status: 'success'});
}
});
router.delete('/group', (req, res) => {
delete groups[req.body.groupID];
res.json({status: 'success'});
});
router.get('/my_pools', (req, res) => {
if (typeof req.query.userID != 'string') {
return;
}
let userID = req.query.userID;
let groupsWithUser = getPoolsWithUser(userID);
if (groupsWithUser) {
res.json({ status: 'success', data: groupsWithUser });
} else {
res.json({ status: 'error', error: 'not_found' });
}
});
router.post('/my_pools', (req, res) => {
if(req.body.groupID in groups) {
res.json({status: 'error', error: 'already_exists'});
}
else {
groups[req.body.groupID] = {
id: req.body.groupID,
member_ids: []
}
res.json({status: 'success'});
}
});