I am encountering an issue with the JSON data being blank in the code below.
The class is defined as follows:
export class Account {
public amount: string;
public name: string;
constructor(amount: string, name: string) {
this.amount = amount;
this.name= name;
}
}
let account: Account[] =[];
function accountList () {
client.getAccounts({}, function (err, accounts) {
accounts.forEach(function (acct) {
console.log('my balance: ' + acct.balance.amount + ' for ' + acct.name);
account.push(new Account(acct.balance.amount, acct.name));
});
return account;
})
};
The function is called using the following:
app.get('/accounts', (req, res) =>
res.send(JSON.stringify(accountList())));
Please advise on any errors present in the code above.