made get score api for pqq

This commit is contained in:
2025-11-24 23:19:18 +05:30
parent c4e470be05
commit 7056f32e24
9 changed files with 687 additions and 128 deletions

View File

@@ -485,82 +485,87 @@ export class MinglarService {
})
}
async getAllHostApplications(userId: number, userRoleXid: number, search?: string, userStatus?: string) {
// Build where clause based on user role
const whereClause: any = {
async getAllHostApplications(
userId: number,
userRoleXid: number,
search?: string,
userStatus?: string
) {
const filters: any = {
isActive: true,
user: {
roleXid: {
notIn: [ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER]
},
}
}
};
// Add search filter if search query is provided
if (search && search.trim() !== '') {
const searchTerm = search.trim();
/** -----------------------------------
* SEARCH FILTER (ID, EMAIL, NAME)
* ----------------------------------- */
if (search?.trim()) {
const term = 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);
if (/^\d+$/.test(term)) {
// Search by Host ID
filters.id = Number(term);
} else {
// Search by email or name
whereClause.user = {
...whereClause.user,
filters.user = {
...filters.user,
OR: [
{ emailAddress: { contains: searchTerm, mode: 'insensitive' } },
{ firstName: { contains: searchTerm, mode: 'insensitive' } },
{ lastName: { contains: searchTerm, mode: 'insensitive' } }
{ emailAddress: { contains: term, mode: "insensitive" } },
{ firstName: { contains: term, mode: "insensitive" } },
{ lastName: { contains: term, mode: "insensitive" } }
]
};
}
}
// Apply userStatus filter (case-insensitive) e.g. userStatus=new / NEW / New
if (userStatus && userStatus.trim().toLowerCase() === MINGLAR_STATUS_DISPLAY.NEW.toLowerCase()) {
whereClause.adminStatusDisplay = MINGLAR_STATUS_DISPLAY.NEW;
/** -----------------------------------
* USER STATUS FILTER (NEW)
* ----------------------------------- */
if (
userStatus &&
userStatus.trim().toLowerCase() === MINGLAR_STATUS_DISPLAY.NEW.toLowerCase()
) {
filters.adminStatusDisplay = MINGLAR_STATUS_DISPLAY.NEW;
}
/** -----------------------------------
* ROLE-BASED FILTER:
* CO_ADMIN & ACCOUNT_MANAGER only see assigned hosts
* ----------------------------------- */
if (userRoleXid === ROLE.CO_ADMIN || userRoleXid === ROLE.ACCOUNT_MANAGER) {
whereClause.accountManagerXid = userId;
filters.accountManagerXid = userId;
}
const hostHeaders = await this.prisma.hostHeader.findMany({
where: whereClause,
/** -----------------------------------
* MAIN QUERY
* ----------------------------------- */
const results = await this.prisma.hostHeader.findMany({
where: filters,
select: {
id: true,
hostStatusInternal: true,
hostStatusDisplay: true,
adminStatusDisplay: true,
adminStatusInternal: true,
createdAt: true,
companyName: true,
assignedOn: true,
cities: {
select: {
id: true,
cityName: true,
}
},
adminStatusDisplay: true,
countries: {
select: {
id: true,
countryName: true,
}
},
states: {
select: {
id: true,
stateName: true,
}
},
cities: { select: { id: true, cityName: true } },
states: { select: { id: true, stateName: true } },
countries: { select: { id: true, countryName: true } },
user: {
select: {
id: true,
firstName: true,
lastName: true,
emailAddress: true,
mobileNumber: true,
mobileNumber: true
}
},
accountManager: {
@@ -570,30 +575,34 @@ export class MinglarService {
lastName: true,
emailAddress: true,
mobileNumber: true,
roleXid: true,
roleXid: true
}
}
},
orderBy: {
createdAt: 'desc'
}
orderBy: { createdAt: "desc" }
});
// Transform the data to return host, hostStatusDisplay, submittedOn, and accountManager details
return hostHeaders.map(host => ({
hostId: host.id,
host: host.user,
hostStatusDisplay: host.hostStatusDisplay,
submittedOn: host.createdAt,
accountManager: host.accountManager || null,
companyName: host.companyName || null,
city: host.cities || null,
state: host.states || null,
country: host.countries || null,
assignedOn: host.assignedOn || null,
/** -----------------------------------
* TRANSFORM RESPONSE
* ----------------------------------- */
return results.map(h => ({
hostId: h.id,
host: h.user,
hostStatusDisplay: h.hostStatusDisplay,
hostStatusInternal: h.hostStatusInternal,
adminStatusDisplay: h.adminStatusDisplay,
adminStatusInternal: h.adminStatusInternal,
submittedOn: h.createdAt,
accountManager: h.accountManager || null,
companyName: h.companyName || null,
city: h.cities || null,
state: h.states || null,
country: h.countries || null,
assignedOn: h.assignedOn || null
}));
}
async getAllCoadminAndAM() {
// 1. Fetch all required users (Admin, Co-Admin, AM)
const users = await this.prisma.user.findMany({