MCPcopy Create free account
hub / github.com/axe-api/axe-api / Validatorjs

Class Validatorjs

packages/axe-api/src/Validators/Validatorjs.ts:6–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import { HttpMethods } from "../Enums";
5
6class 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
38export default Validatorjs;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected