destinguish between pubs without availabilities (orange) and with changed availabilities (red) in calendar dash
This commit is contained in:
@ -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;
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user