frontend et backend: Supprimer un commentaire

This commit is contained in:
Divlo
2020-04-10 20:58:19 +02:00
parent 39a332a867
commit 0ac2fbf3ab
4 changed files with 45 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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