Skip to article
Documentation

src/lib/db/scope.ts

Linked repository file from this build.

import { and, eq, inArray, type SQL } from "drizzle-orm";
import type { Actor } from "@/lib/auth/actor";
import { examinerScope } from "@/lib/auth/scope";
import { reviewIndex } from "./schema";

/** SQL form of canAccessReview. Every list, count and export query filters with it. */
export function reviewScope(actor: Actor): SQL {
  const scope = examinerScope(actor);
  return and(
    eq(reviewIndex.program, actor.program),
    scope === "program" ? undefined : inArray(reviewIndex.examiner, scope),
  )!;
}