PeerTube/server/middlewares/validators/user-history.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-27 07:32:44 -05:00
import express from 'express'
2022-01-18 04:23:41 -06:00
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()
}
]
2022-01-18 04:23:41 -06:00
const userHistoryRemoveAllValidator = [
body('beforeDate')
.optional()
2021-05-31 12:47:14 -05:00
.custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
2022-01-18 04:23:41 -06:00
if (areValidationErrors(req, res)) return
return next()
}
]
const userHistoryRemoveElementValidator = [
param('videoId')
.custom(isIdValid),
2022-01-18 04:23:41 -06:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
userHistoryListValidator,
2022-01-18 04:23:41 -06:00
userHistoryRemoveElementValidator,
userHistoryRemoveAllValidator
}