Creating a service to get transaction details

The endpoint /gettrans returns the incoming and outgoing transactions against an account when called from the bank portal frontend. It fetches the transactions from the transactions relation in the bank database, by running a SELECT query against it.

We start by fetching the customer's account from the request body, as follows:

app.post('/gettrans', function (request, response) {
const account = request.body.account;

Next, we fetch all the transactions from the transactions relation for the account in the request body, as follows:

client.query('SELECT * FROM transactions WHERE saccount = $1 OR raccount = $1', [account], (error, results)=> {

On the response from the pg client, we check for an error response. In the case of no errors, we add the query result rows to the response object and send it back to the bank portal frontend, like this:

if (error) {
throw error
}

if(results)
{
console.log(results);
response.json({
tx: results.rows
});
response.end();
}
})
})

That brings us to the end of our /gettrans endpoint.

Let's look at the methods defined in our backend server next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.68.14