Script in Firestore (Firebase) does not arrive at update

Asked

Viewed 35 times

0

I’m having trouble with the code below. The code reaches postbackRef.add and adds the information in the database, but after that it does not enter transactionsRef.Where to perform the update just below in transactionUpdate.update. What can it be?

pagarme.post("/retornoPagarme", function (req, res) {
var transactionsRef = db.collection('transactions');
var postbackRef = db.collection('postback_return');

var setPostback = postbackRef.add({
    return: req.body
}).then((ref) => {
    var transactionSnapShot = transactionsRef.where('id_pagarme', '==', req.body.id).get();
    let values = null;
    transactionSnapShot.forEach(doc => {
        values = doc.data();
    });
    var transactionUpdate = transactionsRef.doc(values.id);
    transactionUpdate.update({
        status_pagarme: req.body.current_status,
        status: req.body.current_status
    })

    postbackRef.doc(ref.id).set({ status: req.body.current_status });

    return res.status(200);
});

return res.status(200);

});
  • Have you ever tried to make one console.log before the line var transactionSnapshot...? Console shows no error?

1 answer

0


Solved! It was a variable typing problem...

var transactionSnapShot = transactionsRef.where('id_pagarme', '==', Number(req.body.id)).get();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.