data.js working correctly with weekly availabilities
This commit is contained in:
@ -377,7 +377,10 @@ exports.getDateFormattedShort = function (date) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
exports.getDateTimeFormatted = function (date) {
|
||||
// const startTime = start.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', timeZone: 'Europe/Sofia' });
|
||||
return exports.getISODateOnly(new Date(date)) + " " + exports.getTimeFormatted(date);
|
||||
}
|
||||
|
||||
/*Todo: remove:
|
||||
toISOString
|
||||
|
@ -253,6 +253,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
}
|
||||
}
|
||||
}
|
||||
const dayOfWeekEnum = common.getDayOfWeekNameEnEnumForDate(filterTimeFrom);
|
||||
|
||||
const monthInfo = common.getMonthDatesInfo(filterDate);
|
||||
let prevMnt = new Date(filterDate)
|
||||
@ -303,6 +304,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
|
||||
|
||||
if (filterTimeFrom) { // if no date is provided, we don't filter by date
|
||||
|
||||
selectBase.assignments.where = {
|
||||
shift: {
|
||||
startTime: { gte: prevMnt },
|
||||
@ -325,6 +327,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
// startTime: { gte: filterTimeFrom },
|
||||
AND: [
|
||||
{ dayOfMonth: null },
|
||||
{ dayofweek: dayOfWeekEnum },
|
||||
// moved down to conditional filters
|
||||
{ startTime: { lte: filterTimeTo } }, // startTime included
|
||||
{
|
||||
@ -356,7 +359,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
// no dayofweek or time filters here
|
||||
}
|
||||
else {
|
||||
let dayOfWeekEnum = common.getDayOfWeekNameEnEnumForDate(filterDate);
|
||||
//moved to upper qery as it is now also dependant on date filter
|
||||
whereClause["availabilities"].some.OR[1].dayofweek = dayOfWeekEnum;
|
||||
//NOTE: we filter by date after we calculate the correct dates post query
|
||||
if (isExactTime) {
|
||||
@ -377,7 +380,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
where: whereClause,
|
||||
select: {
|
||||
...selectBase,
|
||||
availabilities: true
|
||||
availabilities: true // we select all availabilities here and should filter them later
|
||||
}
|
||||
});
|
||||
|
||||
@ -385,10 +388,15 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
|
||||
// include repeating weekly availabilities. generate occurrences for the month
|
||||
// convert matching weekly availabilities to availabilities for the day to make further processing easier on the client.
|
||||
// we trust that the filtering was OK, so we use the dateFilter as date.
|
||||
publishers.forEach(pub => {
|
||||
pub.availabilities = pub.availabilities.map(avail => {
|
||||
if (avail.dayOfMonth == null) {
|
||||
// filter out repeating availabilities when on other day of week
|
||||
if (filterTimeFrom) {
|
||||
if (avail.dayofweek != dayOfWeekEnum) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
let newStart = new Date(filterDate);
|
||||
newStart.setHours(avail.startTime.getHours(), avail.startTime.getMinutes(), 0, 0);
|
||||
let newEnd = new Date(filterDate);
|
||||
@ -400,7 +408,8 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
}
|
||||
}
|
||||
return avail;
|
||||
});
|
||||
})
|
||||
.filter(avail => avail !== null);
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user