Reputation: 891
I am trying to update a document using a Cloud Store trigger function. Below is the code but when I try to deploy the function I get this error: 119:30 error Parsing error: Unexpected token deviceDoc ✖ 1 problem (1 error, 0 warnings)
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate((change, context) => {
const afterData = change.after.data();
const agentId = afterData.agentId;
console.log('agentId: ', afterData.agentId);
console.log('A transaction has been updated');
/**** GET DEVICE INFORMATION ****/
const deviceDoc = db.collection('device').doc(agentId);
console.log('deviceDoc: ', deviceDoc);
if (deviceDoc == null) {
console.log('No device document found');
}
const deviceData = await deviceDoc.get(); <<<< THIS IS THE PROBLEM CODE
});
The last line is the one that is causing the error but I don't know why. I use this same line in another function and it works there.
Please help! Thanks
Upvotes: 1
Views: 103
Reputation: 7696
You need to add async
to your callback like below:
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate(async (change, context) => {
//... rest of the code
});
Upvotes: 1