2021-08-27 14:32:44 +02:00
|
|
|
import express from 'express'
|
2022-01-18 11:23:41 +01:00
|
|
|
import { body, param, query } from 'express-validator'
|
|
|
|
import { exists, isDateValid, isIdValid } from '../../helpers/custom-validators/misc'
|
2021-06-03 17:33:44 +02:00
|
|
|
import { areValidationErrors } from './shared'
|
2021-01-13 09:16:15 +01:00
|
|
|
|
|
|
|
const userHistoryListValidator = [
|
|
|
|
query('search')
|
|
|
|
.optional()
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(exists),
|
2021-01-13 09:16:15 +01:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
2018-12-17 15:52:38 +01:00
|
|
|
|
2022-01-18 11:23:41 +01:00
|
|
|
const userHistoryRemoveAllValidator = [
|
2018-12-17 15:52:38 +01:00
|
|
|
body('beforeDate')
|
|
|
|
.optional()
|
2021-05-31 19:47:14 +02:00
|
|
|
.custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'),
|
2018-12-17 15:52:38 +01:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2022-01-18 11:23:41 +01:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const userHistoryRemoveElementValidator = [
|
|
|
|
param('videoId')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isIdValid),
|
2022-01-18 11:23:41 +01:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2018-12-17 15:52:38 +01:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-01-13 09:16:15 +01:00
|
|
|
userHistoryListValidator,
|
2022-01-18 11:23:41 +01:00
|
|
|
userHistoryRemoveElementValidator,
|
|
|
|
userHistoryRemoveAllValidator
|
2018-12-17 15:52:38 +01:00
|
|
|
}
|