diff --git a/src/tasks/scrape-sections.ts b/src/tasks/scrape-sections.ts index bd0a48b..a764921 100644 --- a/src/tasks/scrape-sections.ts +++ b/src/tasks/scrape-sections.ts @@ -40,7 +40,7 @@ export class ScrapeSectionsTask { } await db.serializable(this.pool, async trx => { - // Mark courses and sections in term as deleted by default + // Mark courses in term as deleted by default await db.update('Course', { deletedAt: new Date(), }, { @@ -48,12 +48,6 @@ export class ScrapeSectionsTask { year }).run(trx); - await db.update('Section', { - deletedAt: new Date(), - }, { - courseId: db.sql`${db.self} IN (SELECT ${'id'} FROM ${'Course'} WHERE ${'semester'} = ${db.param(semester)} AND ${'year'} = ${db.param(year)})` - }).run(trx); - // Upsert courses await db.upsert('Course', extensionCourses.map(extensionCourse => { const [minCredits, maxCredits] = this.getCreditsRangeFromCourse(extensionCourse); @@ -74,6 +68,15 @@ export class ScrapeSectionsTask { 'maxCredits' ]) }).run(trx); + }); + + await db.serializable(this.pool, async trx => { + // Mark sections in term as deleted by default + await db.update('Section', { + deletedAt: new Date(), + }, { + courseId: db.sql`${db.self} IN (SELECT ${'id'} FROM ${'Course'} WHERE ${'semester'} = ${db.param(semester)} AND ${'year'} = ${db.param(year)})` + }).run(trx); // Upsert sections const sectionsUpsertInput: Array> = extensionCourses.flatMap(extensionCourse => extensionCourse.sections.map(extensionSection => {