X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcomment.ts;h=cfdf2773f634b145c955165610a0d313b1f1eea0;hb=eb34ec30e0b57286fc6f85160490d2e973a3b0b1;hp=020d0b10470b709a989bbb48762b281cc05c5112;hpb=9b337d8c0fce9c9aa68e44d76569c5abc6c0202e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 020d0b104..cfdf2773f 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -1,6 +1,7 @@ import * as express from 'express' -import { ResultList, UserRight } from '../../../../shared/models' -import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models' +import { VideoCommentCreate } from '../../../../shared/models/videos/comment/video-comment.model' import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers/database' @@ -107,7 +108,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { const video = res.locals.onlyVideo const user = res.locals.oauth ? res.locals.oauth.token.User : undefined - let resultList: ResultList + let resultList: ThreadsResultList if (video.commentsEnabled === true) { const apiOptions = await Hooks.wrapObject({ @@ -127,11 +128,15 @@ async function listVideoThreads (req: express.Request, res: express.Response) { } else { resultList = { total: 0, + totalNotDeletedComments: 0, data: [] } } - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json({ + ...getFormattedObjects(resultList.data, resultList.total), + totalNotDeletedComments: resultList.totalNotDeletedComments + }) } async function listVideoThreadComments (req: express.Request, res: express.Response) { @@ -161,7 +166,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo } if (resultList.data.length === 0) { - return res.sendStatus(404) + return res.sendStatus(HttpStatusCode.NOT_FOUND_404) } return res.json(buildFormattedCommentTree(resultList)) @@ -218,5 +223,7 @@ async function removeVideoComment (req: express.Request, res: express.Response) auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) - return res.type('json').status(204).end() + return res.type('json') + .status(HttpStatusCode.NO_CONTENT_204) + .end() }