From d8b34ee55b654912f86bb8b472d391ced8c28f64 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 13 Jan 2021 09:16:15 +0100 Subject: Allow user to search through their watch history (#3576) * allow user to search through their watch history * add tests for search in watch history * Update client/src/app/shared/shared-main/users/user-history.service.ts --- server/middlewares/validators/user-history.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts index 2f1d3cc41..058bf7758 100644 --- a/server/middlewares/validators/user-history.ts +++ b/server/middlewares/validators/user-history.ts @@ -1,8 +1,22 @@ import * as express from 'express' -import { body } from 'express-validator' +import { body, query } from 'express-validator' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' -import { isDateValid } from '../../helpers/custom-validators/misc' +import { exists, isDateValid } from '../../helpers/custom-validators/misc' + +const userHistoryListValidator = [ + query('search') + .optional() + .custom(exists).withMessage('Should have a valid search'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query }) + + if (areValidationErrors(req, res)) return + + return next() + } +] const userHistoryRemoveValidator = [ body('beforeDate') @@ -21,5 +35,6 @@ const userHistoryRemoveValidator = [ // --------------------------------------------------------------------------- export { + userHistoryListValidator, userHistoryRemoveValidator } -- cgit v1.2.3