How do I go about returning a promise
in the deleteBudgets()
method below so that I can use await
inside the updateBudgets()
method?
deleteBudgets
deleteBudgets(data: Budget[], projectId: string): Promise<void> {
forEach(data, (d: Budget) => {
this.fireStore.doc(`projects/${projectId}/budgets/${d.id}`).delete();//here it returns Promise<void>
});
}
updateBudgets
updateBudgets(data: Budget[], projectId: string): Budget[] {
await this.deleteBudgets();//here
let budgets: Budget[] = [];
forEach(data, (d) => {
const budgetId: string = this.fireStore.createId();
d.id = budgetId;
budgets.push(d);
this.fireStore.doc<Budget>(`projects/${projectId}/budgets/${budgetId}`).set({
id: budgetId,
amount: d.amount,
contingency: d.contingency,
budgetGroup: d.budgetGroup,
creationTime: moment().format()
})
})
return budgets;
}