-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathSCEvents.js
More file actions
55 lines (46 loc) · 1.11 KB
/
SCEvents.js
File metadata and controls
55 lines (46 loc) · 1.11 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
import { ApiResponse } from './ApiResponses';
const SCEVENTS_API_URL = 'http://localhost:8080';
export async function getAllSCEvents() {
let status = new ApiResponse();
try {
const url = new URL('/events/', SCEVENTS_API_URL);
const res = await fetch(url.href, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = err;
}
return status;
}
export async function getEventByID(id) {
let status = new ApiResponse();
try {
const url = new URL(`/events/${id}`, SCEVENTS_API_URL);
const res = await fetch(url.href, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = err;
}
return status;
}