Refactor payment details handling: remove IFSC code validation, add currencyXid to DTO, and implement bank branch lookup for IFSC code retrieval.
This commit is contained in:
@@ -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" })
|
||||
|
||||
@@ -90,5 +90,6 @@ export class AddPaymentDetailsDTO {
|
||||
this.accountHolderName = accountHolderName;
|
||||
this.ifscCode = ifscCode;
|
||||
this.hostXid = hostXid;
|
||||
this.currencyXid = currencyXid;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user