From 94143bc4faf4bea8aee7c52f25cb49251631a95f Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sun, 11 Apr 2021 14:14:22 -0400 Subject: [PATCH] add posting comments --- src/api/pool.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/api/pool.ts b/src/api/pool.ts index 0e88dec..f94b3d1 100644 --- a/src/api/pool.ts +++ b/src/api/pool.ts @@ -5,6 +5,26 @@ import requireApiAuth from '../requireApiAuth'; export const router = Router(); +router.post('/:poolID/comment', requireApiAuth, async (req, res) => { + const userID = req.session.accountID; + const poolID = req.params.poolID; + const commentBody = req.body.body; + + await PoolModel.updateOne( + { _id: poolID }, + { + $push: { + comments: { + author_id: userID, + body: commentBody, + }, + }, + } + ).exec(); + + res.json({ status: 'success' }); +}); + router.post('/:poolID/join', async (req, res) => { const userID = req.session.accountID; const poolID = req.params.poolID;