I have a method that return promise and works with async/await concept in loop.
async getFilteredGuaranteesByPermissions(): Promise<GuaranteesMetaData[]> {
const result = [];
for (const guarantees of this.guaranteesMetaData) {
if (await this.permissionService.hasReadPermission(guarantees.key)) {
result.push(guarantees);
}
}
return this.groupingGuaranteesMetaDataCategories(result);
}
groupingGuaranteesMetaDataCategories(guarantees: GuaranteesMetaData[]): GuaranteesMetaData[] {
return _.groupBy(guarantees, 'category');
}
hasReadPermission
return boolean
groupingGuaranteesMetaDataCategories
return array.
I tried use reduce, forkJoin, map, but I cant understand how to rewrite async/await to Observable correct that is not subscribe to every hasReadPermission method in loop?