Passed
Push — feature/update-managers-applca... ( b92f9a...74e2e9 )
by Yonathan
04:13 queued 13s
created

resources/assets/js/api/assessmentPlanNotifications.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 40
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 1
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
/* eslint-disable @typescript-eslint/camelcase */
2
import { baseUrl, ApiResponse, parseDateStrict, axios } from "./base";
3
import { AssessmentPlanNotification } from "../models/types";
4
5
export const parseAssessmentPlanNotification = (
6
  data: any,
7
): AssessmentPlanNotification => ({
8
  ...data,
9
  created_at: parseDateStrict(data.created_at),
10
});
11
12
export const getAssessmentPlanNotificationsByJob = (
13
  jobId: number,
14
): Promise<AssessmentPlanNotification[]> => {
15
  return axios
16
    .get(`${baseUrl()}/assessment-plan-notifications?job_poster_id=${jobId}`)
17
    .then((response: ApiResponse): AssessmentPlanNotification[] => {
18
      if (!Array.isArray(response.data)) {
19
        throw Error("Response must be an array.");
20
      }
21
      return response.data.map(parseAssessmentPlanNotification);
22
    });
23
};
24
25
export const updateAssessmentPlanNotification = (
26
  notification: AssessmentPlanNotification,
27
): Promise<AssessmentPlanNotification> => {
28
  return axios
29
    .put(
30
      `${baseUrl()}/assessment-plan-notifications/${notification.id}`,
31
      notification,
32
    )
33
    .then(
34
      (response: ApiResponse): AssessmentPlanNotification =>
35
        parseAssessmentPlanNotification(
36
          response.data.assessment_plan_notification,
37
        ),
38
    );
39
};
40