Files
NextChair/src/services/notifications/recipients.ts
T
2026-08-03 21:15:24 +01:00

21 lines
787 B
TypeScript

import type { PrismaClient } from "@/generated/prisma/client";
import { Permission } from "@/generated/prisma/enums";
/**
* There's no `Business.ownerUserId` column — "owner" is whoever holds a
* role with VIEW_REPORTING (the permission that gates the owner
* dashboard, see schema.prisma), which can be more than one active staff
* member. Every OWNER_* notification goes to all of them, not just one.
*/
export async function getOwnerUserIds(prisma: PrismaClient, businessId: string): Promise<string[]> {
const staff = await prisma.staffProfile.findMany({
where: {
businessId,
status: "ACTIVE",
role: { permissions: { some: { permission: Permission.VIEW_REPORTING } } },
},
select: { userId: true },
});
return staff.map((s) => s.userId);
}