fix repeating availability dayofmonh problem
This commit is contained in:
@ -90,9 +90,9 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
|||||||
let avs = availabilities.filter(av => av.type !== "assignment");
|
let avs = availabilities.filter(av => av.type !== "assignment");
|
||||||
// Determine if we need to delete and recreate, or just update
|
// Determine if we need to delete and recreate, or just update
|
||||||
let shouldRecreate = avs.length > 0 && avs.length !== groupedTimeSlots.length || avs.some(av => !av.id);
|
let shouldRecreate = avs.length > 0 && avs.length !== groupedTimeSlots.length || avs.some(av => !av.id);
|
||||||
shouldRecreate = shouldRecreate || ( avs.length == 0 && availabilities.length > 0);
|
shouldRecreate = shouldRecreate || (avs.length == 0 && availabilities.length > 0);
|
||||||
//create availability if we open a form with assignment without availability
|
//create availability if we open a form with assignment without availability
|
||||||
|
|
||||||
if (shouldRecreate) {
|
if (shouldRecreate) {
|
||||||
// Delete existing availabilities if they have an ID
|
// Delete existing availabilities if they have an ID
|
||||||
console.log("Recreating availabilities");
|
console.log("Recreating availabilities");
|
||||||
@ -173,52 +173,106 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
|||||||
return groupedIntervals;
|
return groupedIntervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const firstSlotWithTransport = timeSlots[0].checked && timeSlots[0]?.isWithTransport;
|
// // const firstSlotWithTransport = timeSlots[0].checked && timeSlots[0]?.isWithTransport;
|
||||||
// const lastSlotWithTransport = timeSlots[timeSlots.length - 1].checked && timeSlots[timeSlots.length - 1]?.isWithTransport;
|
// // const lastSlotWithTransport = timeSlots[timeSlots.length - 1].checked && timeSlots[timeSlots.length - 1]?.isWithTransport;
|
||||||
function createAvailabilityFromGroup(group) {
|
// function createAvailabilityFromGroup(group) {
|
||||||
let startTime = new Date(day);
|
// let startTime = new Date(day);
|
||||||
|
// startTime.setHours(group[0].startTime.getHours(), group[0].startTime.getMinutes(), group[0].startTime.getSeconds(), 0);
|
||||||
|
|
||||||
|
// let endTime = new Date(day);
|
||||||
|
// endTime.setHours(group[group.length - 1].endTime.getHours(), group[group.length - 1].endTime.getMinutes(), group[group.length - 1].endTime.getSeconds(), 0);
|
||||||
|
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// name: common.getTimeFomatted(startTime) + "-" + common.getTimeFomatted(endTime),
|
||||||
|
// publisherId: publisher.id,
|
||||||
|
// startTime: startTime,
|
||||||
|
// endTime: endTime,
|
||||||
|
// isWithTransportIn: group[0].isFirst && timeSlots[0].isWithTransport,
|
||||||
|
// isWithTransportOut: group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport,
|
||||||
|
// dayofweek: common.getDayOfWeekNameEnEnumForDate(day.getDay()),
|
||||||
|
// repeatWeekly: doRepeat,
|
||||||
|
// dayOfMonth: doRepeat ? null : startTime.getDate(),
|
||||||
|
// endDate: doRepeat ? repeatUntil : null,
|
||||||
|
// dateOfEntry: new Date(),
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function updateAvailabilityFromGroup(availability, group) {
|
||||||
|
// availability.startTime.setTime(group[0].startTime);
|
||||||
|
// availability.endTime.setTime(group[group.length - 1].endTime);
|
||||||
|
// availability.name = common.getTimeFomatted(availability.startTime) + "-" + common.getTimeFomatted(availability.endTime);
|
||||||
|
|
||||||
|
// availability.isWithTransportIn = group[0].isFirst && timeSlots[0].isWithTransport;
|
||||||
|
// availability.isWithTransportOut = group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport;
|
||||||
|
|
||||||
|
// delete availability.weekOfMonth;
|
||||||
|
// if (doRepeat) {
|
||||||
|
// availability.repeatWeekly = true;
|
||||||
|
// availability.dayOfMonth = null;
|
||||||
|
// availability.weekOfMonth = 0;
|
||||||
|
// availability.endDate = repeatUntil;
|
||||||
|
// } else {
|
||||||
|
// availability.repeatWeekly = false;
|
||||||
|
// availability.dayOfMonth = availability.startTime.getDate();
|
||||||
|
// availability.endDate = null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// availability.dateOfEntry = new Date();
|
||||||
|
// if (availability.parentAvailabilityId) {
|
||||||
|
// availability.parentAvailability = { connect: { id: parentAvailabilityId } };
|
||||||
|
// }
|
||||||
|
// delete availability.parentAvailabilityId;
|
||||||
|
|
||||||
|
// return availability;
|
||||||
|
// }
|
||||||
|
// Common function to set shared properties
|
||||||
|
function setSharedAvailabilityProperties(availability, group, timeSlots) {
|
||||||
|
let startTime = new Date(availability.startTime || day);
|
||||||
startTime.setHours(group[0].startTime.getHours(), group[0].startTime.getMinutes(), group[0].startTime.getSeconds(), 0);
|
startTime.setHours(group[0].startTime.getHours(), group[0].startTime.getMinutes(), group[0].startTime.getSeconds(), 0);
|
||||||
|
|
||||||
let endTime = new Date(day);
|
let endTime = new Date(availability.endTime || day);
|
||||||
endTime.setHours(group[group.length - 1].endTime.getHours(), group[group.length - 1].endTime.getMinutes(), group[group.length - 1].endTime.getSeconds(), 0);
|
endTime.setHours(group[group.length - 1].endTime.getHours(), group[group.length - 1].endTime.getMinutes(), group[group.length - 1].endTime.getSeconds(), 0);
|
||||||
|
|
||||||
|
availability.startTime = startTime;
|
||||||
return {
|
availability.endTime = endTime;
|
||||||
name: common.getTimeFomatted(startTime) + "-" + common.getTimeFomatted(endTime),
|
availability.name = common.getTimeFomatted(startTime) + "-" + common.getTimeFomatted(endTime);
|
||||||
publisherId: publisher.id,
|
|
||||||
startTime: startTime,
|
|
||||||
endTime: endTime,
|
|
||||||
isWithTransportIn: group[0].isFirst && timeSlots[0].isWithTransport,
|
|
||||||
isWithTransportOut: group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport,
|
|
||||||
dayofweek: common.getDayOfWeekNameEnEnum(day.getDay()),
|
|
||||||
repeatWeekly: doRepeat,
|
|
||||||
dayOfMonth: doRepeat ? null : startTime.getDate(),
|
|
||||||
endDate: doRepeat ? repeatUntil : null,
|
|
||||||
dateOfEntry: new Date(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAvailabilityFromGroup(availability, group) {
|
|
||||||
availability.startTime.setTime(group[0].startTime);
|
|
||||||
availability.endTime.setTime(group[group.length - 1].endTime);
|
|
||||||
availability.name = common.getTimeFomatted(availability.startTime) + "-" + common.getTimeFomatted(availability.endTime);
|
|
||||||
|
|
||||||
availability.isWithTransportIn = group[0].isFirst && timeSlots[0].isWithTransport;
|
availability.isWithTransportIn = group[0].isFirst && timeSlots[0].isWithTransport;
|
||||||
availability.isWithTransportOut = group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport;
|
availability.isWithTransportOut = group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport;
|
||||||
|
|
||||||
delete availability.weekOfMonth;
|
// Adjustments for repeating settings
|
||||||
if (doRepeat) {
|
if (doRepeat) {
|
||||||
availability.repeatWeekly = true;
|
availability.repeatWeekly = true;
|
||||||
availability.dayOfMonth = null;
|
availability.dayOfMonth = null;
|
||||||
availability.weekOfMonth = 0;
|
|
||||||
availability.endDate = repeatUntil;
|
availability.endDate = repeatUntil;
|
||||||
} else {
|
} else {
|
||||||
availability.repeatWeekly = false;
|
availability.repeatWeekly = false;
|
||||||
availability.dayOfMonth = availability.startTime.getDate();
|
availability.dayOfMonth = startTime.getDate();
|
||||||
availability.endDate = null;
|
availability.endDate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
availability.dateOfEntry = new Date();
|
availability.dateOfEntry = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAvailabilityFromGroup(group) {
|
||||||
|
let availability = {
|
||||||
|
publisherId: publisher.id,
|
||||||
|
dayofweek: common.getDayOfWeekNameEnEnumForDate(day),
|
||||||
|
};
|
||||||
|
|
||||||
|
setSharedAvailabilityProperties(availability, group, timeSlots);
|
||||||
|
|
||||||
|
return availability;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAvailabilityFromGroup(availability, group) {
|
||||||
|
setSharedAvailabilityProperties(availability, group, timeSlots);
|
||||||
|
|
||||||
|
delete availability.weekOfMonth;
|
||||||
|
if (doRepeat) {
|
||||||
|
availability.weekOfMonth = 0;
|
||||||
|
}
|
||||||
if (availability.parentAvailabilityId) {
|
if (availability.parentAvailabilityId) {
|
||||||
availability.parentAvailability = { connect: { id: parentAvailabilityId } };
|
availability.parentAvailability = { connect: { id: parentAvailabilityId } };
|
||||||
}
|
}
|
||||||
@ -227,6 +281,8 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
|||||||
return availability;
|
return availability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleDelete = async (e) => {
|
const handleDelete = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
|
@ -170,7 +170,7 @@ export default function AvailabilityForm({ publisherId, existingItem, inline, on
|
|||||||
availability.name = common.getTimeFomatted(availability.startTime) + "-" + common.getTimeFomatted(availability.endTime);
|
availability.name = common.getTimeFomatted(availability.startTime) + "-" + common.getTimeFomatted(availability.endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
availability.dayofweek = common.getDayOfWeekNameEnEnum(availability.startTime);
|
availability.dayofweek = common.getDayOfWeekNameEnEnumForDate(availability.startTime);
|
||||||
if (availability.repeatWeekly) {
|
if (availability.repeatWeekly) {
|
||||||
availability.dayOfMonth = null;
|
availability.dayOfMonth = null;
|
||||||
availability.weekOfMonth = 0; //weekly recurrance - no need for week of month. special value 0
|
availability.weekOfMonth = 0; //weekly recurrance - no need for week of month. special value 0
|
||||||
|
@ -264,7 +264,7 @@ export default async function handler(req, res) {
|
|||||||
let data = {
|
let data = {
|
||||||
publisherId: pub.id,
|
publisherId: pub.id,
|
||||||
dayOfMonth: null,
|
dayOfMonth: null,
|
||||||
dayofweek: avail.dayofweek || common.getDayOfWeekNameEnEnum(avail.startTime),
|
dayofweek: avail.dayofweek || common.getDayOfWeekNameEnEnumForDate(avail.startTime),
|
||||||
weekOfMonth: avail.weekofMonth || common.getWeekOfMonth(avail.startTime),
|
weekOfMonth: avail.weekofMonth || common.getWeekOfMonth(avail.startTime),
|
||||||
// null for auto generated availabilities
|
// null for auto generated availabilities
|
||||||
//dateOfEntry: new Date(), //avail.dateOfEntry || avail.startTime,
|
//dateOfEntry: new Date(), //avail.dateOfEntry || avail.startTime,
|
||||||
@ -535,7 +535,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
let dayOfWeekEnum: DayOfWeek
|
let dayOfWeekEnum: DayOfWeek
|
||||||
if (filterDate) {
|
if (filterDate) {
|
||||||
// Determine day of week using common function
|
// Determine day of week using common function
|
||||||
dayOfWeekEnum = common.getDayOfWeekNameEnEnum(filterDate);
|
dayOfWeekEnum = common.getDayOfWeekNameEnEnumForDate(filterDate);
|
||||||
if (filterDate.getHours() > 21 || filterDate.getHours() < 6) {
|
if (filterDate.getHours() > 21 || filterDate.getHours() < 6) {
|
||||||
filterDate.setHours(0, 0, 0, 0); // Set to midnight
|
filterDate.setHours(0, 0, 0, 0); // Set to midnight
|
||||||
}
|
}
|
||||||
@ -603,6 +603,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//match exact time (should be same as data.findPublisherAvailability())
|
||||||
whereClause["availabilities"] = {
|
whereClause["availabilities"] = {
|
||||||
some: {
|
some: {
|
||||||
OR: [
|
OR: [
|
||||||
|
@ -383,7 +383,7 @@ export default function ImportPage() {
|
|||||||
|
|
||||||
common.logger.debug("processing availabilities for " + day.toLocaleDateString()); // Output: Sun Apr 17 2022 14:07:11 GMT+0300 (Eastern European Summer Time)
|
common.logger.debug("processing availabilities for " + day.toLocaleDateString()); // Output: Sun Apr 17 2022 14:07:11 GMT+0300 (Eastern European Summer Time)
|
||||||
common.logger.debug("parsing availability input: " + shifts); // Output: 0 (Sunday)
|
common.logger.debug("parsing availability input: " + shifts); // Output: 0 (Sunday)
|
||||||
const dayOfWeekName = common.getDayOfWeekNameEnEnum(day);
|
const dayOfWeekName = common.getDayOfWeekNameEnEnumForDate(day);
|
||||||
|
|
||||||
let dayOfMonth = day.getDate();
|
let dayOfMonth = day.getDate();
|
||||||
const name = `${names[0]} ${names[1]}`;
|
const name = `${names[0]} ${names[1]}`;
|
||||||
|
28
prisma/administrative_scripts/fix_availability_dayofweek.sql
Normal file
28
prisma/administrative_scripts/fix_availability_dayofweek.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
-- find
|
||||||
|
SELECT *
|
||||||
|
FROM availability
|
||||||
|
WHERE dayofweek = "Thursday"
|
||||||
|
AND DAYOFWEEK(startTime) <> 5;
|
||||||
|
|
||||||
|
|
||||||
|
--fix
|
||||||
|
|
||||||
|
UPDATE availability
|
||||||
|
SET dayofweek = CASE DAYOFWEEK(startTime)
|
||||||
|
WHEN 1 THEN 'Sunday'
|
||||||
|
WHEN 2 THEN 'Monday'
|
||||||
|
WHEN 3 THEN 'Tuesday'
|
||||||
|
WHEN 4 THEN 'Wednesday'
|
||||||
|
WHEN 5 THEN 'Thursday'
|
||||||
|
WHEN 6 THEN 'Friday'
|
||||||
|
WHEN 7 THEN 'Saturday'
|
||||||
|
END
|
||||||
|
WHERE dayofweek != CASE DAYOFWEEK(startTime)
|
||||||
|
WHEN 1 THEN 'Sunday'
|
||||||
|
WHEN 2 THEN 'Monday'
|
||||||
|
WHEN 3 THEN 'Tuesday'
|
||||||
|
WHEN 4 THEN 'Wednesday'
|
||||||
|
WHEN 5 THEN 'Thursday'
|
||||||
|
WHEN 6 THEN 'Friday'
|
||||||
|
WHEN 7 THEN 'Saturday'
|
||||||
|
END;
|
@ -151,24 +151,27 @@ exports.getDayOfWeekName = function (date) {
|
|||||||
return exports.dayOfWeekNames[dayOfWeekIndex];
|
return exports.dayOfWeekNames[dayOfWeekIndex];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDayOfWeekNameEnEnum = function (date) {
|
exports.getDayOfWeekNameEnEnumForDate = function (date) {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
const dayOfWeekIndex = date.getDayEuropean();
|
const dayOfWeekIndex = date.getDayEuropean();
|
||||||
const dayOfWeekNames = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
return exports.DaysOfWeekArray[dayOfWeekIndex];
|
||||||
|
|
||||||
//return enum instead of string
|
|
||||||
// const dayOfWeekNames: Record<number, DayOfWeek> = {
|
|
||||||
// 0: DayOfWeek.Monday,
|
|
||||||
// 1: DayOfWeek.Tuesday,
|
|
||||||
// 2: DayOfWeek.Wednesday,
|
|
||||||
// 3: DayOfWeek.Thursday,
|
|
||||||
// 4: DayOfWeek.Friday,
|
|
||||||
// 5: DayOfWeek.Saturday,
|
|
||||||
// 6: DayOfWeek.Sunday
|
|
||||||
// };
|
|
||||||
|
|
||||||
return dayOfWeekNames[dayOfWeekIndex];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//obsolete: we want to ensure getDayEuropean() is used, hense we will not use this function
|
||||||
|
// exports.getDayOfWeekNameEnEnum = function (dayOfWeekIndex) {
|
||||||
|
// //return enum instead of string
|
||||||
|
// // const dayOfWeekNames: Record<number, DayOfWeek> = {
|
||||||
|
// // 0: DayOfWeek.Monday,
|
||||||
|
// // 1: DayOfWeek.Tuesday,
|
||||||
|
// // 2: DayOfWeek.Wednesday,
|
||||||
|
// // 3: DayOfWeek.Thursday,
|
||||||
|
// // 4: DayOfWeek.Friday,
|
||||||
|
// // 5: DayOfWeek.Saturday,
|
||||||
|
// // 6: DayOfWeek.Sunday
|
||||||
|
// // };
|
||||||
|
// return exports.DaysOfWeekArray[dayOfWeekIndex];
|
||||||
|
|
||||||
|
// }
|
||||||
exports.getPubTypeEnum = function (text) {
|
exports.getPubTypeEnum = function (text) {
|
||||||
const input = text.trim();
|
const input = text.trim();
|
||||||
const mapping = {
|
const mapping = {
|
||||||
|
@ -388,7 +388,7 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var dayofWeek = common.getDayOfWeekNameEnEnum(date);
|
var dayofWeek = common.getDayOfWeekNameEnEnumForDate(date);
|
||||||
const cartEvent = cartEvents.find(
|
const cartEvent = cartEvents.find(
|
||||||
(ce) =>
|
(ce) =>
|
||||||
ce.locationId === location.id &&
|
ce.locationId === location.id &&
|
||||||
@ -482,7 +482,7 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
|
|||||||
// create availability with the same date as the event.
|
// create availability with the same date as the event.
|
||||||
//ToDo: add parameter to control if we want to create availability for each event. can be done whe we import previous shifts.
|
//ToDo: add parameter to control if we want to create availability for each event. can be done whe we import previous shifts.
|
||||||
// if (createAvailabilities) {
|
// if (createAvailabilities) {
|
||||||
// const dayofWeek = common.getDayOfWeekNameEnEnum(date);
|
// const dayofWeek = common.getDayOfWeekNameEnEnumForDate(date);
|
||||||
// const availability = await prisma.availability.create({
|
// const availability = await prisma.availability.create({
|
||||||
// data: {
|
// data: {
|
||||||
// publisherId: publisher.id,
|
// publisherId: publisher.id,
|
||||||
@ -536,7 +536,7 @@ exports.processEvents = async function (events, year, monthNumber, progressCallb
|
|||||||
//ToDo: check if that works
|
//ToDo: check if that works
|
||||||
// const availability = await data.findPublisherAvailability(publisher.id, start);
|
// const availability = await data.findPublisherAvailability(publisher.id, start);
|
||||||
// if (!availability && createAvailabilities) {
|
// if (!availability && createAvailabilities) {
|
||||||
// const dayofWeek = common.getDayOfWeekNameEnEnum(date);
|
// const dayofWeek = common.getDayOfWeekNameEnEnumForDate(date);
|
||||||
// const availability = await prisma.availability.create({
|
// const availability = await prisma.availability.create({
|
||||||
// data: {
|
// data: {
|
||||||
// publisherId: publisher.id,
|
// publisherId: publisher.id,
|
||||||
|
Reference in New Issue
Block a user