Editing permissions in the CRM Super Admin
This commit is contained in:
@@ -85,8 +85,8 @@ export class PlatformController {
|
||||
}
|
||||
|
||||
@Get('users')
|
||||
listUsers(@Query('q') q?: string) {
|
||||
return this.platform.listUsers(q);
|
||||
listUsers(@Query('q') q?: string, @Query('owners') owners?: string) {
|
||||
return this.platform.listUsers(q, owners === '1' || owners === 'true');
|
||||
}
|
||||
|
||||
@Get('users/:id')
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user