todo-app: wome routes without jwt

This commit is contained in:
Primakov Alexandr Alexandrovich 2025-01-19 22:23:19 +03:00
parent 270fe51500
commit 15cfc129a5

View File

@ -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