Skip to content

Commit ea8454e

Browse files
Mt/scrum 137 check timetable duplicated name (#70)
1 parent 3d814b0 commit ea8454e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

course-matrix/backend/src/controllers/timetablesController.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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")

0 commit comments

Comments
 (0)