From 3d935af6f1b7a28df808a1710563c52ae58d3a3f Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Alexandrovich Date: Sun, 19 Jan 2025 22:35:22 +0300 Subject: [PATCH] fix get comments to unknown user --- server/routers/todo/comment.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/routers/todo/comment.js b/server/routers/todo/comment.js index a6e5b4e..8106528 100644 --- a/server/routers/todo/comment.js +++ b/server/routers/todo/comment.js @@ -10,6 +10,22 @@ const { TOKEN_KEY } = require('./const') const router = Router() +router.get('/:todoId/:itemId', async (req, res) => { + const { todoId, itemId } = req.params + + const todo = await ListModel.findById(todoId) + if (!todo) { + return res.send(getAnswer(new Error('no such todo'))) + } + + const item = await ItemModel.findById(itemId).populate({ path: 'comments', populate: { path: 'author' } }).exec() + if (!item) { + return res.send(getAnswer(new Error('no such item'))) + } + + res.send(getAnswer(null, item)) +}) + router.use(expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] })) router.post('/:todoId/:itemId', async (req, res) => { @@ -34,20 +50,4 @@ router.post('/:todoId/:itemId', async (req, res) => { res.send(getAnswer(null, comment)) }) -router.get('/:todoId/:itemId', async (req, res) => { - const { todoId, itemId } = req.params - - const todo = await ListModel.findById(todoId) - if (!todo) { - return res.send(getAnswer(new Error('no such todo'))) - } - - const item = await ItemModel.findById(itemId).populate({ path: 'comments', populate: { path: 'author' } }).exec() - if (!item) { - return res.send(getAnswer(new Error('no such item'))) - } - - res.send(getAnswer(null, item)) -}) - module.exports = router