Add validation to prevent duplicate host accounts in addPaymentDetails method
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user