'express-validator custom validator pass but not return request

I'm trying to create a custom validator to create a generic enum validator, but when my rule passes to test, the request does not return it's as if nextFunction didn't trigger. When my rule fails custom validation returns with success.

*what i mean is that when the validation is correct it creates an infinite loop...

My custom validator:

import { CustomValidator, Meta } from "express-validator";

export class EnumMapper<T extends { [name: string]: any }> {

    constructor(public enumObject: T) { }
}
export const isInEnum: CustomValidator = P => (value: any) => {
    let genericEnum = new EnumMapper(P);
    return Object.values(genericEnum.enumObject).includes(value);
};

how am i using my custom validator in code:

export const createOfficeHoursValidation = [
    body('type').custom(isInEnum(OfficeHoursType, body.prototype)),
    // of this the meta-object is required.
    // using body.prototype is having the same effect as creating a {location, path and req} object 
    ...
]

any way to solve this problem? I googled and saw some solutions to validate enums, but not in a generic way..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source