frontend et backend: Supprimer un commentaire
This commit is contained in:
@ -47,4 +47,19 @@ exports.postCommentsByFunctionId = async (req, res, next) => {
|
||||
console.log(error);
|
||||
return errorHandling(next, serverError);
|
||||
}
|
||||
}
|
||||
|
||||
exports.deleteCommentById = async (req, res, next) => {
|
||||
const { commentId } = req.query;
|
||||
try {
|
||||
const comment = await Comments.findOne({ where: { userId: req.userId, id: parseInt(commentId) } });
|
||||
if (!comment) {
|
||||
return errorHandling(next, { message: "Le commentaire n'existe pas.", statusCode: 404 });
|
||||
}
|
||||
await comment.destroy();
|
||||
return res.status(200).json({ message: "Le commentaire a bien été supprimé." });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return errorHandling(next, serverError);
|
||||
}
|
||||
}
|
@ -4,6 +4,11 @@ const isAuth = require('../middlewares/isAuth');
|
||||
|
||||
const CommentsRouter = Router();
|
||||
|
||||
CommentsRouter.route('/')
|
||||
|
||||
// Supprime un commentaire
|
||||
.delete(isAuth, commentsController.deleteCommentById);
|
||||
|
||||
CommentsRouter.route('/:functionId')
|
||||
|
||||
// Récupère les commentaires
|
||||
|
Reference in New Issue
Block a user