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