bugfix: clinic owner user access to other (dentist)staff's treatment plans terminated.

This commit is contained in:
2026-07-14 03:39:42 +03:30
parent 8de15ecdb5
commit a7ba33fb68
7 changed files with 106 additions and 60 deletions

View File

@@ -0,0 +1,26 @@
import type { Prisma } from '@prisma/client';
/** Treatments the clinician owns — by plan provider or linked appointment provider. */
export function treatmentProviderScopeWhere(
actorUserId: string,
): Pick<Prisma.TreatmentWhereInput, 'OR'> {
return {
OR: [
{ providerUserId: actorUserId },
{ appointment: { is: { providerUserId: actorUserId } } },
],
};
}
type TreatmentProviderRow = {
providerUserId: string | null;
appointment?: { providerUserId: string } | null;
};
export function isActorTreatmentProvider(
treatment: TreatmentProviderRow,
actorUserId: string,
): boolean {
if (treatment.providerUserId === actorUserId) return true;
return treatment.appointment?.providerUserId === actorUserId;
}