Feature/add pagination support to user endpoint (#4050)

* Add pagination support to user endpoint

* Update changelog
This commit is contained in:
QURBAN AHMAD 2024-11-17 14:35:59 +05:30 committed by GitHub
parent 4b0e75b26c
commit e7356dc170
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 8 deletions

View File

@ -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/), 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). 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 ## 2.123.0 - 2024-11-16
### Added ### Added

View File

@ -352,7 +352,13 @@ export class AdminController {
@Get('user') @Get('user')
@HasPermission(permissions.accessAdminControl) @HasPermission(permissions.accessAdminControl)
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async getUsers(): Promise<AdminUsers> { public async getUsers(
return this.adminService.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
});
} }
} }

View File

@ -429,8 +429,14 @@ export class AdminService {
}; };
} }
public async getUsers(): Promise<AdminUsers> { public async getUsers({
return { users: await this.getUsersWithAnalytics() }; skip,
take = Number.MAX_SAFE_INTEGER
}: {
skip?: number;
take?: number;
}): Promise<AdminUsers> {
return { users: await this.getUsersWithAnalytics({ skip, take }) };
} }
public async patchAssetProfileData({ public async patchAssetProfileData({
@ -640,7 +646,13 @@ export class AdminService {
return { marketData, count: marketData.length }; 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 = { let orderBy: Prisma.UserOrderByWithRelationInput = {
createdAt: 'desc' createdAt: 'desc'
}; };
@ -661,6 +673,8 @@ export class AdminService {
const usersWithAnalytics = await this.prismaService.user.findMany({ const usersWithAnalytics = await this.prismaService.user.findMany({
orderBy, orderBy,
skip,
take,
where, where,
select: { select: {
_count: { _count: {
@ -677,8 +691,7 @@ export class AdminService {
id: true, id: true,
role: true, role: true,
Subscription: true Subscription: true
}, }
take: 30
}); });
return usersWithAnalytics.map( return usersWithAnalytics.map(

View File

@ -157,7 +157,11 @@ export class AdminService {
} }
public fetchUsers() { 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() { public gather7Days() {