Update
The actual problem I am having is placing the value back inside the response after I decrypt it. I just need to know how to place a value back in the response after I manipulate it.
Background
On the node side of my angular2 app I am preparing to send the response from an api call made to a postgres database. I need to decrypt one of the values in the response. In the docs it showed to handle the response like this,
if (err) {
console.error(err);
res.status(500).send();
return done(); // always close connection
} else {
if (result.rowCount > 0) {
decrypt(result.rows[0].myvalue);
let user = result.rows[0];
res.send(user);
return done(); // always close connection
}
Problem
I can not figure out how to manipulate one of the values in the response before it is sent back. In this case decrypt(user.myvalue); or decrypt it before it is placed in user decrypt(result.rows[0].myValue);
Example
If you console.log(user.myvalue); the encrypted myvalue is displayed. I need to decrypt myvalue before it ends up in the response. I can decrypt it like this,
decrypt(result.rows[0].ssn);
Question
How do I decrypt this with decrypt(result.myvalue); so that it is in the user object that is sent back in the response decrypted?
To be honest I am confused on how this look even works.
if (result.rowCount > 0) { // if greater than 0? Should it not always be greater than 0:
let user = result.rows[0];
The response comes back just fine. I can access the data with no problem on the node side. I just do not get how it is looping through it when it stores it. Because the result.rows[0]; appears to me as just one position? I guess it is just storing the whole response in that one position [0];??
So this outputs myvalue
console.log(result.rows[0].myValue);
So I just need to decrypt that value and put it back in.