API Migrada
This commit is contained in:
22
routes/comments.js
Normal file
22
routes/comments.js
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user