Skip to content

Commit

Permalink
fix: invalid global id during createInvitation
Browse files Browse the repository at this point in the history
Reviewers: WillTwait

Reviewed By: WillTwait

Pull Request: #22
  • Loading branch information
willruggiano authored Aug 14, 2024
1 parent aa9a07c commit 6778097
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/datasources/worker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { NotFoundError } from "@/errors";
import type { Worker } from "@/schema";
import type { WithKey } from "@/util";
import Dataloader from "dataloader";
import type { Request } from "express";
import { sql } from "./postgres";

export default (_: Request) =>
new Dataloader<string, Worker>(async keys => {
const rows = await sql<Worker[]>`
const rows = await sql<WithKey<Worker>[]>`
SELECT
w.workerinstanceuuid AS id,
w.workerinstanceuuid AS _key,
encode(('worker:' || w.workerinstanceuuid)::bytea, 'base64') as id,
(w.workerinstanceenddate IS NULL OR w.workerinstanceenddate > now()) AS active,
w.workerinstancestartdate::text AS "activatedAt",
w.workerinstanceenddate::text AS "deactivatedAt",
Expand All @@ -27,7 +29,7 @@ export default (_: Request) =>
`;

const byKey = rows.reduce(
(acc, row) => acc.set(row.id as string, row),
(acc, row) => acc.set(row._key as string, row),
new Map<string, Worker>(),
);

Expand Down

0 comments on commit 6778097

Please sign in to comment.