From 15cfc129a57d192423cbcfc8ca823eb1e83fe641 Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Alexandrovich Date: Sun, 19 Jan 2025 22:23:19 +0300 Subject: [PATCH] todo-app: wome routes without jwt --- server/routers/todo/routes.js | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/server/routers/todo/routes.js b/server/routers/todo/routes.js index fbf474b..6c6a3cf 100644 --- a/server/routers/todo/routes.js +++ b/server/routers/todo/routes.js @@ -10,6 +10,30 @@ const { requiredValidate } = require('./utils') const router = Router() +router.get('/list', async (req, res) => { + const items = await ListModel + .find({}) + .populate('items') + .exec() + + res.send(getAnswer(null, items)) +}) + +router.get('/:todoId', async (req, res) => { + const { todoId } = req.params + + const list = await ListModel + .findById(todoId) + .populate('items') + .exec() + + if (!list) { + throw new Error('list not found') + } + + res.send(getAnswer(null, list)) +}) + router.use(expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] })) router.post('/', requiredValidate('title'), async (req, res) => { @@ -21,15 +45,6 @@ router.post('/', requiredValidate('title'), async (req, res) => { res.send(getAnswer(null, list)) }) -router.get('/list', async (req, res) => { - const items = await ListModel - .find({}) - .populate('items') - .exec() - - res.send(getAnswer(null, items)) -}) - router.post('/item', requiredValidate('todoId', 'title'), async (req, res) => { const { todoId, title } = req.body @@ -48,20 +63,5 @@ router.post('/item', requiredValidate('todoId', 'title'), async (req, res) => { res.send(getAnswer(null, item)) }) -router.get('/:todoId', async (req, res) => { - const { todoId } = req.params - - const list = await ListModel - .findById(todoId) - .populate('items') - .exec() - - if (!list) { - throw new Error('list not found') - } - - res.send(getAnswer(null, list)) -}) - module.exports = router