1
0
Fork 0
polaris-task-force/src/lib/tickets/staff.ts
Z8MB1E eef1b11bb1 feat(rbac): migrate server actions and service layers to RBAC
Replace hasRoles calls with hasPermission in all server actions and page
components. Update qualification checks (logistics, intelligence) to use
permission-based checks instead of role name matching. Update staff lookup
in tickets/staff.ts to query roles collection. Use enlistmentDate field
on profile page instead of createdAt.
2026-08-19 19:47:57 -04:00

34 lines
1,013 B
TypeScript

/**
* Helpdesk staff resolution. "Staff" = users with the `admin` or `developer`
* role — the people who can manage tickets. Used to fan out notifications when
* a new ticket is created.
*/
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
export async function getStaffUserIds(payload: PayloadType): Promise<number[]> {
try {
const adminRole = await payload.find({
collection: "roles",
where: { slug: { in: ["admin", "developer"] } },
limit: 2,
depth: 0,
overrideAccess: true,
});
const roleIds = adminRole.docs.map((d) => d.id);
if (roleIds.length === 0) return [];
const res = await payload.find({
collection: "users",
where: { roleDocs: { in: roleIds } },
limit: 50,
depth: 0,
select: { username: true },
overrideAccess: true,
});
return res.docs.map((d) => d.id);
} catch (err) {
console.error("[Tickets] Failed to resolve staff recipients:", err);
return [];
}
}