From e7356dc1704ae93479a673f7a82e9fd3f626d7db Mon Sep 17 00:00:00 2001 From: QURBAN AHMAD <79472606+qur786@users.noreply.github.com> Date: Sun, 17 Nov 2024 14:35:59 +0530 Subject: [PATCH] Feature/add pagination support to user endpoint (#4050) * Add pagination support to user endpoint * Update changelog --- CHANGELOG.md | 6 +++++ apps/api/src/app/admin/admin.controller.ts | 10 ++++++-- apps/api/src/app/admin/admin.service.ts | 23 +++++++++++++++---- apps/client/src/app/services/admin.service.ts | 6 ++++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c31eb911..680964869 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added pagination parameters (`skip`, `take`) to the endpoint `GET api/v1/admin/user` + ## 2.123.0 - 2024-11-16 ### Added diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts index e0444d112..4cc4d467e 100644 --- a/apps/api/src/app/admin/admin.controller.ts +++ b/apps/api/src/app/admin/admin.controller.ts @@ -352,7 +352,13 @@ export class AdminController { @Get('user') @HasPermission(permissions.accessAdminControl) @UseGuards(AuthGuard('jwt'), HasPermissionGuard) - public async getUsers(): Promise { - return this.adminService.getUsers(); + public async getUsers( + @Query('skip') skip?: number, + @Query('take') take?: number + ): Promise { + return this.adminService.getUsers({ + skip: isNaN(skip) ? undefined : skip, + take: isNaN(take) ? undefined : take + }); } } diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 49964c77d..a0531c483 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -429,8 +429,14 @@ export class AdminService { }; } - public async getUsers(): Promise { - return { users: await this.getUsersWithAnalytics() }; + public async getUsers({ + skip, + take = Number.MAX_SAFE_INTEGER + }: { + skip?: number; + take?: number; + }): Promise { + return { users: await this.getUsersWithAnalytics({ skip, take }) }; } public async patchAssetProfileData({ @@ -640,7 +646,13 @@ export class AdminService { return { marketData, count: marketData.length }; } - private async getUsersWithAnalytics(): Promise { + private async getUsersWithAnalytics({ + skip, + take + }: { + skip?: number; + take?: number; + }): Promise { let orderBy: Prisma.UserOrderByWithRelationInput = { createdAt: 'desc' }; @@ -661,6 +673,8 @@ export class AdminService { const usersWithAnalytics = await this.prismaService.user.findMany({ orderBy, + skip, + take, where, select: { _count: { @@ -677,8 +691,7 @@ export class AdminService { id: true, role: true, Subscription: true - }, - take: 30 + } }); return usersWithAnalytics.map( diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts index 4c011e8c1..367c1b432 100644 --- a/apps/client/src/app/services/admin.service.ts +++ b/apps/client/src/app/services/admin.service.ts @@ -157,7 +157,11 @@ export class AdminService { } public fetchUsers() { - return this.http.get('/api/v1/admin/user'); + let params = new HttpParams(); + + params = params.append('take', 100); + + return this.http.get('/api/v1/admin/user', { params }); } public gather7Days() {