add support for endDate
This commit is contained in:
@ -9,6 +9,8 @@ import bg from 'date-fns/locale/bg';
|
|||||||
import { bgBG } from '../x-date-pickers/locales/bgBG';
|
import { bgBG } from '../x-date-pickers/locales/bgBG';
|
||||||
import { ToastContainer } from 'react-toastify';
|
import { ToastContainer } from 'react-toastify';
|
||||||
const common = require('src/helpers/common');
|
const common = require('src/helpers/common');
|
||||||
|
//todo import Availability type from prisma schema
|
||||||
|
|
||||||
|
|
||||||
const fetchConfig = async () => {
|
const fetchConfig = async () => {
|
||||||
const config = await import('../../config.json');
|
const config = await import('../../config.json');
|
||||||
@ -114,7 +116,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
|||||||
const id = availability.id;
|
const id = availability.id;
|
||||||
const updatedAvailability = updateAvailabilityFromGroup(availability, group);
|
const updatedAvailability = updateAvailabilityFromGroup(availability, group);
|
||||||
delete updatedAvailability.id;
|
delete updatedAvailability.id;
|
||||||
delete updatedAvailability.type;
|
//delete updatedAvailability.type;
|
||||||
delete updatedAvailability.publisherId;
|
delete updatedAvailability.publisherId;
|
||||||
delete updatedAvailability.title;
|
delete updatedAvailability.title;
|
||||||
delete updatedAvailability.date;
|
delete updatedAvailability.date;
|
||||||
@ -244,9 +246,11 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
|||||||
// Adjustments for repeating settings
|
// Adjustments for repeating settings
|
||||||
if (doRepeat) {
|
if (doRepeat) {
|
||||||
availability.repeatWeekly = true;
|
availability.repeatWeekly = true;
|
||||||
|
availability.type = "Weekly"
|
||||||
availability.dayOfMonth = null;
|
availability.dayOfMonth = null;
|
||||||
availability.endDate = repeatUntil;
|
availability.endDate = repeatUntil;
|
||||||
} else {
|
} else {
|
||||||
|
availability.type = "OneTime"
|
||||||
availability.repeatWeekly = false;
|
availability.repeatWeekly = false;
|
||||||
availability.dayOfMonth = startTime.getDate();
|
availability.dayOfMonth = startTime.getDate();
|
||||||
availability.endDate = null;
|
availability.endDate = null;
|
||||||
|
@ -580,6 +580,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
//substract the time difference between from ISO string and local time
|
//substract the time difference between from ISO string and local time
|
||||||
const offset = filterDate.getTimezoneOffset() * 60000; // offset in milliseconds
|
const offset = filterDate.getTimezoneOffset() * 60000; // offset in milliseconds
|
||||||
var dateAsISO = new Date(filterDate.getTime() + offset);
|
var dateAsISO = new Date(filterDate.getTime() + offset);
|
||||||
|
//if full day, match by date only
|
||||||
if (filterDate.getHours() == 0 || dateAsISO.getHours() == 0) {
|
if (filterDate.getHours() == 0 || dateAsISO.getHours() == 0) {
|
||||||
whereClause["availabilities"] = {
|
whereClause["availabilities"] = {
|
||||||
some: {
|
some: {
|
||||||
@ -594,14 +595,23 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
// This includes availabilities from previous assignments but not with preference
|
// This includes availabilities from previous assignments but not with preference
|
||||||
{
|
{
|
||||||
dayOfMonth: null, // includes monthly and weekly repeats
|
dayOfMonth: null, // includes monthly and weekly repeats
|
||||||
dayofweek: dayOfWeekEnum
|
dayofweek: dayOfWeekEnum,
|
||||||
// ToDo: and weekOfMonth
|
// 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 {
|
else {
|
||||||
//match exact time (should be same as data.findPublisherAvailability())
|
//match exact time (should be same as data.findPublisherAvailability())
|
||||||
whereClause["availabilities"] = {
|
whereClause["availabilities"] = {
|
||||||
@ -617,12 +627,14 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
{
|
{
|
||||||
dayOfMonth: null,
|
dayOfMonth: null,
|
||||||
dayofweek: dayOfWeekEnum,
|
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 (fetchAvailabilities) {
|
||||||
// If no filter date, return all publishers's availabilities for currentMonthStart
|
// If no filter date, return all publishers's availabilities for currentMonthStart
|
||||||
whereClause["availabilities"] = {
|
whereClause["availabilities"] = {
|
||||||
|
Reference in New Issue
Block a user