data.filterPublishers can filter by ID,
api/getPublisherInfo uses dataHelper.filterPubs instead of api.filterPublishers because it handles repeating avs and calcs statistics: shiftgenerate has fn to rank pubs based on weights. stop message every page load; other fixes
This commit is contained in:
@ -221,11 +221,12 @@ async function getAvailabilities(userId) {
|
||||
*
|
||||
* @returns {Promise<Array>} Returns a promise that resolves to an array of publishers with filtered data according to the specified criteria.
|
||||
*/
|
||||
async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, noEndDateFilter = false, isWithStats = true, includeOldAvailabilities = false) {
|
||||
async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, noEndDateFilter = false, isWithStats = true, includeOldAvailabilities = false, id = null) {
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
filterDate = new Date(filterDate); // Convert to date object if not already
|
||||
|
||||
if (filterDate !== null) {
|
||||
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);
|
||||
@ -262,9 +263,20 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
|
||||
let filterTimeFrom = new Date(filterDate)
|
||||
let filterTimeTo = new Date(filterDate);
|
||||
//check if filterDate is valid date
|
||||
if (isNaN(filterDate.getTime())) {
|
||||
console.error("Invalid date: " + filterDate);
|
||||
filterTimeFrom = new Date(2024, 1, 1);
|
||||
noEndDateFilter = true;
|
||||
isForTheMonth = false
|
||||
}
|
||||
|
||||
let isDayFilter = true;
|
||||
let whereClause = {};
|
||||
if (id) {
|
||||
whereClause.id = String(id)
|
||||
|
||||
}
|
||||
if (isForTheMonth) {
|
||||
var weekNr = common.getWeekOfMonth(filterDate); //getWeekNumber
|
||||
|
||||
@ -282,59 +294,65 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
filterTimeTo.setHours(23, 59, 59, 999);
|
||||
}
|
||||
|
||||
whereClause["availabilities"] = {
|
||||
some: {
|
||||
OR: [
|
||||
// Check if dayOfMonth is not null and startTime is after monthInfo.firstMonday (Assignments on specific days AND time)
|
||||
{
|
||||
//dayOfMonth: { not: null },
|
||||
startTime: { gte: filterTimeFrom },
|
||||
// endTime: { lte: monthInfo.lastSunday }
|
||||
},
|
||||
// Check if dayOfMonth is null and match by day of week using the enum (Assigments every week)
|
||||
{
|
||||
// dayOfMonth: null,
|
||||
// startTime: { gte: filterTimeFrom },
|
||||
AND: [
|
||||
{ dayOfMonth: null },
|
||||
{ startTime: { lte: filterTimeTo } }, // startTime included
|
||||
{
|
||||
OR: [ // OR condition for repeatUntil to handle events that either end after filterDate or repeat forever
|
||||
{ endDate: { gte: filterTimeFrom } }, // endDate included
|
||||
{ endDate: null }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
if (filterDate) { // if no date is provided, we don't filter by date
|
||||
whereClause["availabilities"] = {
|
||||
some: {
|
||||
OR: [
|
||||
// ONE TIME AVAILABILITIES
|
||||
// Check if dayOfMonth is not null and startTime is after monthInfo.firstMonday (Assignments on specific days AND time)
|
||||
{
|
||||
//dayOfMonth: { not: null },
|
||||
startTime: { gte: filterTimeFrom },
|
||||
// endTime: { lte: monthInfo.lastSunday }
|
||||
},
|
||||
// REPEATING WEEKLY AVAILABILITIES
|
||||
// Check if dayOfMonth is null and match by day of week using the enum (Assigments every week)
|
||||
{
|
||||
// dayOfMonth: null,
|
||||
// startTime: { gte: filterTimeFrom },
|
||||
AND: [
|
||||
{ dayOfMonth: null },
|
||||
// moved down to conditional filters
|
||||
{ startTime: { lte: filterTimeTo } }, // startTime included
|
||||
{
|
||||
OR: [ // OR condition for repeatUntil to handle events that either end after filterDate or repeat forever
|
||||
{ endDate: { gte: filterTimeFrom } }, // endDate included
|
||||
{ endDate: null }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
/* FILTERS
|
||||
1. exact time
|
||||
2. exact date
|
||||
3. the month
|
||||
4. from start date only
|
||||
*/
|
||||
|
||||
if (noEndDateFilter) {
|
||||
isDayFilter = false;
|
||||
}
|
||||
else {
|
||||
whereClause["availabilities"].some.OR[0].endTime = { lte: filterTimeTo };
|
||||
if (isForTheMonth) {
|
||||
// no dayofweek or time filters here
|
||||
/* FILTERS
|
||||
1. exact time
|
||||
2. exact date
|
||||
3. the month
|
||||
4. from start date only
|
||||
*/
|
||||
|
||||
if (noEndDateFilter) {
|
||||
isDayFilter = false;
|
||||
}
|
||||
else {
|
||||
let dayOfWeekEnum = common.getDayOfWeekNameEnEnumForDate(filterDate);
|
||||
whereClause["availabilities"].some.OR[1].dayofweek = dayOfWeekEnum;
|
||||
//NOTE: we filter by date after we calculate the correct dates post query
|
||||
if (isExactTime) {
|
||||
//if exact time we need the availability to be starting on or before start of the shift and ending on or after the end of the shift
|
||||
whereClause["availabilities"].some.OR[0].startTime = { lte: filterTimeFrom };
|
||||
whereClause["availabilities"].some.OR[0].endTime = { gte: filterTimeTo };
|
||||
whereClause["availabilities"].some.OR[0].endTime = { lte: filterTimeTo };
|
||||
if (isForTheMonth) {
|
||||
// no dayofweek or time filters here
|
||||
}
|
||||
else {
|
||||
let dayOfWeekEnum = common.getDayOfWeekNameEnEnumForDate(filterDate);
|
||||
whereClause["availabilities"].some.OR[1].dayofweek = dayOfWeekEnum;
|
||||
//NOTE: we filter by date after we calculate the correct dates post query
|
||||
if (isExactTime) {
|
||||
//if exact time we need the availability to be starting on or before start of the shift and ending on or after the end of the shift
|
||||
whereClause["availabilities"].some.OR[0].startTime = { lte: filterTimeFrom };
|
||||
whereClause["availabilities"].some.OR[0].endTime = { gte: filterTimeTo };
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1179,6 +1197,7 @@ async function FindPublisherAvailability(publisherId, startDate, endDate, dayOfW
|
||||
// }
|
||||
|
||||
const fs = require('fs');
|
||||
const { filter } = require('jszip');
|
||||
const path = require('path');
|
||||
|
||||
async function runSqlFile(filePath) {
|
||||
|
Reference in New Issue
Block a user