From db69fa24433d5544e365731f1fc9fa7a608cc8df Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sun, 11 Apr 2021 04:06:34 -0400 Subject: [PATCH] feat: didn't go to sleep --- src/api/group.ts | 18 ++++++++++++++++-- src/api/pool.ts | 13 ++++++++++++- src/index.ts | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/api/group.ts b/src/api/group.ts index 7f9d442..2d2467c 100644 --- a/src/api/group.ts +++ b/src/api/group.ts @@ -11,6 +11,17 @@ router.get('/:groupID/pools', async (req, res) => { res.json({ status: 'success', data: pools }); }); +router.post('/:groupID/join', async (req, res) => { + const userID = req.session.accountID; + const groupID = req.params.groupID; + + await GroupModel.findByIdAndUpdate(groupID, { + $addToSet: { member_ids: userID }, + }).exec(); + + res.json({ status: 'success' }); +}); + router.get('/:groupID', async (req, res) => { let groupID = req.params.groupID; let group = await getGroupByID(groupID); @@ -27,8 +38,11 @@ router.post('/', async (req, res) => { const name = req.body.name; const group = new GroupModel(); - group.set('name', name); - group.set('creator_id', userID); + Object.assign(group, { + name: name, + member_ids: [userID], + creator_id: userID, + }); group .save() .then((group) => { diff --git a/src/api/pool.ts b/src/api/pool.ts index 6614a3f..0e88dec 100644 --- a/src/api/pool.ts +++ b/src/api/pool.ts @@ -16,6 +16,17 @@ router.post('/:poolID/join', async (req, res) => { res.json({ status: 'success' }); }); +router.post('/:poolID/leave', async (req, res) => { + const userID = req.session.accountID; + const poolID = req.params.poolID; + + await PoolModel.findByIdAndUpdate(poolID, { + $pull: { participant_ids: userID }, + }).exec(); + + res.json({ status: 'success' }); +}); + router.get('/:poolID', async (req, res) => { const pool = await PoolModel.findById(new ObjectID(req.params.poolID)).exec(); @@ -48,7 +59,7 @@ router.post('/', requireApiAuth, async (req, res) => { status: 'pending', title, type, - participant_ids: [], + participant_ids: [userID], comments: [], create_time: new Date().toISOString(), update_time: new Date().toISOString(), diff --git a/src/index.ts b/src/index.ts index 7c9c57b..6c5bb50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ mongoose.connect(process.env.DB_URL, { useNewUrlParser: true, useUnifiedTopology: true, }); +mongoose.set('useFindAndModify', false); if (!mongoose.connection) console.log('Error connecting to DB'); else console.log('DB connected successfully');