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