Editing permissions in the CRM Super Admin

This commit is contained in:
2026-09-21 16:38:24 +03:30
parent ebf13cfde5
commit f5a4eb577b
6 changed files with 292 additions and 98 deletions
+34 -20
View File
@@ -139,6 +139,7 @@ export class PlatformService {
email: true,
mobile: true,
isActive: true,
billingAccount: true,
},
},
},
@@ -149,16 +150,24 @@ export class PlatformService {
if (!row) throw new NotFoundException('محیط پیدا نشد');
return {
...this.orgToDto(row),
members: row.memberships.map((m) => ({
membershipId: m.id,
userId: m.user.id,
fullName: m.user.fullName,
email: m.user.email,
mobile: m.user.mobile,
role: m.role,
isActive: m.isActive,
userIsActive: m.user.isActive,
})),
members: row.memberships.map((m) => {
const isBillingOwner = m.role === 'owner';
return {
membershipId: m.id,
userId: m.user.id,
fullName: m.user.fullName,
email: m.user.email,
mobile: m.user.mobile,
role: m.role,
isActive: m.isActive,
userIsActive: m.user.isActive,
isBillingOwner,
billing:
isBillingOwner && m.user.billingAccount
? this.billing.toDto(m.user.billingAccount)
: null,
};
}),
};
}
@@ -330,18 +339,23 @@ export class PlatformService {
return this.updateOrganization(id, { isActive });
}
async listUsers(query?: string): Promise<PlatformUserDto[]> {
async listUsers(query?: string, ownersOnly = false): Promise<PlatformUserDto[]> {
const q = query?.trim();
const rows = await this.prisma.user.findMany({
where: q
? {
OR: [
{ fullName: { contains: q, mode: 'insensitive' } },
{ email: { contains: q, mode: 'insensitive' } },
{ mobile: { contains: q } },
],
}
: undefined,
where: {
...(q
? {
OR: [
{ fullName: { contains: q, mode: 'insensitive' } },
{ email: { contains: q, mode: 'insensitive' } },
{ mobile: { contains: q } },
],
}
: {}),
...(ownersOnly
? { memberships: { some: { role: 'owner', isActive: true } } }
: {}),
},
orderBy: { createdAt: 'desc' },
take: 300,
include: {