Mejora de las orders y actualizacion docs

This commit is contained in:
2026-03-04 13:51:24 +01:00
parent 5771972e2a
commit 39c0e87758
12 changed files with 269 additions and 209 deletions

View File

@@ -1,3 +1,5 @@
import { Result } from "../domain/Result.js"
export type Validator<T extends Object> = {
field: keyof T,
errorMsg: string,
@@ -16,10 +18,18 @@ export class BodyValidator<T extends Object> {
this.validatorList = validators
}
public validate(obj: T) {
public validate(obj: T): Result<{ msg: string, field: string }, boolean> {
for (const validator of this.validatorList) {
if (validator.validationFunc(obj) == false) throw new Error(validator.errorMsg)
if (validator.validationFunc(obj) == false)
return {
error: {
msg: validator.errorMsg,
field: String(validator.field)
}
}
}
return true;
return {
data: true
};
}
}