Passed
Push — dev ( 65c6f9...40537c )
by
unknown
05:05 queued 10s
created

resources/assets/js/store/EducationStatus/educationStatusReducer.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 39
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 32
mnd 1
bc 1
fnc 0
dl 0
loc 39
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { EducationStatus } from "../../models/types";
2
import {
3
  EducationStatusAction,
4
  GET_EDUCATION_STATUSES_STARTED,
5
  GET_EDUCATION_STATUSES_SUCCEEDED,
6
  GET_EDUCATION_STATUSES_FAILED,
7
} from "./educationStatusActions";
8
import { mapToObject, getId } from "../../helpers/queries";
9
10
export interface EducationStatusState {
11
  byId: {
12
    [id: number]: EducationStatus;
13
  };
14
  loading: boolean;
15
}
16
17
export const initEducationStatusState = (): EducationStatusState => ({
18
  byId: [],
19
  loading: false,
20
});
21
22
const educationStatusReducer = (
23
  state = initEducationStatusState(),
24
  action: EducationStatusAction,
25
): EducationStatusState => {
26
  switch (action.type) {
27
    case GET_EDUCATION_STATUSES_STARTED:
28
      return { ...state, loading: true };
29
    case GET_EDUCATION_STATUSES_SUCCEEDED:
30
      return { byId: mapToObject(action.payload, getId), loading: false };
31
    case GET_EDUCATION_STATUSES_FAILED:
32
      return { ...state, loading: false };
33
    default:
34
      return state;
35
  }
36
};
37
38
export default educationStatusReducer;
39