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:
@@ -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