Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions course-matrix/backend/src/constants/availableFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
46 changes: 35 additions & 11 deletions course-matrix/backend/src/controllers/eventsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions course-matrix/backend/src/controllers/timetablesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand Down Expand Up @@ -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;

Expand Down