Skip to content

Commit 4206b26

Browse files
committed
Fix: Schema bug with timetable generation
1 parent 09aa681 commit 4206b26

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import { generateWeeklyCourseEvents } from "../controllers/eventsController";
2-
import {
3-
categorizeValidOfferings,
4-
getMaxDays,
5-
getOfferings,
6-
getValidOfferings,
7-
getValidSchedules,
8-
GroupedOfferingList,
9-
groupOfferings,
10-
Offering,
11-
OfferingList,
12-
trim,
13-
} from "../controllers/generatorController";
142
import { supabase } from "../db/setupDb";
153
import { Request } from "express";
4+
import { GroupedOfferingList, Offering, OfferingList } from "../types/generatorTypes";
5+
import { categorizeValidOfferings, getMaxDays, getValidOfferings, groupOfferings, trim } from "../utils/generatorHelpers";
6+
import getOfferings from "../services/getOfferings";
7+
import { getValidSchedules } from "../services/getValidSchedules";
168

179
// Add all possible function names here
1810
export type FunctionNames =
@@ -260,7 +252,7 @@ export const availableFunctions: AvailableFunctions = {
260252
.maybeSingle();
261253

262254
if (existingTimetableError) {
263-
return { status: 400, error: existingTimetableError.message };
255+
return { status: 400, error: `Existing timetable with name: ${name}. Please rename timetable.`};
264256
}
265257

266258
if (existingTimetable) {
@@ -291,9 +283,9 @@ export const availableFunctions: AvailableFunctions = {
291283
await insertTimetable;
292284

293285
if (timetableError) {
294-
return { status: 400, error: timetableError.message };
286+
return { status: 400, error: "Timetable error" + timetableError.message };
295287
}
296-
288+
console.log("1")
297289
// Insert events
298290
for (const offering of schedule) {
299291
//Query course offering information
@@ -304,7 +296,7 @@ export const availableFunctions: AvailableFunctions = {
304296
.eq("id", offering.id)
305297
.maybeSingle();
306298

307-
if (offeringError) return { status: 400, error: offeringError.message };
299+
if (offeringError) return { status: 400, error: `Offering error id: ${offering.id} ` + offeringError.message };
308300

309301
if (!offeringData || offeringData.length === 0) {
310302
return {
@@ -366,7 +358,7 @@ export const availableFunctions: AvailableFunctions = {
366358
.select("*");
367359

368360
if (courseEventError) {
369-
return { status: 400, error: courseEventError.message };
361+
return { status: 400, error: "Coruse event error " + courseEventError.message };
370362
}
371363
}
372364

course-matrix/backend/src/models/timetable-form.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const RestrictionSchema = z.object({
7373
.describe("The type of restriction being applied"),
7474
days: z
7575
.array(DayOfWeekEnum)
76+
.default(["SU", "MO", "TU", "WE", "TH", "FR", "SA"])
7677
.describe("Specific days of the week this restriction applies to"),
7778
numDays: z
7879
.number()

course-matrix/backend/src/utils/generatorHelpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export function isValidOffering(
7474
break;
7575

7676
case RestrictionType.RestrictAfter:
77-
console.log("====");
78-
console.log(offering.end);
79-
console.log(restriction.endTime);
77+
// console.log("====");
78+
// console.log(offering.end);
79+
// console.log(restriction.endTime);
8080
if (offering.end > restriction.startTime) return false;
8181
break;
8282

@@ -97,7 +97,7 @@ export function isValidOffering(
9797
}
9898
}
9999

100-
console.log(offering);
100+
// console.log(offering);
101101
return true;
102102
}
103103

@@ -189,7 +189,7 @@ export async function canInsertList(
189189
toInsertList: Offering[],
190190
curList: Offering[],
191191
) {
192-
console.log(toInsertList);
192+
// console.log(toInsertList);
193193
return toInsertList.every((x) => canInsert(x, curList));
194194
}
195195

0 commit comments

Comments
 (0)