Files
Epicnabbo-Catalogus-Updated…/src/lib/admin/rank-authority.ts
T
2026-07-13 21:57:41 +02:00

27 lines
752 B
TypeScript

import type { AuthorizationActor } from "@/lib/admin/authorization-policy";
export interface RankAuthorityDb {
user: {
findUnique(args: {
where: { id: number };
select: { id: true; username: true; rank: true };
}): Promise<{ id: number; username: string; rank: number } | null>;
};
highestRank(): Promise<number | null>;
}
export async function resolveAuthorizationState(
userId: number,
db: RankAuthorityDb,
): Promise<{ actor: AuthorizationActor; highestRank: number | null } | null> {
const [user, highestRank] = await Promise.all([
db.user.findUnique({
where: { id: userId },
select: { id: true, username: true, rank: true },
}),
db.highestRank(),
]);
if (!user) return null;
return { actor: user, highestRank };
}