src/lib/db/inbox-query.ts
Linked repository file from this build.
import { z } from "zod";
import type { Actor } from "@/features/reviews/types";
const timestamp = z.iso
.datetime({ offset: true })
.transform((value) => new Date(value).toISOString());
const page = z.coerce.number().int().min(0).max(1_000_000).default(0);
/** Bound both individual result sets and offsets supplied by the browser. */
export const inboxQuerySchema = z
.object({
pageSize: z.coerce.number().int().min(1).max(100).default(20),
section: z.enum(["all", "new", "touched", "queue", "events"]).default("all"),
newPage: page,
touchedPage: page,
queuePage: page,
eventsPage: page,
since: timestamp.optional(),
asOf: timestamp.optional(),
})
.refine((value) => !value.since || !value.asOf || value.since <= value.asOf, {
message: "The news start must not follow its cutoff.",
path: ["since"],
});
export type InboxQuery = z.infer<typeof inboxQuerySchema>;
export function awaitingStates(role: Actor["role"]): string[] {
if (role === "supervisor") return ["awaiting_review"];
if (role === "pec") return ["awaiting_pec_approval"];
if (role === "program_manager")
return ["awaiting_review", "awaiting_manager", "awaiting_cao_response"];
return ["awaiting_review", "awaiting_pec_approval", "awaiting_manager", "awaiting_cao_response"];
}