refactoring; logging; cleanup;
This commit is contained in:
@ -2,7 +2,7 @@ import { getToken } from "next-auth/jwt";
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { DayOfWeek, AvailabilityType } from '@prisma/client';
|
||||
const common = require('../../src/helpers/common');
|
||||
const data = require('../../src/helpers/data');
|
||||
const dataHelper = require('../../src/helpers/data');
|
||||
const subq = require('../../prisma/bl/subqueries');
|
||||
import { addMinutes } from 'date-fns';
|
||||
|
||||
@ -172,7 +172,7 @@ export default async function handler(req, res) {
|
||||
// find publisher by full name or email
|
||||
case "findPublisher":
|
||||
const getAll = common.parseBool(req.query.all) || false;
|
||||
let publisher = await data.findPublisher(filter, req.query.email, req.query.select, getAll);
|
||||
let publisher = await dataHelper.findPublisher(filter, req.query.email, req.query.select, getAll);
|
||||
res.status(200).json(publisher);
|
||||
break;
|
||||
|
||||
@ -351,68 +351,8 @@ export default async function handler(req, res) {
|
||||
|
||||
break;
|
||||
case "getPossibleShiftPublisherEmails":
|
||||
let subscribedPublishers = await prisma.publisher.findMany({
|
||||
where: {
|
||||
isSubscribedToCoverMe: true
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true
|
||||
}
|
||||
}).then(pubs => {
|
||||
return pubs.map(pub => {
|
||||
return {
|
||||
id: pub.id,
|
||||
name: pub.firstName + " " + pub.lastName,
|
||||
email: pub.email
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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 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,
|
||||
name: pub.firstName + " " + pub.lastName,
|
||||
email: pub.email
|
||||
}
|
||||
});
|
||||
res.status(200).json({ shift, availablePublishers: availablePublishers, subscribedPublishers });
|
||||
let data = await dataHelper.getCoverMePublisherEmails(parseInt(req.query.shiftId));
|
||||
res.status(200).json(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -492,7 +432,7 @@ export async function getMonthlyStatistics(selectFields, filterDate) {
|
||||
|
||||
|
||||
export async function filterPublishersNew_Available(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isWithStats = true, includeOldAvailabilities = false) {
|
||||
return data.filterPublishersNew(selectFields, filterDate, isExactTime, isForTheMonth, false, isWithStats, includeOldAvailabilities);
|
||||
return dataHelper.filterPublishersNew(selectFields, filterDate, isExactTime, isForTheMonth, false, isWithStats, includeOldAvailabilities);
|
||||
}
|
||||
|
||||
// availabilites filter:
|
||||
|
Reference in New Issue
Block a user