mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
implement fake pagination for searchUsers
This commit is contained in:
parent
8c031a562a
commit
2b6dd2af87
16
backend/src/graphql/arg/SearchUsersArgs.ts
Normal file
16
backend/src/graphql/arg/SearchUsersArgs.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ArgsType, Field, Int } from 'type-graphql'
|
||||
|
||||
@ArgsType()
|
||||
export default class SearchUsersArgs {
|
||||
@Field(() => String)
|
||||
searchText: string
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
currentPage?: number
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
pageSize?: number
|
||||
|
||||
@Field(() => Boolean, { nullable: true })
|
||||
notActivated?: boolean
|
||||
}
|
||||
@ -14,6 +14,7 @@ import { LoginPendingTasksAdminRepository } from '../../typeorm/repository/Login
|
||||
import { UserRepository } from '../../typeorm/repository/User'
|
||||
import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs'
|
||||
import UpdatePendingCreationArgs from '../arg/UpdatePendingCreationArgs'
|
||||
import SearchUsersArgs from '../arg/SearchUsersArgs'
|
||||
import moment from 'moment'
|
||||
import { Transaction } from '@entity/Transaction'
|
||||
import { TransactionCreation } from '@entity/TransactionCreation'
|
||||
@ -27,10 +28,12 @@ import { LoginUserRepository } from '../../typeorm/repository/LoginUser'
|
||||
export class AdminResolver {
|
||||
@Authorized([RIGHTS.SEARCH_USERS])
|
||||
@Query(() => [UserAdmin])
|
||||
async searchUsers(@Arg('searchText') searchText: string): Promise<UserAdmin[]> {
|
||||
async searchUsers(
|
||||
@Args() { searchText, currentPage = 1, pageSize = 25, notActivated = false }: SearchUsersArgs,
|
||||
): Promise<UserAdmin[]> {
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const users = await userRepository.findBySearchCriteria(searchText)
|
||||
const adminUsers = await Promise.all(
|
||||
let adminUsers = await Promise.all(
|
||||
users.map(async (user) => {
|
||||
const adminUser = new UserAdmin()
|
||||
adminUser.userId = user.id
|
||||
@ -42,7 +45,8 @@ export class AdminResolver {
|
||||
return adminUser
|
||||
}),
|
||||
)
|
||||
return adminUsers
|
||||
if (notActivated) adminUsers = adminUsers.filter((u) => !u.emailChecked)
|
||||
return adminUsers.slice(currentPage - 1, currentPage + pageSize - 1)
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.CREATE_PENDING_CREATION])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user