fix statistics;
rewrite availability filters; fix availability filters; ProtectedRoute.IsInRole helper
This commit is contained in:
@ -4,6 +4,7 @@ import { DayOfWeek, AvailabilityType } from '@prisma/client';
|
||||
const common = require('../../src/helpers/common');
|
||||
const data = require('../../src/helpers/data');
|
||||
const subq = require('../../prisma/bl/subqueries');
|
||||
import { addMinutes } from 'date-fns';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@ -350,7 +351,7 @@ export default async function handler(req, res) {
|
||||
|
||||
break;
|
||||
case "getPossibleShiftPublisherEmails":
|
||||
const subscribedPublishers = await prisma.publisher.findMany({
|
||||
let subscribedPublishers = await prisma.publisher.findMany({
|
||||
where: {
|
||||
isSubscribedToCoverMe: true
|
||||
},
|
||||
@ -373,10 +374,37 @@ export default async function handler(req, res) {
|
||||
let shift = await prisma.shift.findUnique({
|
||||
where: {
|
||||
id: parseInt(req.query.shiftId)
|
||||
},
|
||||
include: {
|
||||
assignments: {
|
||||
include: {
|
||||
publisher: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
let availablePublishers = await filterPublishersNew_Available("id,firstName,lastName,email", new Date(shift.startTime), true, false);
|
||||
let availableIn = new Date(addMinutes(shift.startTime, 0))
|
||||
let availablePublishers = await filterPublishersNew_Available("id,firstName,lastName,email", availableIn,
|
||||
true, false, false);
|
||||
|
||||
//filter out publishers that are already assigned to the shift
|
||||
availablePublishers = availablePublishers.filter(pub => {
|
||||
return shift.assignments.findIndex(assignment => assignment.publisher.id == pub.id) == -1;
|
||||
});
|
||||
//subscribed list includes only publishers that are not already assigned to the shift
|
||||
subscribedPublishers = subscribedPublishers.filter(pub => {
|
||||
return availablePublishers.findIndex(availablePub => availablePub.id == pub.id) == -1
|
||||
&& shift.assignments.findIndex(assignment => assignment.publisher.id == pub.id) == -1;
|
||||
});
|
||||
//return names and email info only
|
||||
|
||||
availablePublishers = availablePublishers.map(pub => {
|
||||
return {
|
||||
id: pub.id,
|
||||
|
Reference in New Issue
Block a user