Skip to content

Commit a166876

Browse files
thomasyzy7dawangkkevin-lann
authored
Ty/scrum 156 + 157 (#112)
Co-authored-by: dawangk <[email protected]> Co-authored-by: Kevin Lan <[email protected]>
1 parent 198f5f2 commit a166876

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

course-matrix/backend/src/constants/availableFunctions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ export const availableFunctions: AvailableFunctions = {
197197
try {
198198
// Extract event details and course information from the request
199199
const { name, semester, courses, restrictions } = args;
200+
if (name.length > 50) {
201+
return {
202+
status: 400,
203+
error: "timetable title is over 50 characters long",
204+
};
205+
}
200206

201207
const courseOfferingsList: OfferingList[] = [];
202208
const validCourseOfferingsList: GroupedOfferingList[] = [];

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import asyncHandler from "../middleware/asyncHandler";
33
import { supabase } from "../db/setupDb";
44
import { start } from "repl";
55

6+
function getReadingWeekStart(start_date: string) {
7+
return start_date === "2025-05-02"
8+
? "2025-06-15"
9+
: start_date === "2025-09-02"
10+
? "2025-10-26"
11+
: "2026-02-16";
12+
}
13+
14+
function getReadingWeekEnd(start_date: string) {
15+
return start_date === "2025-05-02"
16+
? "2025-06-22"
17+
: start_date === "2025-09-02"
18+
? "2025-11-01"
19+
: "2026-02-22";
20+
}
621
/**
722
* Helper method to generate weekly course events.
823
* @param courseEventName - The name of the course event (typically derived from the offering code and meeting section).
@@ -67,6 +82,13 @@ export function generateWeeklyCourseEvents(
6782
SA: 6,
6883
};
6984

85+
const rw_start = new Date(
86+
getReadingWeekStart(semester_start_date) + "T00:00:00-05:00",
87+
);
88+
const rw_end = new Date(
89+
getReadingWeekEnd(semester_start_date) + "T00:00:00-05:00",
90+
);
91+
7092
const targetWeekday = weekdayMap[courseDay];
7193
if (targetWeekday === undefined) {
7294
throw new Error("Invalid course day provided");
@@ -91,17 +113,19 @@ export function generateWeeklyCourseEvents(
91113
let eventsToInsert: any[] = [];
92114
//Loop through the semester, adding an event for each week on the targeted weekday
93115
while (currentDate <= semesterEndObj) {
94-
eventsToInsert.push({
95-
user_id,
96-
calendar_id,
97-
event_name: courseEventName,
98-
//Convert the occurrence of date to YYYY-MM-DD format
99-
event_date: currentDate.toISOString().split("T")[0],
100-
event_start: courseStartTime,
101-
event_end: courseEndTime,
102-
event_description: null,
103-
offering_id,
104-
});
116+
if (currentDate < rw_start || currentDate > rw_end) {
117+
eventsToInsert.push({
118+
user_id,
119+
calendar_id,
120+
event_name: courseEventName,
121+
//Convert the occurrence of date to YYYY-MM-DD format
122+
event_date: currentDate.toISOString().split("T")[0],
123+
event_start: courseStartTime,
124+
event_end: courseEndTime,
125+
event_description: null,
126+
offering_id,
127+
});
128+
}
105129
//Cycle to the next week
106130
currentDate.setDate(currentDate.getDate() + 7);
107131
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export default {
2525
.status(400)
2626
.json({ error: "timetable title and semester are required" });
2727
}
28+
// Timetables cannot be longer than 50 characters.
29+
if (timetable_title.length > 50) {
30+
return res
31+
.status(400)
32+
.json({ error: "Timetable Title cannot be over 50 characters long" });
33+
}
2834

2935
// Check if a timetable with the same title already exist for this user
3036
const { data: existingTimetable, error: existingTimetableError } =
@@ -169,6 +175,13 @@ export default {
169175
});
170176
}
171177

178+
// Timetables cannot be longer than 50 characters.
179+
if (timetable_title.length > 50) {
180+
return res
181+
.status(400)
182+
.json({ error: "Timetable Title cannot be over 50 characters long" });
183+
}
184+
172185
//Retrieve the authenticated user
173186
const user_id = (req as any).user.id;
174187

0 commit comments

Comments
 (0)