refactor stats page API

This commit is contained in:
Dobromir Popov
2024-04-13 19:48:58 +03:00
parent 3dcc1862cd
commit 7eeb55af88
2 changed files with 12 additions and 5 deletions

View File

@ -227,8 +227,11 @@ async function getAvailabilities(userId) {
}
async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isWithStats = true) {
filterDate = new Date(filterDate); // Convert to date object if not already
// Only attempt to split if selectFields is a string; otherwise, use it as it is.
selectFields = typeof selectFields === 'string' ? selectFields.split(",") : selectFields;
@ -330,14 +333,15 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
}
if (isForTheMonth) {
// If no filter date, return all publishers's availabilities for currentMonthStart
whereClause["availabilities"] = {
some: {
OR: [
// Check if dayOfMonth is not null and startTime is after currentMonthStart (Assignments on specific days AND time)
// Check if dayOfMonth is not null and startTime is after monthInfo.firstMonday (Assignments on specific days AND time)
{
dayOfMonth: { not: null },
startTime: { gte: currentMonthStart },
endTime: { lte: currentMonthEnd }
startTime: { gte: monthInfo.firstMonday },
endTime: { lte: monthInfo.lastSunday }
},
// Check if dayOfMonth is null and match by day of week using the enum (Assigments every week)
{