UNPKG

@elsikora/nestjs-crud-automator

Version:

A library for automating the creation of CRUD operations in NestJS.

25 lines (23 loc) 1.07 kB
/** * Flattens class-validator errors into the same message array shape used by Nest ValidationPipe. * @param {Array<ValidationError>} errors - Validation errors to flatten. * @param {string} [parentProperty] - Parent property path. * @returns {Array<string>} Flattened validation messages. */ function ApiRouteValidationFlattenErrors(errors, parentProperty) { const messages = []; for (const error of errors) { const propertyPath = parentProperty ? `${parentProperty}.${error.property}` : error.property; if (error.constraints) { messages.push(...Object.values(error.constraints).map((message) => { return parentProperty ? message.replace(`${error.property} `, `${propertyPath} `) : message; })); } if (error.children && error.children.length > 0) { messages.push(...ApiRouteValidationFlattenErrors(error.children, propertyPath)); } } return messages; } export { ApiRouteValidationFlattenErrors }; //# sourceMappingURL=validation-flatten-errors.utility.js.map