]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/comment.ts
Fix thread replies API response
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / comment.ts
index 020d0b10470b709a989bbb48762b281cc05c5112..38fa7c3b005deb6d02320b8c1fc6e0e8465ad5a1 100644 (file)
@@ -1,5 +1,5 @@
 import * as express from 'express'
-import { ResultList, UserRight } from '../../../../shared/models'
+import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models'
 import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
 import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
 import { getFormattedObjects } from '../../../helpers/utils'
@@ -29,6 +29,8 @@ import {
 } from '../../../middlewares/validators'
 import { AccountModel } from '../../../models/account/account'
 import { VideoCommentModel } from '../../../models/video/video-comment'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { logger } from '@server/helpers/logger'
 
 const auditLogger = auditLoggerFactory('comments')
 const videoCommentRouter = express.Router()
@@ -107,7 +109,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<VideoCommentModel>
+  let resultList: ThreadsResultList<VideoCommentModel>
 
   if (video.commentsEnabled === true) {
     const apiOptions = await Hooks.wrapObject({
@@ -127,11 +129,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 +167,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 +224,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()
 }