Here is the challenge: I need to extract information from an action payload that includes specific data structure. The payload looks like this:
{
firms: [{ id: 1, firmName: 'string', roles: ['admin', 'supadmin', 'user'] }],
type: "loadFolder",
userId: 1
};
My task involves iterating through the roles array and making an httpCall for each role, passing in the userId as a parameter. After retrieving the data, I have to categorize it into three separate lists based on the roles (userList, adminList, supadminList). However, I'm currently stuck and unable to find a suitable solution.
loadFolder$ = createEffect(() => {
return this.action$.pipe(
ofType(SidebarAction.loadFirmSuccess),
switchMap(action => {
let roles: Array < string > = [];
let supadminlist = [];
let adminList = [];
let userList = [];
action.firms.map(
firm => {
firm.roles.map((role: string) => {
roles.push(role);
});
}
);
roles.forEach(role => {
this.sidebarService.getFolders(action.userId, role).subscribe(res => {
switch (role) {
case ('supadmin'):
supadminlist = res;
break;
case ('admin'):
adminList = res;
break;
case ('user'):
userList = res;
}
});
});
return sidebarAction.loadFoldersSuccess({supadmin, adminList, userList});
}),
);
});
I've attempted this approach, but I'm struggling with the implementation and unfortunately, this solution is not yielding the desired results.