From 666f0074bb021fcfa297b9c73a6fd75ee60e140e Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Fri, 27 Mar 2026 12:00:04 +0530 Subject: [PATCH] feat: add search and verification status filters to the user listing endpoint --- src/users/users.controller.ts | 4 +++- src/users/users.service.ts | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 2c0f896..c3c4287 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -242,11 +242,13 @@ export class UsersController { @Query('page') page?: string, @Query('limit') limit?: string, @Query('role') role?: UserRole, + @Query('search') search?: string, + @Query('verificationStatus') verificationStatus?: string, ) { const pageNum = page ? parseInt(page, 10) : 1; const limitNum = limit ? parseInt(limit, 10) : 10; - return this.usersService.findAll(pageNum, limitNum, role); + return this.usersService.findAll(pageNum, limitNum, role, search, verificationStatus); } @Get(':id/verification-documents') diff --git a/src/users/users.service.ts b/src/users/users.service.ts index b065d42..af0d8f7 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -114,11 +114,24 @@ export class UsersService { // ADMIN METHODS // ============================================= - async findAll(page = 1, limit = 10, role?: UserRole) { + async findAll(page = 1, limit = 10, role?: UserRole, search?: string, verificationStatus?: string) { const skip = (page - 1) * limit; - // Build where clause for optional role filter - const where: Prisma.UserWhereInput = role ? { role } : {}; + // Build where clause + const where: Prisma.UserWhereInput = {}; + if (role) where.role = role; + if (search) { + where.OR = [ + { email: { contains: search, mode: 'insensitive' } }, + { userProfile: { firstName: { contains: search, mode: 'insensitive' } } }, + { userProfile: { lastName: { contains: search, mode: 'insensitive' } } }, + { agentProfile: { firstName: { contains: search, mode: 'insensitive' } } }, + { agentProfile: { lastName: { contains: search, mode: 'insensitive' } } }, + ]; + } + if (verificationStatus) { + where.agentProfile = { ...((where.agentProfile as object) || {}), verificationStatus: verificationStatus as any }; + } const [users, total] = await Promise.all([ this.prisma.user.findMany({