improve validation

This commit is contained in:
Michael Fatemi 2021-04-10 21:18:08 -04:00
parent f6e8c8f357
commit 85d54333be
2 changed files with 43 additions and 40 deletions

View File

@ -59,46 +59,49 @@ router.get('/pool', (req, res) => {
}); });
router.post('/pool', (req, res) => { router.post('/pool', (req, res) => {
// if (req.body.poolID in pools) { if (req.session.accountID == null) {
// res.json({ status: 'error', error: 'already_exists' }); res.status(401);
// } else { return res.json({ status: 'error', error: 'need_login' });
// pools[req.body.poolID] = { }
// id: req.body.poolID,
// title: req.body.title, const userID = req.session.accountID;
// description: req.body.description, const {
// participant_ids: [], capacity,
// driver_id: 'no driver', description,
// create_time: 'create time', direction,
// update_time: 'update time', end_time,
// comments: [], group_id,
// group_id: 'no group', start_time,
// status: 'pending', title,
// capacity: 0, type,
// direction: 'pickup', } = req.body;
// author_id: 'no author',
// type: 'request', const pool = new PoolModel();
// }; Object.assign(pool, {
// res.json({ status: 'success' }); author_id: userID,
// } capacity,
description,
direction,
status: 'pending',
title,
type,
participant_ids: [],
comments: [],
create_time: new Date().toISOString(),
update_time: new Date().toISOString(),
group_id,
}); });
router.patch('/pool', (req, res) => { pool
// if (!(req.body.poolID in pools)) { .save()
// res.json({ status: 'error', error: 'not_found' }); .then((pool) => {
// } else { res.json({ status: 'success', id: pool._id });
// let pool = pools[req.body.poolID]; })
// pool.title = req.body.title; .catch((err) => {
// pool.description = req.body.description; console.error('Error when creating a pool:', err);
// pool.driver_id = req.body.driver_id; res.json({ status: 'error' });
// pool.update_time = req.body.update_time; });
// pool.status = req.body.status;
// pool.capacity = req.body.capacity;
// pool.direction = req.body.direction;
// res.json({ status: 'success' });
// }
}); });
router.delete('/pool', (req, res) => {});
router.get('/group', async (req, res) => { router.get('/group', async (req, res) => {
if (typeof req.query.groupID != 'string') { if (typeof req.query.groupID != 'string') {

View File

@ -49,7 +49,7 @@ export interface Pool extends Document {
title: string; title: string;
description: string; description: string;
participant_ids: string[]; participant_ids: string[];
driver_id: string; driver_id?: string;
create_time: string; create_time: string;
update_time: string; update_time: string;
comments: Comment[]; comments: Comment[];
@ -65,7 +65,7 @@ const PoolSchema: Schema = new Schema({
title: { type: String, required: true }, title: { type: String, required: true },
description: { type: String, required: true }, description: { type: String, required: true },
participant_ids: { type: [String], required: true }, participant_ids: { type: [String], required: true },
driver_id: { type: String, required: true }, driver_id: { type: String, required: false },
create_time: { type: String, required: true }, create_time: { type: String, required: true },
update_time: { type: String, required: true }, update_time: { type: String, required: true },
comments: { type: [CommentSchema], required: true }, comments: { type: [CommentSchema], required: true },