Browse Source
Feature/add pagination support to user endpoint (#4050)
* Add pagination support to user endpoint
* Update changelog
pull/4054/head
QURBAN AHMAD
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
37 additions and
8 deletions
-
CHANGELOG.md
-
apps/api/src/app/admin/admin.controller.ts
-
apps/api/src/app/admin/admin.service.ts
-
apps/client/src/app/services/admin.service.ts
|
|
@ -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 |
|
|
|
|
|
@ -352,7 +352,13 @@ export class AdminController { |
|
|
|
@Get('user') |
|
|
|
@HasPermission(permissions.accessAdminControl) |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
public async getUsers(): Promise<AdminUsers> { |
|
|
|
return this.adminService.getUsers(); |
|
|
|
public async getUsers( |
|
|
|
@Query('skip') skip?: number, |
|
|
|
@Query('take') take?: number |
|
|
|
): Promise<AdminUsers> { |
|
|
|
return this.adminService.getUsers({ |
|
|
|
skip: isNaN(skip) ? undefined : skip, |
|
|
|
take: isNaN(take) ? undefined : take |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -429,8 +429,14 @@ export class AdminService { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public async getUsers(): Promise<AdminUsers> { |
|
|
|
return { users: await this.getUsersWithAnalytics() }; |
|
|
|
public async getUsers({ |
|
|
|
skip, |
|
|
|
take = Number.MAX_SAFE_INTEGER |
|
|
|
}: { |
|
|
|
skip?: number; |
|
|
|
take?: number; |
|
|
|
}): Promise<AdminUsers> { |
|
|
|
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<AdminUsers['users']> { |
|
|
|
private async getUsersWithAnalytics({ |
|
|
|
skip, |
|
|
|
take |
|
|
|
}: { |
|
|
|
skip?: number; |
|
|
|
take?: number; |
|
|
|
}): Promise<AdminUsers['users']> { |
|
|
|
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( |
|
|
|
|
|
@ -157,7 +157,11 @@ export class AdminService { |
|
|
|
} |
|
|
|
|
|
|
|
public fetchUsers() { |
|
|
|
return this.http.get<AdminUsers>('/api/v1/admin/user'); |
|
|
|
let params = new HttpParams(); |
|
|
|
|
|
|
|
params = params.append('take', 100); |
|
|
|
|
|
|
|
return this.http.get<AdminUsers>('/api/v1/admin/user', { params }); |
|
|
|
} |
|
|
|
|
|
|
|
public gather7Days() { |
|
|
|