0.0.2 • Published 2 years ago

nestjs-i18n-custom-validator v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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
    }
  }));