multiple schedule suppport kinda

This commit is contained in:
Sriram Hariharan
2023-03-15 23:54:07 -05:00
parent 6d4a4307cf
commit 6afd372945
30 changed files with 224 additions and 155 deletions

View File

@@ -45,6 +45,9 @@ export class Course {
courseName: string;
/** The unique identifier for which department that a course belongs to, i.e. CS, MAL, etc. */
department: string;
/** The number of credits that a course is worth */
creditHours: number;
/** Is the course open, closed, waitlisted, or cancelled? */
status: Status;
/** all the people that are teaching this course, and some metadata about their names */

View File

@@ -0,0 +1,35 @@
import { Serialized } from 'chrome-extension-toolkit';
import { Course } from './Course';
/**
* Represents a user's schedule that is stored in the extension
*/
export class UserSchedule {
courses: Course[];
id: string;
name: string;
constructor(schedule: Serialized<UserSchedule>) {
this.courses = schedule.courses.map(c => new Course(c));
this.id = schedule.id;
this.name = schedule.name;
}
containsCourse(course: Course): boolean {
return this.courses.some(c => c.uniqueId === course.uniqueId);
}
getCreditHours(): number {
return this.courses.reduce((acc, course) => acc + course.creditHours, 0);
}
addCourse(course: Course): void {
if (!this.containsCourse(course)) {
this.courses.push(course);
}
}
removeCourse(course: Course): void {
this.courses = this.courses.filter(c => c.uniqueId !== course.uniqueId);
}
}