Skip to content

Commit

Permalink
Merge branch 'dev' into bal-1950
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-shvadron authored May 1, 2024
2 parents 8e18b93 + 6386367 commit 65b597f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 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,12 +84,31 @@ 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,
})),
);
}
}

function 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const AltPaymentBrandNames = {
SCB_PAYNOW: 'scb_paynow',
['China UnionPay']: 'china unionpay',
['American Express']: 'american express',

['ALIPAYHOST']: 'alipayhost',
['WECHAT']: 'wechathost',
['GRABPAY']: 'grabpay',
...PaymentBrandName,
} as const;

Expand Down Expand Up @@ -166,9 +168,9 @@ export class TransactionCreateAltDto {

@ApiProperty({ required: true })
@Transform(({ value }) => value.toLowerCase())
@IsEnum(AltPaymentBrandNames)
@IsString()
@IsNotEmpty()
tx_product!: AltPaymentBrandNames;
tx_product!: string;

@ApiProperty({ required: false })
@IsString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ export class TransactionEntityMapper {
return 'china_union_pay';
case 'american express':
return 'american_express';
case 'alipayhost':
return 'alipay_host';
case 'wechathost':
return 'wechat_host';
case 'grabpay':
return 'grab_pay';
default:
return undefined;
}
Expand Down

0 comments on commit 65b597f

Please sign in to comment.