1 file changed
+12
-6
@@ -51,12 +51,18 @@ export default async function StaffCustomerDetailsPage({
|
||||
});
|
||||
if (!customer) notFound();
|
||||
|
||||
// "Belongs to this business" is via the appointment relation — see
|
||||
// docs/phase-5-summary.md, same reasoning as the clients list query.
|
||||
const belongsToBusiness = await prisma.appointment.findFirst({
|
||||
where: { customerId: id, businessId: context.businessId },
|
||||
select: { id: true },
|
||||
});
|
||||
// "Belongs to this business" mirrors the Clients list query exactly
|
||||
// (see (staff)/staff/clients/page.tsx) — either a real appointment here,
|
||||
// or a registered client with no appointment anywhere yet (added via
|
||||
// /staff/clients/add, or self-registered but never booked). Without the
|
||||
// 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();
|
||||
|
||||
const [upcoming, past, cancelled, notesRaw, loyalty] = await Promise.all([
|
||||
|
||||
Reference in new issue
Block a user