All files / projects/organization-management/src/app/store/users users.selectors.ts

100% Statements 36/36
100% Branches 0/0
100% Functions 18/18
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 4749x   49x   49x   49x   49x   49x   49x   49x   49x 7x     49x 2x 5x       49x   49x     10x     49x   49x   49x 2x   49x 3x   4x    
import { createSelector } from '@ngrx/store';
 
import { selectRouteParam } from 'ish-core/store/core/router';
 
import { getOrganizationManagementState } from '../organization-management-store';
 
import { usersAdapter } from './users.reducer';
 
const getUsersState = createSelector(getOrganizationManagementState, state => state.users);
 
export const getUsersLoading = createSelector(getUsersState, state => state.loading);
 
export const getUsersError = createSelector(getUsersState, state => state.error);
 
const { selectAll, selectEntities, selectTotal } = usersAdapter.getSelectors(getUsersState);
 
export const getUsers = createSelector(selectAll, users =>
  users.filter(user => !user.roleIDs?.find(roleID => ['APP_B2B_OCI_USER', 'APP_B2B_CXML_USER'].includes(roleID)))
);
 
export const getCostCenterManagers = createSelector(selectAll, users =>
  users.filter(user =>
    user.roleIDs?.find(roleID => ['APP_B2B_COSTCENTER_OWNER', 'APP_B2B_ACCOUNT_OWNER'].includes(roleID))
  )
);
 
export const getUserCount = selectTotal;
 
export const getSelectedUser = createSelector(
  selectRouteParam('B2BCustomerLogin'),
  selectEntities,
  (login, users) => users[login]
);
 
export const getSystemUserRoles = createSelector(getUsersState, state => state.roles);
 
export const isSystemUserRolesLoaded = createSelector(getSystemUserRoles, roles => !!roles.length);
 
export const getRole = (roleID: string) =>
  createSelector(getSystemUserRoles, roles => roles?.find(r => r.id === roleID));
 
export const getRoles = (roleIDs: string[]) =>
  createSelector(getSystemUserRoles, roles =>
    // preserve order from state
    roles.filter(r => roleIDs?.includes(r.id))
  );