nestjs-i18n-custom-validator
v0.0.2
Published
Build input validation in multi-language
Downloads
13
Readme
In testing, please wait... config main.ts:
import { i18nValidationErrorFactory, I18nValidationExceptionFilter } from 'nestjs-i18n-2';
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory: i18nValidationErrorFactory,
}),
);
app.useGlobalFilters(new I18nValidationExceptionFilter({
errorFormatter(data: ValidationError[]) {
let customErrors: any[] = []
data.forEach(error => {
// console.log(error.value)
// console.log(error.contexts)
let element = {} as any
element.field = error.property
let errorStringJoin: string = ""
for (let type in error.constraints) {
errorStringJoin = errorStringJoin + error.constraints[type] + ". "
}
element.error = errorStringJoin.trim()
customErrors.push(element)
});
return customErrors
}
}));