]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/bulk.ts
Add `req` and `res` as controllers hooks parameters
[github/Chocobozzz/PeerTube.git] / server / controllers / api / bulk.ts
CommitLineData
41fb13c3 1import express from 'express'
4c7e60bc 2import { removeComment } from '@server/lib/video-comment'
444c0a0e
C
3import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
4import { VideoCommentModel } from '@server/models/video/video-comment'
c0e8b12e 5import { HttpStatusCode } from '@shared/models'
4c7e60bc
C
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { asyncMiddleware, authenticate } from '../../middlewares'
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) {
7226e90f 40 await removeComment(comment, req, res)
444c0a0e
C
41 }
42}