diff --git a/CHANGELOG.md b/CHANGELOG.md index c87a00cd1..3bad82b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added pagination parameters (`skip`, `take`) to the endpoint `GET api/v1/admin/user` +- Added pagination response (`count`) to the endpoint `GET api/v1/admin/user` ### Changed diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index a0531c483..4abd47565 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -140,7 +140,7 @@ export class AdminService { const [settings, transactionCount, userCount] = await Promise.all([ this.propertyService.get(), this.prismaService.order.count(), - this.prismaService.user.count() + this.countUsersWithAnalytics() ]); return { @@ -436,7 +436,12 @@ export class AdminService { skip?: number; take?: number; }): Promise { - return { users: await this.getUsersWithAnalytics({ skip, take }) }; + const [count, users] = await Promise.all([ + this.countUsersWithAnalytics(), + this.getUsersWithAnalytics({ skip, take }) + ]); + + return { count, users }; } public async patchAssetProfileData({ @@ -514,6 +519,22 @@ export class AdminService { return response; } + private async countUsersWithAnalytics() { + let where: Prisma.UserWhereInput; + + if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { + where = { + NOT: { + Analytics: null + } + }; + } + + return this.prismaService.user.count({ + where + }); + } + private getExtendedPrismaClient() { Logger.debug('Connect extended prisma client', 'AdminService'); diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts index 367c1b432..20cfa8ef8 100644 --- a/apps/client/src/app/services/admin.service.ts +++ b/apps/client/src/app/services/admin.service.ts @@ -159,7 +159,7 @@ export class AdminService { public fetchUsers() { let params = new HttpParams(); - params = params.append('take', 100); + params = params.append('take', 30); return this.http.get('/api/v1/admin/user', { params }); } diff --git a/libs/common/src/lib/interfaces/admin-users.interface.ts b/libs/common/src/lib/interfaces/admin-users.interface.ts index 24eb45c85..8fde15e18 100644 --- a/libs/common/src/lib/interfaces/admin-users.interface.ts +++ b/libs/common/src/lib/interfaces/admin-users.interface.ts @@ -1,6 +1,7 @@ import { Role } from '@prisma/client'; export interface AdminUsers { + count: number; users: { accountCount: number; country: string;