Skip to content

Commit

Permalink
fix(db): reference the correct table
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Jul 12, 2024
1 parent 4608985 commit d3bfcde
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/server/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type AvailableLabs = InferOutput<typeof AvailableLabs>;
export type QueriedFaculty = InferOutput<typeof QueriedFaculty>;
export type TaggedStudentsWithLabs = InferOutput<typeof TaggedStudentsWithLabs>;

export type Sql = postgres.Sql<{ bigint: bigint }>;
export type Sql = postgres.Sql<{ bigint: bigint; }>;

export class Database implements Loggable {
#sql: Sql;
Expand Down Expand Up @@ -245,9 +245,9 @@ export class Database implements Loggable {
@timed async autoAcknowledgeLabsWithoutPreferences(draft: Draft['draft_id']) {
const sql = this.#sql;
const d = sql`SELECT draft_id, curr_round FROM drap.drafts WHERE draft_id = ${draft}`;
const drafted = sql`SELECT lab_id, count(student_email) draftees FROM draft JOIN drap.faculty_choices_emails USING (draft_id) GROUP BY lab_id`;
const selected = sql`SELECT labs[curr_round] lab_id FROM draft JOIN drap.student_ranks USING (draft_id) LEFT JOIN drap.faculty_choices_emails ON email = student_email WHERE student_email IS NULL`;
const values = sql`WITH d AS (${d}), drafted AS (${drafted}), selected AS (${selected}) SELECT draft_id, curr_round, lab_id FROM draft, drap.labs LEFT JOIN drafted USING (lab_id) LEFT JOIN selected USING (lab_id) WHERE coalesce(draftees, 0) < quota`;
const drafted = sql`SELECT lab_id, count(student_email) draftees FROM d JOIN drap.faculty_choices_emails USING (draft_id) GROUP BY lab_id`;
const selected = sql`SELECT labs[curr_round] lab_id FROM d JOIN drap.student_ranks USING (draft_id) LEFT JOIN drap.faculty_choices_emails ON email = student_email WHERE student_email IS NULL`;
const values = sql`WITH d AS (${d}), drafted AS (${drafted}), selected AS (${selected}) SELECT draft_id, curr_round, lab_id FROM d, drap.labs LEFT JOIN drafted USING (lab_id) LEFT JOIN selected USING (lab_id) WHERE coalesce(draftees, 0) < quota`;
const { count } = await sql`INSERT INTO drap.faculty_choices (draft_id, round, lab_id) ${values}`;
return count;
}
Expand Down

0 comments on commit d3bfcde

Please sign in to comment.