Passed
Push — feature/profile-skills-finaliz... ( 961836...9d523b )
by Tristan
06:45
created

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

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 79
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 58
mnd 3
bc 3
fnc 0
dl 0
loc 79
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { ResponseData, baseUrl, ApiResponse, axios } from "./base";
2
import { RatingGuideAnswer, RatingGuideQuestion } from "../models/types";
3
4
export const parseRatingGuideAnswer = (
5
  data: ResponseData,
6
): RatingGuideAnswer => ({
7
  id: Number(data.id),
8
  rating_guide_question_id: Number(data.rating_guide_question_id),
9
  criterion_id: data.criterion_id ? Number(data.criterion_id) : null,
10
  expected_answer: data.expected_answer ? String(data.expected_answer) : null,
11
});
12
13
export const parseRatingGuideQuestion = (
14
  data: ResponseData,
15
): RatingGuideQuestion => ({
16
  id: Number(data.id),
17
  job_poster_id: Number(data.job_poster_id),
18
  assessment_type_id: Number(data.assessment_type_id),
19
  question: data.question ? String(data.question) : null,
20
});
21
22
export const updateRatingGuideAnswer = (
23
  ratingGuideAnswer: RatingGuideAnswer,
24
): Promise<RatingGuideAnswer> => {
25
  return axios
26
    .put(
27
      `${baseUrl()}/rating-guide-answers/${ratingGuideAnswer.id}`,
28
      ratingGuideAnswer,
29
    )
30
    .then(
31
      (response: ApiResponse): RatingGuideAnswer =>
32
        parseRatingGuideAnswer(response.data.rating_guide_answer),
33
    );
34
};
35
36
export const updateRatingGuideQuestion = (
37
  ratingGuideQuestion: RatingGuideQuestion,
38
): Promise<RatingGuideQuestion> => {
39
  return axios
40
    .put(
41
      `${baseUrl()}/rating-guide-questions/${ratingGuideQuestion.id}`,
42
      ratingGuideQuestion,
43
    )
44
    .then(
45
      (response: ApiResponse): RatingGuideQuestion =>
46
        parseRatingGuideQuestion(response.data.rating_guide_question),
47
    );
48
};
49
50
export const createRatingGuideAnswer = (
51
  ratingGuideAnswer: RatingGuideAnswer,
52
): Promise<RatingGuideAnswer> => {
53
  return axios
54
    .post(`${baseUrl()}/rating-guide-answers`, ratingGuideAnswer)
55
    .then(
56
      (response: ApiResponse): RatingGuideAnswer =>
57
        parseRatingGuideAnswer(response.data.rating_guide_answer),
58
    );
59
};
60
61
export const createRatingGuideQuestion = (
62
  ratingGuideQuestion: RatingGuideQuestion,
63
): Promise<RatingGuideQuestion> => {
64
  return axios
65
    .post(`${baseUrl()}/rating-guide-questions`, ratingGuideQuestion)
66
    .then(
67
      (response: ApiResponse): RatingGuideQuestion =>
68
        parseRatingGuideQuestion(response.data.rating_guide_question),
69
    );
70
};
71
72
export const deleteRatingGuideAnswer = async (id: number): Promise<void> => {
73
  await axios.delete(`${baseUrl()}/rating-guide-answers/${id}`);
74
};
75
76
export const deleteRatingGuideQuestion = async (id: number): Promise<void> => {
77
  await axios.delete(`${baseUrl()}/rating-guide-questions/${id}`);
78
};
79