📦 NEW: backend PUT /comments
This commit is contained in:
parent
6848c790ed
commit
ea5ee96845
@ -37,7 +37,7 @@ exports.postCommentsByFunctionId = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.deleteCommentById = async (req, res, next) => {
|
exports.deleteCommentById = async (req, res, next) => {
|
||||||
const { commentId } = req.query;
|
const { commentId } = req.params;
|
||||||
try {
|
try {
|
||||||
const comment = await Comments.findOne({ where: { userId: req.userId, id: parseInt(commentId) } });
|
const comment = await Comments.findOne({ where: { userId: req.userId, id: parseInt(commentId) } });
|
||||||
if (!comment) {
|
if (!comment) {
|
||||||
@ -50,3 +50,23 @@ exports.deleteCommentById = async (req, res, next) => {
|
|||||||
return errorHandling(next, serverError);
|
return errorHandling(next, serverError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.putCommentsById = async (req, res, next) => {
|
||||||
|
const { commentId } = req.params;
|
||||||
|
const { message } = req.body;
|
||||||
|
if (!message) {
|
||||||
|
return errorHandling(next, { message: "Vous ne pouvez pas poster de commentaire vide.", statusCode: 400 });
|
||||||
|
}
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
comment.message = message;
|
||||||
|
await comment.save();
|
||||||
|
return res.status(200).json({ message: "Le commentaire a bien été modifié." });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return errorHandling(next, serverError);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,10 @@ const isAuth = require('../middlewares/isAuth');
|
|||||||
|
|
||||||
const CommentsRouter = Router();
|
const CommentsRouter = Router();
|
||||||
|
|
||||||
CommentsRouter.route('/')
|
CommentsRouter.route('/:commentId')
|
||||||
|
|
||||||
|
// Modifier un commentaire
|
||||||
|
.put(isAuth, commentsController.putCommentsById)
|
||||||
|
|
||||||
// Supprime un commentaire
|
// Supprime un commentaire
|
||||||
.delete(isAuth, commentsController.deleteCommentById);
|
.delete(isAuth, commentsController.deleteCommentById);
|
||||||
|
@ -14,7 +14,7 @@ const CommentCard = forwardRef((props, ref) => {
|
|||||||
props.manageComment.setLoadingComments(true);
|
props.manageComment.setLoadingComments(true);
|
||||||
if (isAuth && user.token != undefined) {
|
if (isAuth && user.token != undefined) {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/comments?commentId=${props.id}`, { headers: { 'Authorization': user.token } });
|
await api.delete(`/comments/${props.id}`, { headers: { 'Authorization': user.token } });
|
||||||
const newCommentsData = { ...props.manageComment.commentsData };
|
const newCommentsData = { ...props.manageComment.commentsData };
|
||||||
const commentIndex = newCommentsData.rows.findIndex((value) => value.id === props.id);
|
const commentIndex = newCommentsData.rows.findIndex((value) => value.id === props.id);
|
||||||
newCommentsData.rows.splice(commentIndex, 1);
|
newCommentsData.rows.splice(commentIndex, 1);
|
||||||
|
@ -4,9 +4,6 @@ import ReactMarkdown from 'react-markdown/with-html';
|
|||||||
import HeadTag from '../components/HeadTag';
|
import HeadTag from '../components/HeadTag';
|
||||||
|
|
||||||
const About = (props) => {
|
const About = (props) => {
|
||||||
|
|
||||||
console.log(props);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<HeadTag
|
<HeadTag
|
||||||
|
Reference in New Issue
Block a user