import { ClassConstructor } from 'class-transformer';
import { RequestHandler } from 'express';
import { HumandResponse } from '../types/response';
import { ValidationClass } from '../validationClasses/validationClass';
import { genericValidateParams } from './genericValidateParams';

export const validateStringQueryParams = (modelClass: ClassConstructor<ValidationClass>): RequestHandler<any, HumandResponse, any, any, any> =>
    genericValidateParams(
        (req) => req.query as ValidationClass,
        (res, output) => {
            res.locals.queryParams = output;
        },
        modelClass,
    );
