Add validation to prevent duplicate host accounts in addPaymentDetails method

This commit is contained in:
2025-12-06 12:06:04 +05:30
parent 06010ef6e8
commit 51b053310f

View File

@@ -368,6 +368,19 @@ export class HostService {
async addPaymentDetails(data: AddPaymentDetailsDTO) {
return await this.prisma.$transaction(async (tx) => {
const existingAccount = await tx.hostBankDetails.findFirst({
where: {
accountNumber: data.accountNumber,
isActive: true,
},
});
if (existingAccount) {
throw new ApiError(
400,
'Host account with this account number already exists.'
);
}
const addedPaymentDetails = await tx.hostBankDetails.create({
data,
});