availability serf reference;
fix copying last month;
This commit is contained in:
@ -79,10 +79,7 @@ async function findPublisher(names, email, select, getAll = false) {
|
||||
}
|
||||
|
||||
async function findPublisherAvailability(publisherId, date) {
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
const dayOfWeek = common.getDayOfWeekNameEnEnum(date); // Assuming common.getDayOfWeekNameEnEnum returns the day of week
|
||||
//const weekOfMonth = common.getWeekOfMonth(date); // Assuming common.getWeekOfMonth returns the week of month
|
||||
date = new Date(date); // Convert to date object if not already
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
@ -90,32 +87,24 @@ async function findPublisherAvailability(publisherId, date) {
|
||||
const potentialAvailabilities = await prisma.availability.findMany({
|
||||
where: {
|
||||
publisherId: publisherId,
|
||||
OR: [
|
||||
AND: [ // Ensure both conditions must be met
|
||||
{
|
||||
// Exact date match
|
||||
startTime: {
|
||||
gte: new Date(date.setHours(0, 0, 0, 0)),
|
||||
lt: new Date(date.setHours(23, 59, 59, 999))
|
||||
}
|
||||
lte: new Date(date), // startTime is less than or equal to the date
|
||||
},
|
||||
},
|
||||
{
|
||||
// Correct day of week and before the date, with endDate consideration
|
||||
dayofweek: dayOfWeek,
|
||||
OR: [
|
||||
{
|
||||
endDate: null
|
||||
},
|
||||
{
|
||||
endDate: {
|
||||
gt: date
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
endTime: {
|
||||
gte: new Date(date), // endTime is greater than or equal to the date
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
if (potentialAvailabilities.length === 0) {
|
||||
return null; // No availability found
|
||||
}
|
||||
// Filter the results based on time and other criteria when not exact date match
|
||||
const availability = potentialAvailabilities.find(avail => {
|
||||
const availStartHours = avail.startTime.getHours();
|
||||
|
Reference in New Issue
Block a user