This repository was archived by the owner on Dec 28, 2022. It is now read-only.
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
67 lines (55 loc) · 1.78 KB
/
Copy pathapiHelper.js
File metadata and controls
67 lines (55 loc) · 1.78 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
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 const getServices = () => makeGenericGet('services');
export const getMentors = () => makeGenericGet('mentors');
export const getMentor = id => makeGenericGet(`mentors/${id}`);
export const getRequests = () => makeGenericGet('requests');
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 updateRequest({ request, status, mentor }) {
const authHeader = setAuthorizationHeader();
return axios.patch(`${config.backendUrl}/requests/${request}`, {
request: {
status,
mentor
}
}, {
headers: authHeader
});
}