forked from OperationCode/operationcode_frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiHelper.js
More file actions
98 lines (81 loc) · 2.54 KB
/
Copy pathapiHelper.js
File metadata and controls
98 lines (81 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import axios from 'axios';
import config from 'config/environment';
import Cookies from 'universal-cookie';
export const setAuthorizationHeader = () => {
const cookies = new Cookies();
return {
Authorization: `bearer ${cookies.get('token')}`
};
};
function makeGenericGet(endpoint) {
const authHeader = setAuthorizationHeader();
return axios.get(`${config.backendUrl}/${endpoint}`, {
headers: authHeader
}).then(({ data }) => data);
}
export function postBackend(path, body) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.backendUrl}/${path}`, body, { headers: authHeader });
}
export function patchBackend(path, body) {
const authHeader = setAuthorizationHeader();
return axios.patch(`${config.backendUrl}/${path}`, body, { headers: authHeader });
}
export function joinSquad(id) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.backendUrl}/squads/${id}/join`, {
request: {
}
}, {
headers: authHeader
}).then(({ data }) => data);
}
export const getServices = () => makeGenericGet('services');
export const getMentors = () => makeGenericGet('mentors');
export const getMentor = id => makeGenericGet(`mentors/${id}`);
export const getRequests = () => makeGenericGet('requests');
export const getSquads = () => makeGenericGet('squads');
export const getScholarships = () => makeGenericGet('scholarships');
export const getScholarship = id => makeGenericGet(`scholarships/${id}`);
export function postRequest({ language, additionalDetails, mentor, service }) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.backendUrl}/requests`, {
request: {
details: additionalDetails,
requested_mentor_id: mentor,
service_id: service,
language
}
}, {
headers: authHeader
});
}
export function postSquads({ name, leaderId, description, minimum, maximum, skillLevel, activities, endCondition, mentorIds }) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.backendUrl}/squads`, {
squad: {
name,
leader_id: leaderId,
description,
minimum,
maximum,
skill_level: skillLevel,
activities,
end_condition: endCondition,
mentor_ids: mentorIds
}
}, {
headers: authHeader
});
}
export function updateRequest({ request, status, mentor }) {
const authHeader = setAuthorizationHeader();
return axios.patch(`${config.backendUrl}/requests/${request}`, {
request: {
status,
mentor
}
}, {
headers: authHeader
});
}