/** * 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>; export async function getStaffUserIds(payload: PayloadType): Promise { 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 []; } }