Skip to content

Commit

Permalink
feat: merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-shvadron committed May 1, 2024
1 parent 1a48cc9 commit 53ccf83
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions services/workflows-service/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,32 @@ export class ValidationError extends common.BadRequestException {
}

static fromClassValidator(error: ClassValidatorValidationError[]) {
const childrens = error[0]?.children ? error[0].children : [];
const flattenedErrors = flattenValidationErrors(error);

return new ValidationError(
[...error, ...childrens].map(({ property, constraints = {} }) => ({
flattenedErrors.map(({ property, constraints = {}, value }, index) => ({
message: `${Object.values(constraints).join(', ')}.`,
value: index !== 0 ? value : {},
path: property,
})),
);
}
}

const flattenValidationErrors = (
errors: ClassValidatorValidationError[],
): ClassValidatorValidationError[] => {
const flattenedErrors: ClassValidatorValidationError[] = [];

for (const error of errors) {
flattenedErrors.push(error);

if (error.children) {
for (const child of error.children) {
flattenedErrors.push(...flattenValidationErrors([child]));
}
}
}

return flattenedErrors;
};

0 comments on commit 53ccf83

Please sign in to comment.