@@ -54,7 +54,7 @@ function generateWeeklyCourseEvents(
5454 calendar_id : string ,
5555 offering_id : string ,
5656 semester_start_date : string ,
57- semester_end_date : string ,
57+ semester_end_date : string
5858) : any [ ] {
5959 //Map weekday code to JS day number
6060 const weekdayMap : { [ key : string ] : number } = {
@@ -199,7 +199,7 @@ export default {
199199 calendar_id ,
200200 offering_id ,
201201 semester_start_date ,
202- semester_end_date ,
202+ semester_end_date
203203 ) ;
204204 } else {
205205 //If no semester dates provided, insert a single event using the provided event_day
@@ -347,6 +347,10 @@ export default {
347347 semester_end_date,
348348 } = req . body ;
349349
350+ if ( ! calendar_id ) {
351+ return res . status ( 400 ) . json ( { error : "calendar id is required" } ) ;
352+ }
353+
350354 // Retrieve the authenticated user
351355 const { data : authData , error : authError } =
352356 await supabase . auth . getUser ( ) ;
@@ -372,6 +376,7 @@ export default {
372376 }
373377
374378 if ( new_offering_id ) {
379+ console . log ( old_offering_id ) ;
375380 //If an offering_id is provided: Updating a courseEvent
376381 //If old_offering_id does not match throw an error
377382 const { data : oldofferingData , error : oldofferingError } =
@@ -380,13 +385,17 @@ export default {
380385 . from ( "course_events" )
381386 . select ( "*" )
382387 . eq ( "offering_id" , old_offering_id )
383- . maybeSingle ( ) ;
388+ . eq ( "calendar_id" , calendar_id ) ;
389+
390+ console . log ( oldofferingData ) ;
391+ console . log ( oldofferingError ) ;
384392 if ( oldofferingError || ! oldofferingData ) {
385393 return res . status ( 400 ) . json ( {
386394 error :
387395 "Invalid current offering_id or current offering id not found." ,
388396 } ) ;
389397 }
398+ console . log ( old_offering_id ) ;
390399
391400 const { data : newofferingData , error : newofferingError } =
392401 await supabase
@@ -400,6 +409,7 @@ export default {
400409 error : "Invalid offering_id or course offering not found." ,
401410 } ) ;
402411 }
412+ console . log ( new_offering_id ) ;
403413
404414 const courseEventName = `${ newofferingData . code } - ${ newofferingData . meeting_section } ` ;
405415 const courseDay = newofferingData . day ;
@@ -416,7 +426,7 @@ export default {
416426 calendar_id ,
417427 new_offering_id ,
418428 semester_start_date ,
419- semester_end_date ,
429+ semester_end_date
420430 ) ;
421431 } else {
422432 let eventDate = getNextWeekDayOccurance ( courseDay ) ;
@@ -491,6 +501,10 @@ export default {
491501 const { id } = req . params ;
492502 const { calendar_id, event_type, offering_id } = req . query ;
493503
504+ if ( ! calendar_id ) {
505+ return res . status ( 400 ) . json ( { error : "calendar id is required" } ) ;
506+ }
507+
494508 // Retrieve the authenticated user
495509 const { data : authData , error : authError } =
496510 await supabase . auth . getUser ( ) ;
@@ -535,7 +549,9 @@ export default {
535549 deleteQuery = deleteQuery . eq ( "id" , id ) ;
536550 }
537551
538- const { error : deleteError } = await deleteQuery . select ( "*" ) ;
552+ const { error : deleteError } = await deleteQuery
553+ . eq ( "calendar_id" , calendar_id )
554+ . select ( "*" ) ;
539555 if ( deleteError )
540556 return res . status ( 400 ) . json ( { error : deleteError . message } ) ;
541557
0 commit comments