Update page.tsx
CI / ci (push) Canceled after 0s

This commit is contained in:
Stefan Lazic committed 2026-09-18 21:07:37 +01:00
1 parent 410aa07596
commit 7338c9d9e2
1 file changed
+12 -6
+12 -6
View File
@@ -51,12 +51,18 @@ export default async function StaffCustomerDetailsPage({
}); });
if (!customer) notFound(); if (!customer) notFound();
// "Belongs to this business" is via the appointment relation — see // "Belongs to this business" mirrors the Clients list query exactly
// docs/phase-5-summary.md, same reasoning as the clients list query. // (see (staff)/staff/clients/page.tsx) — either a real appointment here,
const belongsToBusiness = await prisma.appointment.findFirst({ // or a registered client with no appointment anywhere yet (added via
where: { customerId: id, businessId: context.businessId }, // /staff/clients/add, or self-registered but never booked). Without the
select: { id: true }, // second branch, a client visible in the list because of that same
}); // broadening would 404 the moment staff actually clicked into them —
// confirmed live, this exact gap.
const [appointmentsHereCount, totalAppointmentCount] = await Promise.all([
prisma.appointment.count({ where: { customerId: id, businessId: context.businessId } }),
prisma.appointment.count({ where: { customerId: id } }),
]);
const belongsToBusiness = appointmentsHereCount > 0 || (!customer.isGuest && totalAppointmentCount === 0);
if (!belongsToBusiness) notFound(); if (!belongsToBusiness) notFound();
const [upcoming, past, cancelled, notesRaw, loyalty] = await Promise.all([ const [upcoming, past, cancelled, notesRaw, loyalty] = await Promise.all([