multy-stub/server/routers/todo/routes.js
Primakov Alexandr Alexandrovich fb644b6f7b create todo list
2025-01-18 16:50:58 +03:00

25 lines
681 B
JavaScript

const { Router } = require('express')
const { expressjwt } = require('express-jwt')
const { getAnswer } = require('../../utils/common')
const { ListModel } = require('./model/todo/list')
const { ItemModel } = require('./model/todo/item')
const { TOKEN_KEY } = require('./const')
const { requiredValidate } = require('./utils')
const router = Router()
router.use(expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] }))
router.post('/', requiredValidate('title'), async (req, res) => {
const { title } = req.body
const userId = req.auth.id
const list = await ListModel.create({ title, createdBy: userId })
res.send(getAnswer(null, list))
})
module.exports = router