in this code i want to set value in where object before processing to next line , but just after this.conn.getUserByAlterNumber
the execution is gone to if (this.doctorFilter
&& this.doctorFilter.length
) without waiting for response from the function and thus this.conn.getOrders
isgetting a blank object in place of where and my filter is not working, how to stop the execution until this.conn.getUserByAlternateNumber
returns value.
loadMore(offset: number): Promise<any> {
let where: any = {};
this.filters.forEach((item: any) => {
if (item.key === 'alternateNumber') {
this.conn.getUserByAlternateNumber(item.value)
.then((user: any) => {
where['contactName'] = user[0].attributes.PatientName;
console.log(where,'>>>>>');
});
} else {
(where[item.key] = item.value);
}
});
if (this.doctorFilter && this.doctorFilter.length) {
where.allocatedDoctor = this.doctorFilter;
}
console.log(where);
return this.conn.getOrders({
where,
include: ['user', 'allocatedDoctor'],
limit: this.ui.grid.pageSize,
asc: this.OrderAsc,
offset,
})
.then((items: any) => this.zone.run(() => Promise.resolve(items.map((i: any) => JSON.parse(JSON.stringify(i))))));
}