import * as _ from "lodash" ; import { Validator , ValidationError } from "../types" ; export class EnumValueValidator < T > implements Validator { public constructor ( protected enumObject , protected field , protected valueProperty ? , protected message ? ) { } public validate ( value ) { const valueToValidate = this . valueProperty ? _ . get ( value , this . valueProperty ) : value ; if ( ! _ . includes ( _ . values ( this . enumObject ) , valueToValidate ) ) { throw new ValidationError ( this . message || `${ _ . upperFirst ( this . field ) } must be relevant enumeration item` ) ; } } }