hacker-news-cli/api/comments.js
2019-02-15 17:59:55 -05:00

26 lines
612 B
JavaScript

const router = require('express').Router()
const { Comment } = require('../db/models')
const buildPage = require('../scripts/buildPage')
module.exports = router
router.get('/', async (req, res, next) => {
try {
const comments = await Comment.findAll({
attributes: ['id', 'title', 'content', 'userId', 'parentId']
})
} catch (err) {
next(err)
}
})
router.post('/', async (req, res, next) => {
const newComment = req.body // good sanitization
try {
const comment = await Comment.create(newComment)
res.redirect('http://localhost:1337')
} catch (err) {
next(err)
}
})