aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/blacklist.ts
blob: fe8fa40a45b7eef526f149715b6ec5110406661f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { param } from 'express-validator/check'
import * as express from 'express'

import { database as db } from '../../initializers/database'
import { checkErrors } from './utils'
import { logger } from '../../helpers'

const blacklistRemoveValidator = [
  param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })

    checkErrors(req, res, () => {
      db.BlacklistedVideo.loadById(req.params.id)
        .then(entry => {
          if (!entry) return res.status(404).send('Blacklisted video not found')

          res.locals.blacklistEntryToRemove = entry

          next()
        })
        .catch(err => {
          logger.error('Error in blacklistRemove request validator', { error: err })
          return res.sendStatus(500)
        })
    })
  }
]

// ---------------------------------------------------------------------------

export {
  blacklistRemoveValidator
}