X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fshared%2Fvideo-comments.ts;h=0961b3ec9d49ca7fcc88f42147eb589fc2d40f7f;hb=4638cd713dcdd007cd7f49b9a95fa62ac7823e7c;hp=83ea15c988a0ce1a8ca8092eac382f474d536918;hpb=cf21b2cbef61929177b9c09b5e017c3b7eb8535d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/shared/video-comments.ts b/server/middlewares/validators/shared/video-comments.ts index 83ea15c98..0961b3ec9 100644 --- a/server/middlewares/validators/shared/video-comments.ts +++ b/server/middlewares/validators/shared/video-comments.ts @@ -1,10 +1,11 @@ -import * as express from 'express' +import express from 'express' import { VideoCommentModel } from '@server/models/video/video-comment' import { MVideoId } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' +import { forceNumber } from '@shared/core-utils' +import { HttpStatusCode, ServerErrorCode } from '@shared/models' async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) { - const id = parseInt(idArg + '', 10) + const id = forceNumber(idArg) const videoComment = await VideoCommentModel.loadById(id) if (!videoComment) { @@ -16,7 +17,10 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide } if (videoComment.videoId !== video.id) { - res.fail({ message: 'Video comment is not associated to this video.' }) + res.fail({ + type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO, + message: 'Video comment is not associated to this video.' + }) return false } @@ -30,7 +34,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide } async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) { - const id = parseInt(idArg + '', 10) + const id = forceNumber(idArg) const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) if (!videoComment) { @@ -42,7 +46,10 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r } if (videoComment.videoId !== video.id) { - res.fail({ message: 'Video comment is not associated to this video.' }) + res.fail({ + type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO, + message: 'Video comment is not associated to this video.' + }) return false } @@ -51,7 +58,7 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r } async function doesCommentIdExist (idArg: number | string, res: express.Response) { - const id = parseInt(idArg + '', 10) + const id = forceNumber(idArg) const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) if (!videoComment) {