import { asc, isNull } from "drizzle-orm"; import { db } from "@/db/client"; import { editorialAccounts } from "@/db/schema"; import { AlbumGrantError, albumGrantService, type AlbumAccessOverviewAlbum, } from "@/modules/albums/grants"; export type EditorialOption = { id: string; name: string }; export async function loadAlbumAccess( service: Pick = albumGrantService, ): Promise<{ albums: AlbumAccessOverviewAlbum[]; unavailable: boolean }> { try { const albums = await service.listAlbumAccessOverview(); return { albums, unavailable: false }; } catch (error) { if (error instanceof AlbumGrantError && error.code === "IMMICH_UNAVAILABLE") { return { albums: [], unavailable: true }; } throw error; } } /** * Bulk-grant targets: every non-archived editorial. Archived accounts cannot * log in anymore, so they stay out of the selection; grants they still hold * remain visible in the overview. */ export async function loadAssignableEditorials(): Promise { return db .select({ id: editorialAccounts.id, name: editorialAccounts.name }) .from(editorialAccounts) .where(isNull(editorialAccounts.archivedAt)) .orderBy(asc(editorialAccounts.name)); }