Creating an endpoint to fetch customer data

The /customerinfo endpoint takes the userID as the request parameter and returns a response object, with the customer details matching the user ID, after fetching them from the bank database.

The service fetches the user ID from the request body. It then uses the pg client object to run a SELECT query on the customers table in the banka database, as follows:

var userId=request.body.userId;

client.query('SELECT name,address,account,balance from customers where user_id = $1', [userId], (error, results)=> {

On the response from the pg client, we check for error responses. In the case of no errors, the customer's name, address, account, and current balance are added to the json response object and sent back to the requestor, like this:

if (error) {
throw error
}

if(results)
{
response.json({
name: results.rows[0].name,
address: results.rows[0].address,
account: results.rows[0].account,
balance: results.rows[0].balance
});

response.end();

}});
});

Next, let's look at the payment endpoint used to post transaction requests.

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

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