Encountered an error: The property 'then' does not exist on type 'CloudFunction>' in my Firebase cloud function. Does anyone have a solution?
exports.rebuildFormTriggerClientDetails = functions.firestore.
document('clientDetails/{details}').onUpdate((change) => {
const afterDoc = change.after.data();
const documentId = change.after.id
if (afterDoc)
{
let docUsers = db.collection("clientDetails").doc(documentId);
//var userMap: {[key: string]: any} = {};
let caseArray: Array<string>;
caseArray = afterDoc.CaseRefArray;
for (var valCase of caseArray) {
console.log(valCase);
console.log(documentId);
createObjectDocument(docUsers,valCase);
}
}
}).then(() => {
console.log("Successfully updated document!");
}).catch((error: any) => {
console.error("Error updating document: ", error);
});
Could the createObjectDocument function be causing the error?
function createObjectDocument(document: any, caseNumber: String)
{
document.get().then(function(doc: any) {
if (doc.exists) {
console.log("Document data:", doc.data());
for (let [key, value] of Object.entries(doc.data())) {
console.log(`${key}: ${value}`);
if (key != "CaseRefArray")
{
db.collection("casesToExport").doc(caseNumber).update({key : value });
}
}
} else {
console.log("No such document!");
}
}).catch(function(error: any) {
console.log("Error getting document:", error);
});
}