Files
UT-Registration-Plus/src/pages/background/lib/clearCourses.ts
Razboy20 85769e9d2c refactor(UserSchedule): index by a unique id rather than name (#166)
* refactor(UserSchedule): index by a unique id rather than name

* refactor: Update parameter names in schedule function jsdocs

* refactor: change more instances of .name to .id

* refactor: Fix typo in variable name and update references

* refactor: Remove console.log statement

* fix(chromatic): Update ScheduleListItem story

* refactor: remove unused eslint rule
2024-03-14 23:09:04 -05:00

19 lines
658 B
TypeScript

import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
/**
* Clears the courses for a given schedule.
* @param scheduleId - The id of the schedule.
* @throws Error if the schedule does not exist.
*/
export default async function clearCourses(scheduleId: string): Promise<void> {
const schedules = await UserScheduleStore.get('schedules');
const schedule = schedules.find(schedule => schedule.id === scheduleId);
if (!schedule) {
throw new Error(`Schedule ${scheduleId} does not exist`);
}
schedule.courses = [];
schedule.updatedAt = Date.now();
await UserScheduleStore.set('schedules', schedules);
}