| 4 | import { HttpMethods } from "../Enums"; |
| 5 | |
| 6 | class Validatorjs implements IValidator { |
| 7 | constructor(supportedLanguages: string[]) { |
| 8 | supportedLanguages.forEach((language) => { |
| 9 | Validator.useLang(language); |
| 10 | |
| 11 | LogService.debug( |
| 12 | `Validatorjs language pack has been imported: ${language}`, |
| 13 | ); |
| 14 | }); |
| 15 | } |
| 16 | async validate(req: AxeRequest, model: IModelService, formData: any) { |
| 17 | // Setting the language |
| 18 | Validator.useLang(req.currentLanguage.language); |
| 19 | |
| 20 | // Getting the validation rules |
| 21 | const requestMethod: HttpMethods = req.method as unknown as HttpMethods; |
| 22 | const validationRules = model.instance.getValidationRules(requestMethod); |
| 23 | |
| 24 | // Validating the data if there is any |
| 25 | if (validationRules) { |
| 26 | const validation = new Validator(formData, validationRules); |
| 27 | |
| 28 | // Return the validation errors |
| 29 | if (validation.fails()) { |
| 30 | return validation.errors; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return null; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export default Validatorjs; |
nothing calls this directly
no outgoing calls
no test coverage detected