This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
qoverflow/server/routes/question/DeleteAnswerComment.js

32 lines
966 B
JavaScript

const Comment = require('../../db/models/Comment');
const config = require('../../config.json');
const createRequest = require('../../utils/api');
async function DeleteAnswerComment(req, res) {
const { user } = req;
const { question_id, answer_id, comment_id } = req.params;
const comment = await Comment.findById(comment_id);
// Verify comment exists
if (!comment) return res.status(404).send(config.errorNotFound);
// Verify user is creator
if (comment.creator !== user.username) {
return res.status(403).send(config.errorForbidden);
}
// Delete question with BDPA server
const { success } = await createRequest(
'delete',
`/questions/${question_id}/answers/${answer_id}/comments/${comment_id}`
);
if (!success) return res.status(500).send(config.errorGeneric);
await Comment.findByIdAndDelete(comment_id);
return res.sendStatus(200);
}
module.exports = DeleteAnswerComment;