using the same API for email UI and sending email
This commit is contained in:
@ -262,27 +262,35 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let subscribedPublishers = [], availablePublishers = [];
|
let targetEmails = await data.getCoverMePublisherEmails(assignment.shift.id);
|
||||||
if (toSubscribed) {
|
if (!toSubscribed) {
|
||||||
//get all subscribed publisers
|
targetEmails.subscribedPublishers = [];
|
||||||
subscribedPublishers = await prisma.publisher.findMany({
|
}
|
||||||
where: {
|
if (!toAvailable) {
|
||||||
isSubscribedToCoverMe: true
|
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
|
// use
|
||||||
|
|
||||||
|
|
||||||
//concat and remove duplicate emails
|
//concat and remove duplicate emails
|
||||||
let pubsToSend = subscribedPublishers.concat(availablePublishers).
|
let pubsToSend = targetEmails.subscribedPublishers.concat(targetEmails.availablePublishers).
|
||||||
filter((item, index, self) =>
|
filter((item, index, self) =>
|
||||||
index === self.findIndex((t) => (
|
index === self.findIndex((t) => (
|
||||||
t.email === item.email && item.email !== publisher.email//and exclude the user himself
|
t.email === item.email && item.email !== publisher.email//and exclude the user himself
|
||||||
|
@ -488,6 +488,8 @@ async function getCoverMePublisherEmails(shiftId) {
|
|||||||
return pubs.map(pub => {
|
return pubs.map(pub => {
|
||||||
return {
|
return {
|
||||||
id: pub.id,
|
id: pub.id,
|
||||||
|
firstName: pub.firstName,
|
||||||
|
lastName: pub.lastName,
|
||||||
name: pub.firstName + " " + pub.lastName,
|
name: pub.firstName + " " + pub.lastName,
|
||||||
email: pub.email
|
email: pub.email
|
||||||
}
|
}
|
||||||
@ -531,6 +533,8 @@ async function getCoverMePublisherEmails(shiftId) {
|
|||||||
availablePublishers = availablePublishers.map(pub => {
|
availablePublishers = availablePublishers.map(pub => {
|
||||||
return {
|
return {
|
||||||
id: pub.id,
|
id: pub.id,
|
||||||
|
firstName: pub.firstName,
|
||||||
|
lastName: pub.lastName,
|
||||||
name: pub.firstName + " " + pub.lastName,
|
name: pub.firstName + " " + pub.lastName,
|
||||||
email: pub.email
|
email: pub.email
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,15 @@ function normalizeEmailAddresses(to) {
|
|||||||
|
|
||||||
return emails; // Always returns an array
|
return emails; // Always returns an array
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Final email sending function.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="to">Email address or array of email addresses</param>
|
||||||
|
/// <param name="subject">Email subject</param>
|
||||||
|
/// <param name="text">Plain text version of the email</param>
|
||||||
|
/// <param name="html">HTML version of the email</param>
|
||||||
|
/// <param name="attachments">Array of attachment objects</param>
|
||||||
|
/// <returns>Promise</returns>
|
||||||
|
|
||||||
exports.SendEmail = async function (to, subject, text, html, attachments = []) {
|
exports.SendEmail = async function (to, subject, text, html, attachments = []) {
|
||||||
let sender = process.env.EMAIL_SENDER || '"Специално Свидетелстване София" <sofia@mwitnessing.com>';
|
let sender = process.env.EMAIL_SENDER || '"Специално Свидетелстване София" <sofia@mwitnessing.com>';
|
||||||
|
Reference in New Issue
Block a user