Is there a way to ensure that all promises are resolved before moving on to the next line of code? Currently, it seems like it's moving to the next line without completing the operation below. I want to make sure that the forEach
loop is fully executed before proceeding to the next step. How can I achieve this?
forEach(project.projectDetail.memberList, async (m) => {
const memberDocumentRef: firebase.firestore.DocumentReference = this.fireStore.doc(`members/${m.id}`).ref;
await this.fireStore.firestore.runTransaction(transaction => {
return transaction.get(memberDocumentRef).then(memberDoc => {
let currentProjects: Project[] = memberDoc.data().projects;
const finalProjects = filter(currentProjects, (p: Project) => { return p.id != project.projectDetail.id; });//projects Without Updated Project
finalProjects.push(project.projectDetail);
transaction.update(memberDocumentRef, { projects: Object.assign({}, finalProjects) });//update projects on each member
});
});
});