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

@ -6,26 +6,12 @@ import {
getUserByID,
groups,
users,
pools
} from './data';
export const router = Router();
router.get('/user/:userID', (req, res) => {
if (typeof req.query.userID != 'string') {
return;
}
let userID = req.query.userID;
let user = getUserByID(userID);
if (user) {
res.json({ status: 'success', data: user });
} else {
res.json({ status: 'error', error: 'not_found' });
}
});
router.post('/user', (req, res) => {
router.get('/user', (req, res) => {
if (typeof req.query.userID != 'string') {
return;
}
@ -74,31 +60,34 @@ router.get('/pool', (req, res) => {
}
});
router.get('/group/:groupID', (req, res) => {
if (!(req.params.groupID in groups)) {
res.send('invalid group id');
return;
}
res.json(groups[req.params.groupID]);
router.post('/pool', (req, res) => {
if(req.body.poolID in pools) {
res.json({status: 'error', error: 'already_exists'});
}
else {
pools[req.body.poolID] = {
id: req.body.poolID,
title: req.body.title,
description: req.body.description,
participant_ids: [],
driver_id: 'no driver',
create_time: 'create time',
update_time: 'update time',
comments: [],
group_id: 'no group',
status: 'pending',
capacity: 0,
direction: 'pickup',
author_id: 'no author',
type: 'request'
}
res.json({status: 'success'});
}
});
router.post('/group', (req, res) => {
groups[req.body.title] = {
id: 'temp id 0',
member_ids: [],
};
});
router.patch('/group', (req, res) => {});
router.delete('/group', (req, res) => {
delete groups[req.body.groupID];
});
router.get('/my_pools', (req, res) => {
let userID = 'myfatemi04';
let poolIDs = getPoolsWithUser(userID);
res.json({ status: 'success', data: poolIDs.map((id) => getPoolByID(id)) });
router.delete('/pool', (req, res) => {
delete pools[req.body.poolID];
res.json({status: 'success'});
});
router.get('/group', (req, res) => {
@ -115,3 +104,60 @@ router.get('/group', (req, res) => {
res.json({ status: 'error', error: 'not_found' });
}
});
router.post('/group', (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'});
}
});
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'});
}
});