2016-12-01 36 views
0

更新解密數據從數據庫之前發送迴響應的Node.js

我有拼勁值迴響應后里面我decrypt它的實際問題。我只需要知道如何在操作後將值放回response

背景

在我angular2應用程序的node側,我準備從一個api呼叫到postgres數據庫進行發送response。我需要decryptresponse中的一個值。在文檔拿給處理response這樣,

   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 
        } 

問題

我無法弄清楚如何操縱值中的一個響應送回之前。在這種情況下decrypt(user.myvalue);或解密它被放置在userdecrypt(result.rows[0].myValue);

之前如果console.log(user.myvalue);顯示加密myvalue。我需要解密myvalue,然後才結束response。我可以decrypt它這樣,

decrypt(result.rows [0] .ssn);

問題

我如何decrypt這與decrypt(result.myvalue);,使其在在responsedecrypted發送回用戶object

說實話,我很困惑這個外觀如何運作。

if (result.rowCount > 0) { // if greater than 0? Should it not always be greater than 0: 
let user = result.rows[0]; 

響應恢復正常。我可以在node方面訪問沒有問題的數據。我只是不明白當它存儲它時它是如何循環播放的。因爲result.rows[0];在我看來只是一個位置?我想這只是將整個響應存儲在一個位置[0]; ??

所以這個輸出myvalue

console.log(result.rows[0].myValue);

所以我只需要decrypt該值並把它放回

回答

1

你可以試試這個:

result.rows[0].myvalue = decrypt(result.rows[0].myvalue); 

它將decrypt() myvalue。

+0

是的我沒有問題解密它。問題是我把它放回響應之後,我會/ – wuno

+1

是的,它會放置解密值作爲迴應。試試這個解決方案 – AJS

+0

Dude your rockstar thanks。 – wuno

相關問題