aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/user-history.ts
blob: f2dae313437ad42c8a8835b25bdb21b52bd6504b (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
36
37
38
39
40
41
42
43
44
45
46
47
import express from 'express'
import { body, param, query } from 'express-validator'
import { exists, isDateValid, isIdValid } from '../../helpers/custom-validators/misc'
import { areValidationErrors } from './shared'

const userHistoryListValidator = [
  query('search')
    .optional()
    .custom(exists),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return

    return next()
  }
]

const userHistoryRemoveAllValidator = [
  body('beforeDate')
    .optional()
    .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return

    return next()
  }
]

const userHistoryRemoveElementValidator = [
  param('videoId')
    .custom(isIdValid),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return

    return next()
  }
]

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

export {
  userHistoryListValidator,
  userHistoryRemoveElementValidator,
  userHistoryRemoveAllValidator
}