feat: add search and verification status filters to the user listing endpoint
This commit is contained in:
@@ -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')
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user