]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/bulk.ts
refactor API errors to standard error format
[github/Chocobozzz/PeerTube.git] / server / controllers / api / bulk.ts
CommitLineData
444c0a0e
C
1import * as express from 'express'
2import { asyncMiddleware, authenticate } from '../../middlewares'
3import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
4import { VideoCommentModel } from '@server/models/video/video-comment'
444c0a0e 5import { removeComment } from '@server/lib/video-comment'
2d53be02
RK
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
444c0a0e
C
8
9const bulkRouter = express.Router()
10
11bulkRouter.post('/remove-comments-of',
12 authenticate,
13 asyncMiddleware(bulkRemoveCommentsOfValidator),
14 asyncMiddleware(bulkRemoveCommentsOf)
15)
16
17// ---------------------------------------------------------------------------
18
19export {
20 bulkRouter
21}
22
23// ---------------------------------------------------------------------------
24
25async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) {
26 const account = res.locals.account
27 const body = req.body as BulkRemoveCommentsOfBody
28 const user = res.locals.oauth.token.User
29
30 const filter = body.scope === 'my-videos'
31 ? { onVideosOfAccount: user.Account }
32 : {}
33
34 const comments = await VideoCommentModel.listForBulkDelete(account, filter)
35
36 // Don't wait result
76148b27 37 res.status(HttpStatusCode.NO_CONTENT_204).end()
444c0a0e
C
38
39 for (const comment of comments) {
40 await removeComment(comment)
41 }
42}