data api and UI style fixes

This commit is contained in:
Dobromir Popov
2024-05-28 00:57:10 +03:00
parent 308c27eba9
commit a938c89225
2 changed files with 44 additions and 31 deletions

View File

@ -910,7 +910,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
return (
<div
key={index}
className={`text-sm text-white p-2 rounded-md ${isFromPrevMonth ? 'border-l-6 border-black-500' : ''} ${assignmentExists ? 'bg-blue-200' : shift.color} h-24 flex flex-col justify-center`}
className={`text-sm text-white p-2 rounded-md ${isFromPrevMonth ? 'border-l-6 border-black-500' : ''} ${shift.color} ${assignmentExists ? 'border-2 border-blue-500' : ""} h-24 flex flex-col justify-center`}
>
{common.getTimeRange(shift.startTime, shift.endTime)} {shift.id}

View File

@ -212,7 +212,7 @@ async function getAvailabilities(userId) {
* This function heavily relies on the `prisma` client to query and manipulate data related to publishers.
*
* @param {Array|string} selectFields - Fields to select from the publishers data. Can be an array of field names or a comma-separated string of field names.
* @param {string|Date} filterDate - The reference date for filtering. Can be a date string or a Date object. Used to determine relevant time frames like current month, previous month, etc.
* @param {string|Date|null} filterDate - The reference date for filtering. Can be a date string, a Date object, or null. Used to determine relevant time frames like current month, previous month, etc.
* @param {boolean} [isExactTime=false] - If true, filters publishers who are available at the exact time of `filterDate` plus/minus a specific duration (e.g., 90 minutes).
* @param {boolean} [isForTheMonth=false] - If true, adjusts the filtering to encompass the entire month based on `filterDate`.
* @param {boolean} [noEndDateFilter=false] - If true, removes any filtering based on the end date of publishers' availabilities.
@ -224,9 +224,36 @@ async function getAvailabilities(userId) {
async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, noEndDateFilter = false, isWithStats = true, includeOldAvailabilities = false, id = null) {
const prisma = common.getPrismaClient();
if (filterDate !== null) {
let filterTimeFrom, filterTimeTo;
if (filterDate === null || filterDate === "" || filterDate === undefined) {
noEndDateFilter = true;
isForTheMonth = false;
isExactTime = false;
} else {
filterDate = new Date(filterDate); // Convert to date object if not already
//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
isExactTime = false;
} else {
filterTimeFrom = new Date(filterDate)
filterTimeTo = new Date(filterDate);
if (isExactTime) {
//add +- 90 minutes to the filterDate ToDo: should be "shift duration"
// filterTimeFrom.setMinutes(filterTimeFrom.getMinutes() - 90);
filterTimeTo.setMinutes(filterTimeTo.getMinutes() + 90);
}
else {
filterTimeFrom.setHours(0, 0, 0, 0);
filterTimeTo.setHours(23, 59, 59, 999);
}
}
}
const monthInfo = common.getMonthDatesInfo(filterDate);
let prevMnt = new Date(filterDate)
prevMnt.setMonth(prevMnt.getMonth() - 1);
@ -240,7 +267,6 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
return acc;
}, {});
selectBase.assignments = {
select: {
id: true,
@ -252,25 +278,15 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
}
}
},
where: {
shift: {
startTime: {
gte: prevMnt,
}
}
}
// where: {
// shift: {
// startTime: {
// gte: prevMnt,
// }
// }
// }
};
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) {
@ -284,17 +300,14 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
filterTimeTo = monthInfo.lastSunday;
isDayFilter = false;
}
if (isExactTime) {
//add +- 90 minutes to the filterDate ToDo: should be "shift duration"
// filterTimeFrom.setMinutes(filterTimeFrom.getMinutes() - 90);
filterTimeTo.setMinutes(filterTimeTo.getMinutes() + 90);
}
else {
filterTimeFrom.setHours(0, 0, 0, 0);
filterTimeTo.setHours(23, 59, 59, 999);
}
if (filterDate) { // if no date is provided, we don't filter by date
if (filterTimeFrom) { // if no date is provided, we don't filter by date
selectBase.assignments.where = {
shift: {
startTime: { gte: prevMnt },
}
};
whereClause["availabilities"] = {
some: {
OR: [