feat: add search and verification status filters to the user listing endpoint

This commit is contained in:
pradeepkumar
2026-03-27 12:00:04 +05:30
parent 486b9f9421
commit 666f0074bb
2 changed files with 19 additions and 4 deletions

View File

@@ -242,11 +242,13 @@ export class UsersController {
@Query('page') page?: string, @Query('page') page?: string,
@Query('limit') limit?: string, @Query('limit') limit?: string,
@Query('role') role?: UserRole, @Query('role') role?: UserRole,
@Query('search') search?: string,
@Query('verificationStatus') verificationStatus?: string,
) { ) {
const pageNum = page ? parseInt(page, 10) : 1; const pageNum = page ? parseInt(page, 10) : 1;
const limitNum = limit ? parseInt(limit, 10) : 10; 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') @Get(':id/verification-documents')

View File

@@ -114,11 +114,24 @@ export class UsersService {
// ADMIN METHODS // 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; const skip = (page - 1) * limit;
// Build where clause for optional role filter // Build where clause
const where: Prisma.UserWhereInput = role ? { role } : {}; 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([ const [users, total] = await Promise.all([
this.prisma.user.findMany({ this.prisma.user.findMany({