22 lines
841 B
JavaScript
22 lines
841 B
JavaScript
import { Router } from 'express';
|
|
import { createNewComment, getCommentsByPostId, deleteComment, getAllComments, getCommentById, editComment } from '../functions/commentFunctions.js';
|
|
const router = Router();
|
|
|
|
// Validate create comment payload
|
|
const validateCommentPayload = (req, res, next) => {
|
|
// ...simple validation...
|
|
const { contenido, id_usuario, id_post } = req.body;
|
|
if (!contenido || !id_usuario || !id_post) {
|
|
return res.status(400).json({ error: 'contenido, id_usuario and id_post are required' });
|
|
}
|
|
next();
|
|
};
|
|
|
|
router.post('/', validateCommentPayload, createNewComment);
|
|
router.get('/', getAllComments);
|
|
router.get('/post/:id_post', getCommentsByPostId);
|
|
router.get('/:id_comentario', getCommentById);
|
|
router.put('/:id_comentario', editComment);
|
|
router.delete('/:id_comentario', deleteComment);
|
|
|
|
export default router; |