X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fuser-history.ts;h=f2dae313437ad42c8a8835b25bdb21b52bd6504b;hb=e364e31e25bd1d4b8d801c845a96d6be708f0a18;hp=418313d09812d8a365f757b0b15462c05d54e49c;hpb=73471b1a52f242e86364ffb077ea6cadb3b07ae2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts index 418313d09..f2dae3134 100644 --- a/server/middlewares/validators/user-history.ts +++ b/server/middlewares/validators/user-history.ts @@ -1,18 +1,37 @@ -import * as express from 'express' -import 'express-validator' -import { body } from 'express-validator/check' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' -import { isDateValid } from '../../helpers/custom-validators/misc' - -const userHistoryRemoveValidator = [ +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 valid before date'), + .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body }) + 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() @@ -22,5 +41,7 @@ const userHistoryRemoveValidator = [ // --------------------------------------------------------------------------- export { - userHistoryRemoveValidator + userHistoryListValidator, + userHistoryRemoveElementValidator, + userHistoryRemoveAllValidator }