Passed
Push — feature/manager-summary-view ( 1d0e65...0b472e )
by Grant
04:22
created

resources/assets/js/store/User/userSelector.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 20
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
dl 0
loc 20
rs 10
c 0
b 0
f 0
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import { createSelector } from "reselect";
2
import { RootState } from "../store";
3
import { User } from "../../models/types";
4
import { hasKey } from "../../helpers/queries";
5
6
const getUsersById = (state: RootState): { [id: number]: User } =>
7
  state.user.usersById;
8
9
export const getUsers = createSelector(getUsersById, (usersById): User[] =>
10
  Object.values(usersById),
11
);
12
13
export const getUserById = (
14
  state: RootState,
15
  { userId }: { userId: number },
16
): User | null => {
17
  const usersById = getUsersById(state);
18
  return hasKey(usersById, userId) ? usersById[userId] : null;
19
};
20