fix filters
This commit is contained in:
@ -233,6 +233,11 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
const prisma = common.getPrismaClient();
|
||||
filterDate = new Date(filterDate); // Convert to date object if not already
|
||||
|
||||
const monthInfo = common.getMonthDatesInfo(filterDate);
|
||||
let prevMnt = new Date(filterDate)
|
||||
prevMnt.setMonth(prevMnt.getMonth() - 1);
|
||||
const prevMonthInfo = common.getMonthDatesInfo(prevMnt);
|
||||
|
||||
// Only attempt to split if selectFields is a string; otherwise, use it as it is.
|
||||
selectFields = typeof selectFields === 'string' ? selectFields.split(",") : selectFields;
|
||||
|
||||
@ -241,6 +246,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
selectBase.assignments = {
|
||||
select: {
|
||||
id: true,
|
||||
@ -255,7 +261,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
where: {
|
||||
shift: {
|
||||
startTime: {
|
||||
gte: filterDate,
|
||||
gte: prevMnt,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -266,7 +272,6 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
let isDayFilter = true;
|
||||
let whereClause = {};
|
||||
|
||||
var monthInfo = common.getMonthDatesInfo(filterDate);
|
||||
if (isForTheMonth) {
|
||||
var weekNr = common.getWeekOfMonth(filterDate); //getWeekNumber
|
||||
|
||||
@ -371,20 +376,11 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
});
|
||||
|
||||
|
||||
let currentWeekStart, currentWeekEnd,
|
||||
currentMonthStart, currentMonthEnd,
|
||||
previousMonthStart, previousMonthEnd;
|
||||
let currentWeekStart, currentWeekEnd;
|
||||
|
||||
if (isWithStats) {
|
||||
currentWeekStart = common.getStartOfWeek(filterDate);
|
||||
currentWeekEnd = common.getEndOfWeek(filterDate);
|
||||
currentMonthStart = monthInfo.firstMonday;
|
||||
currentMonthEnd = monthInfo.lastSunday;
|
||||
let prevMnt = new Date(filterDate)
|
||||
prevMnt.setMonth(prevMnt.getMonth() - 1);
|
||||
monthInfo = common.getMonthDatesInfo(prevMnt);
|
||||
previousMonthStart = monthInfo.firstMonday;
|
||||
previousMonthEnd = monthInfo.lastSunday;
|
||||
|
||||
//get if publisher has assignments for current weekday, week, current month, previous month
|
||||
publishers.forEach(pub => {
|
||||
@ -401,12 +397,12 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
|
||||
// Filter assignments for current month
|
||||
pub.currentMonthAssignments = pub.assignments?.filter(assignment => {
|
||||
return assignment.shift.startTime >= currentMonthStart && (noEndDateFilter || assignment.shift.startTime <= currentMonthEnd);
|
||||
return assignment.shift.startTime >= monthInfo.firstMonday && (noEndDateFilter || assignment.shift.startTime <= monthInfo.lastSunday);
|
||||
}).length;
|
||||
|
||||
// Filter assignments for previous month
|
||||
pub.previousMonthAssignments = pub.assignments?.filter(assignment => {
|
||||
return assignment.shift.startTime >= previousMonthStart && assignment.shift.startTime <= previousMonthEnd;
|
||||
return assignment.shift.startTime >= prevMonthInfo.firstMonday && assignment.shift.startTime <= prevMonthInfo.lastSunday;
|
||||
}).length;
|
||||
});
|
||||
|
||||
@ -419,8 +415,8 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
publishers.forEach(pub => {
|
||||
if (isWithStats) {
|
||||
pub.currentMonthAvailability = pub.availabilities?.filter(avail => {
|
||||
// return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= currentMonthEnd;
|
||||
return avail.startTime >= currentMonthStart && (noEndDateFilter || avail.startTime <= currentMonthEnd);
|
||||
// return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= monthInfo.lastSunday;
|
||||
return avail.startTime >= monthInfo.firstMonday && (noEndDateFilter || avail.startTime <= monthInfo.lastSunday);
|
||||
})
|
||||
pub.currentMonthAvailabilityDaysCount = pub.currentMonthAvailability.length || 0;
|
||||
// pub.currentMonthAvailabilityDaysCount += pub.availabilities.filter(avail => {
|
||||
@ -431,7 +427,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
}, 0);
|
||||
//if pub has up-to-date availabilities (with dayOfMonth) for the current month
|
||||
pub.hasUpToDateAvailabilities = pub.availabilities?.some(avail => {
|
||||
return avail.dayOfMonth != null && avail.startTime >= currentMonthStart; // && avail.startTime <= currentMonthEnd;
|
||||
return avail.dayOfMonth != null && avail.startTime >= monthInfo.firstMonday; // && avail.startTime <= monthInfo.lastSunday;
|
||||
});
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user