multy-stub/server/routers/todo/routes.js

25 lines
681 B
JavaScript
Raw Normal View History

2024-10-16 11:06:23 +03:00
const { Router } = require('express')
2025-01-18 16:50:58 +03:00
const { expressjwt } = require('express-jwt')
const { getAnswer } = require('../../utils/common')
2024-10-16 11:06:23 +03:00
2025-01-17 19:51:33 +03:00
const { ListModel } = require('./model/todo/list')
const { ItemModel } = require('./model/todo/item')
2025-01-18 16:50:58 +03:00
const { TOKEN_KEY } = require('./const')
const { requiredValidate } = require('./utils')
2024-10-16 11:06:23 +03:00
const router = Router()
2025-01-18 16:50:58 +03:00
router.use(expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] }))
2024-10-16 11:06:23 +03:00
2025-01-18 16:50:58 +03:00
router.post('/', requiredValidate('title'), async (req, res) => {
const { title } = req.body
const userId = req.auth.id
2024-10-16 11:06:23 +03:00
2025-01-18 16:50:58 +03:00
const list = await ListModel.create({ title, createdBy: userId })
2024-10-16 11:06:23 +03:00
res.send(getAnswer(null, list))
})
module.exports = router