add support for endDate

This commit is contained in:
Dobromir Popov
2024-04-05 15:07:27 +03:00
parent 95ac760447
commit 3c9dcfece6
2 changed files with 20 additions and 4 deletions

View File

@ -9,6 +9,8 @@ import bg from 'date-fns/locale/bg';
import { bgBG } from '../x-date-pickers/locales/bgBG';
import { ToastContainer } from 'react-toastify';
const common = require('src/helpers/common');
//todo import Availability type from prisma schema
const fetchConfig = async () => {
const config = await import('../../config.json');
@ -114,7 +116,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
const id = availability.id;
const updatedAvailability = updateAvailabilityFromGroup(availability, group);
delete updatedAvailability.id;
delete updatedAvailability.type;
//delete updatedAvailability.type;
delete updatedAvailability.publisherId;
delete updatedAvailability.title;
delete updatedAvailability.date;
@ -244,9 +246,11 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
// Adjustments for repeating settings
if (doRepeat) {
availability.repeatWeekly = true;
availability.type = "Weekly"
availability.dayOfMonth = null;
availability.endDate = repeatUntil;
} else {
availability.type = "OneTime"
availability.repeatWeekly = false;
availability.dayOfMonth = startTime.getDate();
availability.endDate = null;

View File

@ -580,6 +580,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
//substract the time difference between from ISO string and local time
const offset = filterDate.getTimezoneOffset() * 60000; // offset in milliseconds
var dateAsISO = new Date(filterDate.getTime() + offset);
//if full day, match by date only
if (filterDate.getHours() == 0 || dateAsISO.getHours() == 0) {
whereClause["availabilities"] = {
some: {
@ -594,14 +595,23 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
// This includes availabilities from previous assignments but not with preference
{
dayOfMonth: null, // includes monthly and weekly repeats
dayofweek: dayOfWeekEnum
dayofweek: dayOfWeekEnum,
// ToDo: and weekOfMonth
//startTime: { gte: currentMonthStart },
startTime: { lte: filterDate },
AND: [
{
OR: [ // OR condition for repeatUntil to handle events that either end after filterDate or repeat forever
{ endDate: { gte: filterDate } },
{ endDate: null }
]
}
]
}
]
}
};
}
//if not full day, match by date and time
else {
//match exact time (should be same as data.findPublisherAvailability())
whereClause["availabilities"] = {
@ -617,12 +627,14 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
{
dayOfMonth: null,
dayofweek: dayOfWeekEnum,
startTime: { gte: filterDate },
}
]
}
};
}
} else { // we use month filter if date is passed and useDateFilter is false
} else {
// we use month filter if date is passed and useDateFilter is false to get all publishers with availabilities for the current month
if (fetchAvailabilities) {
// If no filter date, return all publishers's availabilities for currentMonthStart
whereClause["availabilities"] = {