map((tasks): any => {
return tasks.map(task => ({
...task,
status: this.getStatus(task.owner, task.delegationState, task.assignee, task.id),
}));
});
I utilize the getStatus method within the map() operator from rxjs.
getStatus(
owner: string | null,
delegationState: string | null,
assignee: string | null,
id: string): string {
if (assignee) {
if (!owner) {
if (!delegationState) {
this.caseService.getUserOperationHistory({
taskId: id,
entityType: 'T',
operationType: 'Claim',
}).subscribe((res) => {
return 'Claimed';
});
} else {
return 'Assigned';
}
}
if (delegationState === 'PENDING') {
return 'Delegated';
}
if (delegationState === 'RESOLVED') {
return 'Assigned';
}
}
return 'Unassigned';
}
While executing the asynchronous code in getUserOperationHistory(), it runs synchronously causing a premature result of 'Unassigned' instead of 'Claimed'. How can I ensure that the async code completes before returning a value?