From 9af3d9862e79cd1f89a40f5b370bc9932a31992e Mon Sep 17 00:00:00 2001 From: Khoa Ng Date: Thu, 30 Apr 2026 19:03:23 -0700 Subject: [PATCH 1/2] Fix SCEvents API functions and add registration/me endpoint support --- src/APIFunctions/SCEvents.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/APIFunctions/SCEvents.js b/src/APIFunctions/SCEvents.js index 1aaad7ef2..8c18b89c2 100644 --- a/src/APIFunctions/SCEvents.js +++ b/src/APIFunctions/SCEvents.js @@ -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, }); @@ -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}`, }, @@ -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', @@ -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', @@ -150,7 +154,7 @@ 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`); + const url = new URL(`${SCEVENTS_API_URL}/events/${eventId}/registrations`, window.location.origin); url.searchParams.set('limit', String(limit)); url.searchParams.set('offset', String(offset)); @@ -174,7 +178,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}`, }, @@ -194,7 +199,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', @@ -218,7 +224,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}`, }, @@ -239,7 +246,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}`, From ab469bc92044f129ae9b322362848eaf9d426cc8 Mon Sep 17 00:00:00 2001 From: Khoa Ng Date: Sat, 2 May 2026 17:39:19 -0700 Subject: [PATCH 2/2] fix the incorrect url --- src/APIFunctions/SCEvents.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/APIFunctions/SCEvents.js b/src/APIFunctions/SCEvents.js index 8c18b89c2..ec2d48d17 100644 --- a/src/APIFunctions/SCEvents.js +++ b/src/APIFunctions/SCEvents.js @@ -154,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`, window.location.origin); - 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}`, }, @@ -262,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;