From cdac4940cfadefb19984502c4543311080b792ee Mon Sep 17 00:00:00 2001 From: Alon Peretz Date: Wed, 1 May 2024 13:57:22 +0300 Subject: [PATCH 1/3] chore(tm): adding mappings, brand names --- services/workflows-service/src/errors.ts | 23 +++++++++++++++++-- .../dtos/transaction-create.dto.ts | 3 ++- .../src/transaction/transaction.mapper.ts | 4 ++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/services/workflows-service/src/errors.ts b/services/workflows-service/src/errors.ts index 2532cc36e1..862df6e40a 100644 --- a/services/workflows-service/src/errors.ts +++ b/services/workflows-service/src/errors.ts @@ -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; +} diff --git a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts index 56ddf03741..f805b7f84e 100644 --- a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts +++ b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts @@ -34,7 +34,8 @@ export const AltPaymentBrandNames = { SCB_PAYNOW: 'scb_paynow', ['China UnionPay']: 'china unionpay', ['American Express']: 'american express', - + ['ALIPAYHOST']: 'alipayhost', + ['WECHAT']: 'wechathost', ...PaymentBrandName, } as const; diff --git a/services/workflows-service/src/transaction/transaction.mapper.ts b/services/workflows-service/src/transaction/transaction.mapper.ts index 53b8cacecb..6b1ef9cfc3 100644 --- a/services/workflows-service/src/transaction/transaction.mapper.ts +++ b/services/workflows-service/src/transaction/transaction.mapper.ts @@ -204,6 +204,10 @@ export class TransactionEntityMapper { return 'china_union_pay'; case 'american express': return 'american_express'; + case 'alipayhost': + return 'alipay_host'; + case 'wechathost': + return 'wechat_host'; default: return undefined; } From 1864373f3a0594cf41494e305c46789e8f4fdb2b Mon Sep 17 00:00:00 2001 From: Alon Peretz Date: Wed, 1 May 2024 15:02:56 +0300 Subject: [PATCH 2/3] chore(tm): adding mappings, brand names --- .../src/transaction/dtos/transaction-create.dto.ts | 1 + .../workflows-service/src/transaction/transaction.mapper.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts index f805b7f84e..bfe1087cb7 100644 --- a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts +++ b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts @@ -36,6 +36,7 @@ export const AltPaymentBrandNames = { ['American Express']: 'american express', ['ALIPAYHOST']: 'alipayhost', ['WECHAT']: 'wechathost', + ['GRABPAY']: 'grabpay', ...PaymentBrandName, } as const; diff --git a/services/workflows-service/src/transaction/transaction.mapper.ts b/services/workflows-service/src/transaction/transaction.mapper.ts index 6b1ef9cfc3..70d023d466 100644 --- a/services/workflows-service/src/transaction/transaction.mapper.ts +++ b/services/workflows-service/src/transaction/transaction.mapper.ts @@ -208,6 +208,8 @@ export class TransactionEntityMapper { return 'alipay_host'; case 'wechathost': return 'wechat_host'; + case 'grabpay': + return 'grab_pay'; default: return undefined; } From 63863677ca3a161b61d137bebda837ddbeeedbbc Mon Sep 17 00:00:00 2001 From: Alon Peretz Date: Wed, 1 May 2024 15:09:37 +0300 Subject: [PATCH 3/3] chore(tm): adding mappings, brand names --- .../src/transaction/dtos/transaction-create.dto.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts index bfe1087cb7..da04d9b903 100644 --- a/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts +++ b/services/workflows-service/src/transaction/dtos/transaction-create.dto.ts @@ -168,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()