destinguish between pubs without availabilities (orange) and with changed availabilities (red) in calendar dash

This commit is contained in:
Dobromir Popov
2024-03-02 19:10:29 +02:00
parent 27a0c2cbb4
commit 6c6f8f41d0
6 changed files with 122 additions and 45 deletions

View File

@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { DayOfWeek } from '@prisma/client';
const common = require('../../src/helpers/common');
const data = require('../../src/helpers/data');
const subq = require('../../prisma/bl/subqueries');
import fs from 'fs';
import path from 'path';
@ -168,6 +169,19 @@ export default async function handler(req, res) {
let startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
let endOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
const pubAvCount = await prisma.publisher.findMany({
select: {
id: true,
firstName: true,
lastName: true,
_count: {
select: {
availabilities: true,
}
}
}
});
let shiftsForDate = await prisma.shift.findMany({
where: {
startTime: {
@ -178,12 +192,19 @@ export default async function handler(req, res) {
include: {
assignments: {
include: {
publisher: true,
publisher: subq.publisherSelect
},
},
},
});
shiftsForDate.forEach(shift => {
shift.assignments.forEach(assignment => {
assignment.publisher.availabilityCount = pubAvCount.find(pub => pub.id === assignment.publisher.id)?._count?.availabilities || 0;
});
}
);
console.log("shiftsForDate(" + date + ") - " + shiftsForDate.length + " : " + JSON.stringify(shiftsForDate.map(shift => shift.id)));
res.status(200).json(shiftsForDate);
@ -587,7 +608,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
//if pub has up-to-date availabilities (with dayOfMonth) for the current month
pub.hasUpToDateAvailabilities = pub.availabilities?.some(avail => {
return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= currentMonthEnd;
return avail.dayOfMonth != null && avail.startTime >= currentMonthStart; // && avail.startTime <= currentMonthEnd;
});
});