@@ -117,6 +117,7 @@ import timeGridPlugin from "@fullcalendar/timegrid"
117117import interactionPlugin from " @fullcalendar/interaction"
118118import Dialog from " primevue/dialog"
119119import { DateTime } from " luxon"
120+ import calendarService from " ../../services/calendarService"
120121
121122import CalendarSectionHeader from " ../../components/ccalendarevent/CalendarSectionHeader.vue"
122123
@@ -258,20 +259,7 @@ async function fetchSessions() {
258259 isLoadingSessions .value = true
259260 errorMessage .value = " "
260261
261- const resp = await fetch (" /api/calendar/my-students-schedule" , {
262- method: " GET" ,
263- headers: { Accept: " application/json" },
264- })
265-
266- if (! resp .ok ) {
267- const text = await resp .text ().catch (() => " " )
268- console .error (" [MyStudentsSchedule] Sessions request failed" , resp .status , text)
269- errorMessage .value = t (" Failed to load sessions" )
270- sessions .value = []
271- return
272- }
273-
274- const data = await resp .json ()
262+ const data = await calendarService .getMyStudentsSchedule ()
275263 sessions .value = Array .isArray (data) ? data : []
276264 } catch (e) {
277265 console .error (" [MyStudentsSchedule] Unexpected error" , e)
@@ -378,26 +366,18 @@ async function fetchEvents(info, successCallback, failureCallback) {
378366 const start = DateTime .fromJSDate (info .start ).toISO ()
379367 const end = DateTime .fromJSDate (info .end ).toISO ()
380368
381- const url = ` /api/calendar/my-students-schedule?sid=${ encodeURIComponent (sid)} &start=${ encodeURIComponent (
382- start,
383- )} &end=${ encodeURIComponent (end)} `
384-
385- const resp = await fetch (url, { method: " GET" , headers: { Accept: " application/json" } })
386-
387- if (! resp .ok ) {
388- const text = await resp .text ().catch (() => " " )
389- console .error (" [MyStudentsSchedule] Events request failed" , resp .status , text)
390- errorMessage .value = resp .status === 403 ? t (" Not allowed" ) : t (" Failed to load events" )
391- successCallback ([])
392- return
393- }
394-
395- const data = await resp .json ()
369+ const data = await calendarService .getMyStudentsSchedule ({ sid, start, end })
396370 successCallback (Array .isArray (data) ? data : [])
397371 } catch (e) {
398- console .error (" [MyStudentsSchedule] Unexpected error" , e)
399- errorMessage .value = t (" Failed to load events" )
400- failureCallback? .(e)
372+ if (e? .response ) {
373+ console .error (" [MyStudentsSchedule] Events request failed" , e .response .status )
374+ errorMessage .value = e .response .status === 403 ? t (" Not allowed" ) : t (" Failed to load events" )
375+ successCallback ([])
376+ } else {
377+ console .error (" [MyStudentsSchedule] Unexpected error" , e)
378+ errorMessage .value = t (" Failed to load events" )
379+ failureCallback? .(e)
380+ }
401381 }
402382}
403383
0 commit comments