diff --git a/course-matrix/backend/src/constants/availableFunctions.ts b/course-matrix/backend/src/constants/availableFunctions.ts index 0d540011..03b16dd1 100644 --- a/course-matrix/backend/src/constants/availableFunctions.ts +++ b/course-matrix/backend/src/constants/availableFunctions.ts @@ -195,6 +195,12 @@ export const availableFunctions: AvailableFunctions = { try { // Extract event details and course information from the request const { name, semester, courses, restrictions } = args; + if (name.length > 50) { + return { + status: 400, + error: "timetable title is over 50 characters long", + }; + } const courseOfferingsList: OfferingList[] = []; const validCourseOfferingsList: GroupedOfferingList[] = []; diff --git a/course-matrix/backend/src/controllers/eventsController.ts b/course-matrix/backend/src/controllers/eventsController.ts index c70fae10..fab4aae8 100644 --- a/course-matrix/backend/src/controllers/eventsController.ts +++ b/course-matrix/backend/src/controllers/eventsController.ts @@ -3,6 +3,21 @@ import asyncHandler from "../middleware/asyncHandler"; import { supabase } from "../db/setupDb"; import { start } from "repl"; +function getReadingWeekStart(start_date: string) { + return start_date === "2025-05-02" + ? "2025-06-15" + : start_date === "2025-09-02" + ? "2025-10-26" + : "2026-02-16"; +} + +function getReadingWeekEnd(start_date: string) { + return start_date === "2025-05-02" + ? "2025-06-22" + : start_date === "2025-09-02" + ? "2025-11-01" + : "2026-02-22"; +} /** * Helper method to generate weekly course events. * @param courseEventName - The name of the course event (typically derived from the offering code and meeting section). @@ -67,6 +82,13 @@ export function generateWeeklyCourseEvents( SA: 6, }; + const rw_start = new Date( + getReadingWeekStart(semester_start_date) + "T00:00:00-05:00", + ); + const rw_end = new Date( + getReadingWeekEnd(semester_start_date) + "T00:00:00-05:00", + ); + const targetWeekday = weekdayMap[courseDay]; if (targetWeekday === undefined) { throw new Error("Invalid course day provided"); @@ -91,17 +113,19 @@ export function generateWeeklyCourseEvents( let eventsToInsert: any[] = []; //Loop through the semester, adding an event for each week on the targeted weekday while (currentDate <= semesterEndObj) { - eventsToInsert.push({ - user_id, - calendar_id, - event_name: courseEventName, - //Convert the occurrence of date to YYYY-MM-DD format - event_date: currentDate.toISOString().split("T")[0], - event_start: courseStartTime, - event_end: courseEndTime, - event_description: null, - offering_id, - }); + if (currentDate < rw_start || currentDate > rw_end) { + eventsToInsert.push({ + user_id, + calendar_id, + event_name: courseEventName, + //Convert the occurrence of date to YYYY-MM-DD format + event_date: currentDate.toISOString().split("T")[0], + event_start: courseStartTime, + event_end: courseEndTime, + event_description: null, + offering_id, + }); + } //Cycle to the next week currentDate.setDate(currentDate.getDate() + 7); } diff --git a/course-matrix/backend/src/controllers/timetablesController.ts b/course-matrix/backend/src/controllers/timetablesController.ts index 77a59741..d7b3b4de 100644 --- a/course-matrix/backend/src/controllers/timetablesController.ts +++ b/course-matrix/backend/src/controllers/timetablesController.ts @@ -25,6 +25,12 @@ export default { .status(400) .json({ error: "timetable title and semester are required" }); } + // Timetables cannot be longer than 50 characters. + if (timetable_title.length > 50) { + return res + .status(400) + .json({ error: "Timetable Title cannot be over 50 characters long" }); + } // Check if a timetable with the same title already exist for this user const { data: existingTimetable, error: existingTimetableError } = @@ -169,6 +175,13 @@ export default { }); } + // Timetables cannot be longer than 50 characters. + if (timetable_title.length > 50) { + return res + .status(400) + .json({ error: "Timetable Title cannot be over 50 characters long" }); + } + //Retrieve the authenticated user const user_id = (req as any).user.id;