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 { 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); }