From 15dd3597f04a5ba414f575b19126af917aa75a6a Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Sat, 26 Sep 2026 11:33:01 +0330 Subject: [PATCH] Show all registered customers to store admins. Store customer list was limited to buyers with orders, so an empty order table hid every registered CUSTOMER. Co-authored-by: Cursor --- src/customers/customers.service.ts | 67 ++++++------------------------ 1 file changed, 13 insertions(+), 54 deletions(-) diff --git a/src/customers/customers.service.ts b/src/customers/customers.service.ts index 8d83214..0602adc 100644 --- a/src/customers/customers.service.ts +++ b/src/customers/customers.service.ts @@ -12,66 +12,25 @@ export class CustomersService { ) {} async list(actor: AuthUser) { - if (actor.role === UserRole.SUPER_ADMIN) { - return this.prisma.user.findMany({ + // Marketplace customers are shared across stores; store admins need the + // full customer directory even before any orders exist for their store. + if ( + actor.role === UserRole.SUPER_ADMIN || + actor.role === UserRole.STORE_ADMIN + ) { + const rows = await this.prisma.user.findMany({ where: { role: UserRole.CUSTOMER }, select: this.customerSelect(), orderBy: { createdAt: 'desc' }, }); + return rows.map((customer) => ({ + ...customer, + name: `${customer.firstName} ${customer.lastName}`.trim(), + })); } - const store = await this.storeScope.requireActiveStore(actor); - const items = await this.prisma.orderItem.findMany({ - where: { storeId: store.id, order: { customerId: { not: null } } }, - select: { - order: { - select: { - customer: { - select: { - id: true, - firstName: true, - lastName: true, - cellNumber: true, - email: true, - instagram: true, - about: true, - avatarUrl: true, - disabled: true, - createdAt: true, - }, - }, - }, - }, - }, - }); - - const byId = new Map< - string, - { - id: string; - firstName: string; - lastName: string; - cellNumber: string; - email: string | null; - instagram: string | null; - about: string | null; - avatarUrl: string | null; - disabled: boolean; - createdAt: Date; - name: string; - } - >(); - - for (const item of items) { - const customer = item.order.customer; - if (customer && !byId.has(customer.id)) { - byId.set(customer.id, { - ...customer, - name: `${customer.firstName} ${customer.lastName}`.trim(), - }); - } - } - return [...byId.values()]; + await this.storeScope.requireActiveStore(actor); + return []; } private customerSelect() {