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
56 lines (49 loc) · 1.46 KB
/
Copy pathapiHelper.js
File metadata and controls
56 lines (49 loc) · 1.46 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
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.apiUrl}/${endpoint}`, {
headers: authHeader
})
.then(({ data }) => data);
}
export function postBackend(path, body) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.apiUrl}/${path}`, body, { headers: authHeader });
}
export function patchBackend(path, body) {
const authHeader = setAuthorizationHeader();
return axios.patch(`${config.apiUrl}/${path}`, body, { headers: authHeader });
}
export const getMentorshipData = () => makeGenericGet('airtable/mentorships');
export const getScholarships = () => makeGenericGet('scholarships');
export const getScholarship = id => makeGenericGet(`scholarships/${id}`);
export function createMentorRequest({
slackUser,
email,
serviceIds,
skillsets,
additionalDetails,
mentorId
}) {
const authHeader = setAuthorizationHeader();
return axios.post(`${config.apiUrl}/airtable/mentorships`, '', {
params: {
slack_user: slackUser,
email,
services: serviceIds,
skillsets,
additional_details: additionalDetails,
mentor_requested: mentorId
},
headers: authHeader
});
}