I need the user to input a specific account number in the endpoint, and I've been trying to validate this parameter against my database. However, I'm having trouble getting it to work correctly. Can you please point out what I might be doing wrong?
My validation logic:
const validateReq: [
param('accountNumber').exists().custom(acctNo => accountNumberExist(acctNo)),]
Function for checking account number existence:
function accountNumberExist(inputAcct) {
const isfound = accounts.find(account => account.accountNumber === inputAcct);
if (isfound === undefined) throw new Error('Account Number not found');
}
Data in my accounts file:
const accounts = [
{
id: 1,
accountNumber: 1234567890,
createdOn: new Date(),
owner: 1,
type: 'current',
balance: 23444.43,
status: 'active',
},
{
id: 2,
accountNumber: 1234167890,
createdOn: new Date(),
owner: 1,
type: 'savings',
balance: 2233444.43,
status: 'active',
},
{
id: 3,
accountNumber: 9987654321,
createdOn: new Date(),
owner: 2,
type: 'saving',
balance: 73444.43,
status: 'active',
},
];
Despite the fact that the requested parameter exists in my accounts database, I keep receiving the error message 'Account Number not found'. Any insights on why this could be happening?