if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res)) return
if (!isVideoCommentsEnabled(res.locals.videoAll, res)) return
- if (!await isVideoCommentAccepted(req, res, res.locals.videoAll,false)) return
+ if (!await isVideoCommentAccepted(req, res, res.locals.videoAll, false)) return
return next()
}
// ---------------------------------------------------------------------------
-async function doesVideoCommentThreadExist (id: number, video: MVideoId, res: express.Response) {
+async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
+ const id = parseInt(idArg + '', 10)
const videoComment = await VideoCommentModel.loadById(id)
if (!videoComment) {
if (videoComment.videoId !== video.id) {
res.status(400)
- .json({ error: 'Video comment is associated to this video.' })
+ .json({ error: 'Video comment is not associated to this video.' })
.end()
return false
return true
}
-async function doesVideoCommentExist (id: number, video: MVideoId, res: express.Response) {
+async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
+ const id = parseInt(idArg + '', 10)
const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
if (!videoComment) {
if (videoComment.videoId !== video.id) {
res.status(400)
- .json({ error: 'Video comment is associated to this video.' })
+ .json({ error: 'Video comment is not associated to this video.' })
.end()
return false
}
function checkUserCanDeleteVideoComment (user: MUser, videoComment: MCommentOwner, res: express.Response) {
+ if (videoComment.isDeleted()) {
+ res.status(409)
+ .json({ error: 'This comment is already deleted' })
+ .end()
+ return false
+ }
+
const account = videoComment.Account
if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) === false && account.userId !== user.id) {
res.status(403)