Passed
Push — dev ( 1fa567...2debb5 )
by
unknown
05:36
created

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

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 75
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 58
mnd 5
bc 5
fnc 0
dl 0
loc 75
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
/* eslint-disable camelcase */
2
import { baseUrl, parseDate } from "./base";
3
import { Experience, ExperienceSkill } from "../models/types";
4
5
export interface ExperienceResponse {
6
  experience: Experience;
7
  experienceSkills: ExperienceSkill[];
8
}
9
10
export const parseSingleExperience = (data: any): ExperienceResponse => {
11
  const { experience_skills, ...experience } = data;
12
  if (data.start_date) {
13
    experience.start_date = parseDate(data.start_date);
14
  }
15
  if (data.end_date) {
16
    experience.end_date = parseDate(data.end_date);
17
  }
18
  if (data.awarded_date) {
19
    experience.awarded_date = parseDate(data.awarded_date);
20
  }
21
  return {
22
    experience,
23
    experienceSkills: experience_skills,
24
  };
25
};
26
27
export const parseExperience = (data: any): ExperienceResponse[] =>
28
  data.map(parseSingleExperience);
29
30
export const parseExperienceSkill = (data: any): ExperienceSkill => {
31
  return {
32
    ...data,
33
    created_at: parseDate(data.created_at),
34
    updated_at: parseDate(data.updated_at),
35
  };
36
};
37
38
export const parseBatchExperienceSkills = (data: any): ExperienceSkill[] =>
39
  data.map(parseExperienceSkill);
40
41
export const getApplicantExperienceEndpoint = (applicantId: number): string =>
42
  `${baseUrl()}/applicants/${applicantId}/experience`;
43
44
export const getApplicationExperienceEndpoint = (
45
  applicationId: number,
46
): string => `${baseUrl(2)}/applications/${applicationId}/experience`;
47
48
/**
49
 * This endpoint can be used to update (PUT) or delete (DELETE) Experiences.
50
 */
51
export const getExperienceEndpoint = (
52
  id: number,
53
  type: Experience["type"],
54
): string => `${baseUrl()}/${type.replace("_", "-")}/${id}`;
55
56
/**
57
 * This endpoint is used for creating (POST) new Experiences. They must be associated with an Applicant.
58
 */
59
export const getCreateExperienceEndpoint = (
60
  applicantId: number,
61
  type: Experience["type"],
62
): string => {
63
  return `${baseUrl()}/applicants/${applicantId}/${type.replace("_", "-")}`;
64
};
65
66
export const getExperienceSkillEndpoint = (id: number | null = null): string =>
67
  `${baseUrl()}/experience-skills/${id ?? ""}`;
68
69
export const getBatchCreateExperienceSkillsEndpoint = (): string =>
70
  `${baseUrl()}/experience-skills/batch-store`;
71
export const getBatchUpdateExperienceSkillsEndpoint = (): string =>
72
  `${baseUrl()}/experience-skills/batch-update`;
73
export const getBatchDeleteExperienceSkillsEndpoint = (): string =>
74
  `${baseUrl()}/experience-skills/batch-destroy`;
75