Fix error logging
[oweals/peertube.git] / server / controllers / api / videos / blacklist.ts
1 import * as express from 'express'
2
3 import { database as db } from '../../../initializers/database'
4 import { logger } from '../../../helpers'
5 import {
6   authenticate,
7   ensureIsAdmin,
8   videosBlacklistValidator
9 } from '../../../middlewares'
10
11 const blacklistRouter = express.Router()
12
13 blacklistRouter.post('/:id/blacklist',
14   authenticate,
15   ensureIsAdmin,
16   videosBlacklistValidator,
17   addVideoToBlacklist
18 )
19
20 // ---------------------------------------------------------------------------
21
22 export {
23   blacklistRouter
24 }
25
26 // ---------------------------------------------------------------------------
27
28 function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
29   const videoInstance = res.locals.video
30
31   const toCreate = {
32     videoId: videoInstance.id
33   }
34
35   db.BlacklistedVideo.create(toCreate)
36     .then(() => res.type('json').status(204).end())
37     .catch(err => {
38       logger.error('Errors when blacklisting video ', err)
39       return next(err)
40     })
41 }