Mejora de las orders y actualizacion docs
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user