Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/APIFunctions/SCEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export async function getEventByID(id, token) {
? { Authorization: `Bearer ${token}` }
: {};

const res = await fetch(`${SCEVENTS_API_URL}/events/${id}`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${id}`, window.location.origin);
const res = await fetch(url.href, {
headers,
});

Expand All @@ -58,7 +59,8 @@ export async function getEventByID(id, token) {
export async function getEventAttendanceSummary(id, token) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${id}/attendance`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${id}/attendance`, window.location.origin);
const res = await fetch(url.href, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand All @@ -78,7 +80,8 @@ export async function getEventAttendanceSummary(id, token) {
export async function createSCEvent(token, eventBody) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/`, {
const url = new URL(`${SCEVENTS_API_URL}/events/`, window.location.origin);
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -101,7 +104,8 @@ export async function createSCEvent(token, eventBody) {
export async function updateSCEvent(id, token, eventUpdates) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${id}`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${id}`, window.location.origin);
const res = await fetch(url.href, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -150,11 +154,9 @@ export async function deleteSCEvent(id, token) {
export async function getEventRegistrations(eventId, token, { limit = 50, offset = 0 } = {}) {
const status = new ApiResponse();
try {
const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/registrations`);
url.searchParams.set('limit', String(limit));
url.searchParams.set('offset', String(offset));
const params = new URLSearchParams({ limit: String(limit), offset: String(offset) });

const res = await fetch(url.href, {
const res = await fetch(`${SCEVENTS_API_URL}/events/${eventId}/registrations?${params}`, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand All @@ -174,7 +176,8 @@ export async function getEventRegistrations(eventId, token, { limit = 50, offset
export async function getEventRegistrationByRequestId(eventId, requestId, token) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${eventId}/registrations/${requestId}`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/registrations/${requestId}`, window.location.origin);
const res = await fetch(url.href, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand All @@ -194,7 +197,8 @@ export async function getEventRegistrationByRequestId(eventId, requestId, token)
export async function registerForEvent(eventId, token, payload) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${eventId}/register`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/register`, window.location.origin);
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -218,7 +222,8 @@ export async function registerForEvent(eventId, token, payload) {
export async function getMyEventRegistrationState(eventId, token) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${eventId}/registration/me`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/registration/me`, window.location.origin);
const res = await fetch(url.href, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand All @@ -239,7 +244,8 @@ export async function joinWaitlistForSCEvent(eventId, token) {
const status = new ApiResponse();

try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${eventId}/waitlist`, {
const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/waitlist`, window.location.origin);
const res = await fetch(url.href, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -254,7 +260,7 @@ export async function joinWaitlistForSCEvent(eventId, token) {
}
} catch (err) {
status.error = true;
status.responseData = err;
status.responseData = { error: err?.message || 'Failed to connect to SCEvents API' };
}

return status;
Expand Down
Loading