Passed
Push — feature/timeline-profile-page ( 94fe7b...b6c64d )
by Tristan
04:48
created

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

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 66
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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