Writing a method to add transactions to the database

The insertTrans() method will insert a new transaction to the transactions relation by using the pg client. It is invoked after the customer's balance is updated by the /payment endpoint.

The method runs an INSERT query to insert the transaction into the transactions database. Apart from the transaction details, an additional flag, transtype, is inserted with the data to indicate that the transaction is an Outgoing transaction, as shown in the following code block: 

var insertTrans = function(trans,res) {

client.query('INSERT INTO transactions(transaction_id,sname, saccount,sbank, saddress, rname, raccount, rbank, raddress, amount, currency, invhash, boehash, dochash, transtype) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)', [trans.txID,trans.det.sname,trans.det.saccount,trans.det.sbank,trans.det.saddress,trans.det.rname,trans.det.raccount,trans.det.rbank,trans.det.raddress, trans.det.amount,trans.det.currency,trans.hasharray[0],trans.hasharray[1],trans.hasharray[2], 'Outgoing'], (error, results) => {

We check the pg client for any error responses. In the case of no errors, we return control to the function invoked with the Transaction successfully submitted message. This message will then returned back to the bank portal frontend by the payment endpoint, as follows:

if (error)
{
throw error;
}

var msg = "Transaction successfully submitted";
console.log("Reached here",msg);
return res(msg);

})
}

That wraps up the insertTrans() method for our backend server.

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

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