File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
course-matrix/backend/src/controllers Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,26 @@ export default {
2525 . json ( { error : "timetable title and semester are required" } ) ;
2626 }
2727
28+ // Check if a timetable with the same title already exist for this user
29+ const { data : existingTimetable , error : existingTimetableError } =
30+ await supabase
31+ . schema ( "timetable" )
32+ . from ( "timetables" )
33+ . select ( "id" )
34+ . eq ( "user_id" , user_id )
35+ . eq ( "timetable_title" , timetable_title )
36+ . maybeSingle ( ) ;
37+
38+ if ( existingTimetableError ) {
39+ return res . status ( 400 ) . json ( { error : existingTimetableError . message } ) ;
40+ }
41+
42+ if ( existingTimetable ) {
43+ return res
44+ . status ( 400 )
45+ . json ( { error : "A timetable with this title already exists" } ) ;
46+ }
47+
2848 //Create query to insert the user_id and timetable_title into the db
2949 let insertTimetable = supabase
3050 . schema ( "timetable" )
You can’t perform that action at this time.
0 commit comments