feat: add search functionality to getAllHostApplications

This commit is contained in:
paritosh18
2025-11-17 19:05:39 +05:30
parent a54f61e8c8
commit c402c76096
2 changed files with 29 additions and 2 deletions

View File

@@ -376,7 +376,7 @@ export class MinglarService {
})
}
async getAllHostApplications(userId: number, userRoleXid: number) {
async getAllHostApplications(userId: number, userRoleXid: number, search?: string) {
// Build where clause based on user role
const whereClause: any = {
isActive: true,
@@ -387,6 +387,29 @@ export class MinglarService {
}
};
// Add search filter if search query is provided
if (search && search.trim() !== '') {
const searchTerm = search.trim();
// Check if search term is a number (for ID search)
const isNumeric = /^\d+$/.test(searchTerm);
if (isNumeric) {
// Search by host ID
whereClause.id = parseInt(searchTerm);
} else {
// Search by email or name
whereClause.user = {
...whereClause.user,
OR: [
{ emailAddress: { contains: searchTerm, mode: 'insensitive' } },
{ firstName: { contains: searchTerm, mode: 'insensitive' } },
{ lastName: { contains: searchTerm, mode: 'insensitive' } }
]
};
}
}
// If user is Co_Admin or Account_Manager, filter by assigned hosts only
if (userRoleXid === ROLE.CO_ADMIN || userRoleXid === ROLE.ACCOUNT_MANAGER) {
whereClause.accountManagerXid = userId;
@@ -433,6 +456,7 @@ export class MinglarService {
accountManager: host.accountManager || null
}));
}
async getAllCoadminAndAM() {
return await this.prisma.user.findMany({
where: {