all repos — stealth-developers @ 32e571c080df75ef430ed79c120546abdf71328e

apps/api/src/lib/access.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
import type { Actor, TicketWithRelations } from "@stealth-developers/db";

export function hasAccessToTicket(
	actor: Actor,
	ticket: TicketWithRelations,
	{ requireModerator = false }: { requireModerator?: boolean } = {},
) {
	const isModerator = actor.moderator;
	if (requireModerator) return isModerator;

	if (actor.discordId === ticket.subjectActor?.discordId) return true;
	if (isModerator) return true;

	return false;
}