Skip to content

Commit 05ed46e

Browse files
committed
Made changes to SCEvents.js with Steven's comments
1 parent 6e8ad19 commit 05ed46e

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

src/APIFunctions/SCEvents.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { ApiResponse } from './ApiResponses';
22

3-
const SCEVENTS_BASE =
4-
(typeof process !== 'undefined' && process.env.REACT_APP_SCEVENTS_URL) ||
5-
'http://localhost:8002';
6-
7-
function eventsUrl(path) {
8-
const base = SCEVENTS_BASE.replace(/\/$/, '');
9-
const p = path.startsWith('/') ? path : `/${path}`;
10-
return `${base}${p}`;
11-
}
3+
const SCEVENTS_API_URL = 'http://localhost:8002';
124

135
export async function getAllSCEvents() {
146
const status = new ApiResponse();
157
try {
16-
const res = await fetch(eventsUrl('/events/'));
8+
const res = await fetch(`${SCEVENTS_API_URL}/events/`);
179
const result = await res.json();
1810
status.responseData = result;
1911
if (!res.ok) {
@@ -29,43 +21,37 @@ export async function getAllSCEvents() {
2921
export async function getEventByID(id) {
3022
const status = new ApiResponse();
3123
try {
32-
const res = await fetch(eventsUrl(`/events/${id}`));
24+
const res = await fetch(`${SCEVENTS_API_URL}/events/${id}`);
3325
const result = await res.json();
3426
status.responseData = result;
3527
if (!res.ok) {
3628
status.error = true;
3729
}
3830
} catch (err) {
39-
status.responseData = err;
4031
status.error = true;
32+
status.responseData = err;
4133
}
4234
return status;
4335
}
4436

4537
export async function createSCEvent(eventBody) {
4638
const status = new ApiResponse();
47-
status.statusCode = null;
4839
try {
49-
const res = await fetch(eventsUrl('/events/'), {
40+
const res = await fetch(`${SCEVENTS_API_URL}/events/`, {
5041
method: 'POST',
5142
headers: {
5243
'Content-Type': 'application/json',
5344
},
5445
body: JSON.stringify(eventBody),
5546
});
56-
status.statusCode = res.status;
5747
const body = await res.json();
58-
if (res.ok) {
59-
status.responseData = body;
60-
} else {
48+
status.responseData = body;
49+
if (!res.ok) {
6150
status.error = true;
62-
status.responseData = body;
6351
}
6452
} catch (err) {
6553
status.error = true;
66-
status.responseData =
67-
err && typeof err.message === 'string' ? err.message : String(err);
68-
status.networkError = true;
54+
status.responseData = err;
6955
}
7056
return status;
7157
}

0 commit comments

Comments
 (0)