From fb77111e349b76fb19c892da8ae2ad01a708a4c1 Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Tue, 2 Dec 2025 17:27:36 +0530 Subject: [PATCH] Refactor payment details handling: remove IFSC code validation, add currencyXid to DTO, and implement bank branch lookup for IFSC code retrieval. --- .../validation/host/addPaymentDetails.validation.ts | 5 ----- src/modules/host/dto/host.dto.ts | 1 + .../Host_Admin/onboarding/updateBankDetails.ts | 13 +++++++++++-- src/modules/host/services/host.service.ts | 11 +++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/common/utils/validation/host/addPaymentDetails.validation.ts b/src/common/utils/validation/host/addPaymentDetails.validation.ts index c289a06..b8af555 100644 --- a/src/common/utils/validation/host/addPaymentDetails.validation.ts +++ b/src/common/utils/validation/host/addPaymentDetails.validation.ts @@ -11,11 +11,6 @@ export const hostBankDetailsSchema = z.object({ .nonempty("Account holder name is required") .min(2, { message: "Account holder name must be at least 2 characters" }), - ifscCode: z - .string() - .nonempty("IFSC code is required") - .regex(/^[A-Z]{4}0[A-Z0-9]{6}$/, { message: "Invalid IFSC code format" }), - bankXid: z .number() .int({ message: "Bank ID must be an integer" }) diff --git a/src/modules/host/dto/host.dto.ts b/src/modules/host/dto/host.dto.ts index e07e110..2a0b32e 100644 --- a/src/modules/host/dto/host.dto.ts +++ b/src/modules/host/dto/host.dto.ts @@ -90,5 +90,6 @@ export class AddPaymentDetailsDTO { this.accountHolderName = accountHolderName; this.ifscCode = ifscCode; this.hostXid = hostXid; + this.currencyXid = currencyXid; } } \ No newline at end of file diff --git a/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts b/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts index 42f1aec..73f87ad 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts @@ -33,7 +33,7 @@ export const handler = safeHandler(async ( } // Parse request body - let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; confirmAccountNumber?: string; accountHolderName?: string; ifscCode?: string; currencyXid?: number }; + let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; confirmAccountNumber?: string; accountHolderName?: string; currencyXid?: number }; try { body = event.body ? JSON.parse(event.body) : {}; @@ -54,7 +54,16 @@ export const handler = safeHandler(async ( const validatedData = validationResult.data; - await hostService.addPaymentDetails(validatedData); + // Fetch IFSC code from bank branch + const bankBranch = await hostService.getBankBranchById(validatedData.bankBranchXid); + if (!bankBranch) { + throw new ApiError(404, 'Bank branch not found'); + } + + await hostService.addPaymentDetails({ + ...validatedData, + ifscCode: bankBranch.ifscCode, + }); return { statusCode: 200, diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 430afaf..77bb31b 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -330,6 +330,17 @@ export class HostService { return true; } + async getBankBranchById(bankBranchXid: number) { + return await this.prisma.bankBranches.findUnique({ + where: { id: bankBranchXid }, + select: { + id: true, + ifscCode: true, + bankXid: true, + }, + }); + } + async addPaymentDetails(data: AddPaymentDetailsDTO) { return await this.prisma.$transaction(async (tx) => { const addedPaymentDetails = await tx.hostBankDetails.create({