hisptz/integration-app

View on GitHub
src/app/store/selectors/user.selectors.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { createSelector } from '@ngrx/store';
import { getRootState, State } from '../reducers';
import { UserState } from '../states/user.state';
import { User } from '@iapps/ngx-dhis2-http-client';

export const getUserState = createSelector(
  getRootState,
  (state: State) => state.user
);

export const getCurrentUser = createSelector(
  getUserState,
  (state: UserState) => state.currentUser
);

export const getCurrentUserLoading = createSelector(
  getUserState,
  (state: UserState) => state.loading
);

export const getCurrentUserLoaded = createSelector(
  getUserState,
  (state: UserState) => state.loaded
);

export const getCurrentUserLoadingError = createSelector(
  getUserState,
  (state: UserState) => state.error
);

export const getCurrentUserManagementAuthoritiesStatus = createSelector(
  getCurrentUser,
  (currentUser: User) => {
    if (!currentUser) {
      return false;
    }

    return currentUser && currentUser.authorities
      ? currentUser.authorities.includes('ALL')
      : false;
  }
);