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 <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-26 11:33:01 +03:30
co-authored by Cursor
parent 3e1b95e7bb
commit 15dd3597f0
+13 -54
View File
@@ -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() {