using the same API for email UI and sending email

This commit is contained in:
Dobromir Popov
2024-04-27 16:49:54 +03:00
parent 0b1ed6b1f8
commit e06a40d8cf
3 changed files with 34 additions and 14 deletions

View File

@ -262,27 +262,35 @@ export default async function handler(req, res) {
}
});
let subscribedPublishers = [], availablePublishers = [];
if (toSubscribed) {
//get all subscribed publisers
subscribedPublishers = await prisma.publisher.findMany({
where: {
isSubscribedToCoverMe: true
}
});
let targetEmails = await data.getCoverMePublisherEmails(assignment.shift.id);
if (!toSubscribed) {
targetEmails.subscribedPublishers = [];
}
if (!toAvailable) {
targetEmails.availablePublishers = [];
}
// let subscribedPublishers = targetEmails.subscribedPublishers, availablePublishers = [];
// if (toSubscribed) {
// //get all subscribed publisers
// subscribedPublishers = await prisma.publisher.findMany({
// where: {
// isSubscribedToCoverMe: true
// }
// });
// }
if (toAvailable) {
availablePublishers = await data.filterPublishersNew("id,firstName,lastName,email", new Date(assignment.shift.startTime),
true, false);
}
// if (toAvailable) {
// availablePublishers = await data.filterPublishersNew("id,firstName,lastName,email", new Date(assignment.shift.startTime),
// true, false);
// }
// use
//concat and remove duplicate emails
let pubsToSend = subscribedPublishers.concat(availablePublishers).
let pubsToSend = targetEmails.subscribedPublishers.concat(targetEmails.availablePublishers).
filter((item, index, self) =>
index === self.findIndex((t) => (
t.email === item.email && item.email !== publisher.email//and exclude the user himself