returning a valid response after creating a beneficiary

also throw 409 status code if account already exists in beneficiaries table against that customer
This commit is contained in:
asif
2025-08-09 15:51:28 +05:30
parent 20af204304
commit 6e8eccd767

View File

@@ -54,8 +54,15 @@ async function addBeneficiary(req, res) {
const query = const query =
'INSERT INTO beneficiaries (customer_no, account_no, account_type, ifsc_code, name) VALUES ($1, $2, $3, $4, $5)'; 'INSERT INTO beneficiaries (customer_no, account_no, account_type, ifsc_code, name) VALUES ($1, $2, $3, $4, $5)';
await db.query(query, [customerNo, accountNo, accountType, ifscCode, name]); await db.query(query, [customerNo, accountNo, accountType, ifscCode, name]);
res.json({ message: 'SUCCESS' });
} catch (error) { } catch (error) {
logger.error(error, 'Error adding beneficiary'); logger.error(error, 'Error adding beneficiary');
if (
error.message ==
'duplicate key value violates unique constraint "beneficiaries_pkey"'
) {
res.status(409).json({ error: 'BENEFICIARY_ALREADY_EXITS' });
}
res.status(500).json({ error: 'INTERNAL_SERVER_ERROR' }); res.status(500).json({ error: 'INTERNAL_SERVER_ERROR' });
} }
} }