ProManager instance server updates.

This commit is contained in:
Patrick Fic
2024-04-22 12:39:30 -07:00
parent 7dd6baef33
commit 73dfb74ed7
7 changed files with 84 additions and 41 deletions

View File

@@ -8,7 +8,8 @@ const INITIAL_STATE = {
name: "ShopName",
address: InstanceRenderManager({
imex: "noreply@iemx.online",
rome: "noreply@romeonline.io"
rome: "noreply@romeonline.io",
promanager: "noreply@promanager.web-est.com"
})
},
to: null,

View File

@@ -1,5 +1,6 @@
import axios from "axios";
import { auth } from "../firebase/firebase.utils";
import InstanceRenderManager from "./instanceRenderMgr";
axios.defaults.baseURL =
import.meta.env.VITE_APP_AXIOS_BASE_API_URL ||
@@ -12,6 +13,13 @@ export const axiosAuthInterceptorId = axios.interceptors.request.use(
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
InstanceRenderManager({
executeFunction: true,
args: [],
promanager: () => {
config.headers["Convenient-Company"] = "promanager";
}
});
}
return config;

View File

@@ -920,6 +920,7 @@
- cdk_dealerid
- city
- claimscorpid
- convenient_company
- country
- created_at
- default_adjustment_rate

View File

@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."bodyshops" add column "convenient_company" text
-- null;

View File

@@ -0,0 +1,2 @@
alter table "public"."bodyshops" add column "convenient_company" text
null;

View File

@@ -24,7 +24,7 @@ const ses = new aws.SES({
const transporter = nodemailer.createTransport({
SES: { ses, aws },
sendingRate: 40 // 40 emails per second.
sendingRate: InstanceManager({ imex: 40, rome: 10 })
});
// Initialize the Tasks Email Queue
@@ -41,38 +41,28 @@ const tasksEmailQueueCleanup = async () => {
}
};
// Handling SIGINT (e.g., Ctrl+C)
process.on("SIGINT", async () => {
await tasksEmailQueueCleanup();
process.exit(0);
});
// Handling SIGTERM (e.g., sent by system shutdown)
process.on("SIGTERM", async () => {
await tasksEmailQueueCleanup();
process.exit(0);
});
// Handling uncaught exceptions
process.on("uncaughtException", async (err) => {
await tasksEmailQueueCleanup();
process.exit(1); // Exit with an 'error' code
});
// Handling unhandled promise rejections
process.on("unhandledRejection", async (reason, promise) => {
await tasksEmailQueueCleanup();
process.exit(1); // Exit with an 'error' code
});
const fromEmails = InstanceManager({
imex: "ImEX Online <noreply@imex.online>",
rome: "Rome Online <noreply@romeonline.io>",
promanager: "ProManager <noreply@promanager.web-est.com>"
});
const endPoints = InstanceManager({
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
rome: process.env?.NODE_ENV === "test" ? "https//test.romeonline.io" : "https://romeonline.io",
promanager: process.env?.NODE_ENV === "test" ? "https//test.promanager.web-est.com" : "https://promanager.web-est.com"
});
if (process.env.NODE_ENV !== "development") {
// Handling SIGINT (e.g., Ctrl+C)
process.on("SIGINT", async () => {
await tasksEmailQueueCleanup();
process.exit(0);
});
// Handling SIGTERM (e.g., sent by system shutdown)
process.on("SIGTERM", async () => {
await tasksEmailQueueCleanup();
process.exit(0);
});
// Handling uncaught exceptions
process.on("uncaughtException", async (err) => {
await tasksEmailQueueCleanup();
process.exit(1); // Exit with an 'error' code
});
// Handling unhandled promise rejections
process.on("unhandledRejection", async (reason, promise) => {
await tasksEmailQueueCleanup();
process.exit(1); // Exit with an 'error' code
});
}
/**
* Format the date for the email.
@@ -105,6 +95,17 @@ const formatPriority = (priority) => {
* @returns {{header, body: string, subHeader: string}}
*/
const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, job, taskId) => {
const endPoints = InstanceManager({
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
rome:
bodyshop.convenient_company === "promanager"
? process.env?.NODE_ENV === "test"
? "https//test.promanager.web-est.com"
: "https://promanager.web-est.com"
: process.env?.NODE_ENV === "test"
? "https//test.romeonline.io"
: "https://romeonline.io"
});
return {
header: title,
subHeader: `Body Shop: ${bodyshop.shopname} | Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
@@ -121,12 +122,15 @@ const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, j
* @param taskIds
* @param successCallback
*/
const sendMail = (type, to, subject, html, taskIds, successCallback) => {
// Push next messages to Nodemailer
//transporter.once("idle", () => {
// Note: This is commented out because despite being in the documentation, it does not work
// and stackoverflow suggests it is not needed
// if (transporter.isIdle()) {
const sendMail = (type, to, subject, html, taskIds, successCallback, requestInstance) => {
const fromEmails = InstanceManager({
imex: "ImEX Online <noreply@imex.online>",
rome:
requestInstance === "promanager"
? "ProManager <noreply@promanager.web-est.com>"
: "Rome Online <noreply@romeonline.io>"
});
transporter.sendMail(
{
from: fromEmails,
@@ -184,7 +188,8 @@ const taskAssignedEmail = async (req, res) => {
tasks_by_pk.job,
newTask.id
)
)
),
tasks_by_pk.bodyshop.convenient_company
);
// We return success regardless because we don't want to block the event trigger.
@@ -233,6 +238,14 @@ const tasksRemindEmail = async (req, res) => {
// Iterate over all recipients and send the email.
recipientCounts.forEach((recipient) => {
const fromEmails = InstanceManager({
imex: "ImEX Online <noreply@imex.online>",
rome:
onlyTask.bodyshop.convenient_company === "promanager"
? "ProManager <noreply@promanager.web-est.com>"
: "Rome Online <noreply@romeonline.io>"
});
const emailData = {
from: fromEmails,
to: recipient.email
@@ -261,6 +274,18 @@ const tasksRemindEmail = async (req, res) => {
}
// There are multiple emails to send to this author.
else {
const endPoints = InstanceManager({
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
rome:
allTasks[0].bodyshop.convenient_company === "promanager"
? process.env?.NODE_ENV === "test"
? "https//test.promanager.web-est.com"
: "https://promanager.web-est.com"
: process.env?.NODE_ENV === "test"
? "https//test.romeonline.io"
: "https://romeonline.io"
});
const allTasks = groupedTasks[recipient.email];
emailData.subject = `New Tasks Reminder - ${allTasks.length} Tasks require your attention`;
emailData.html = generateEmailTemplate({

View File

@@ -2431,6 +2431,7 @@ exports.QUERY_REMIND_TASKS = `
jobid
bodyshop {
shopname
convenient_company
}
bodyshopid
}
@@ -2453,6 +2454,7 @@ query QUERY_TASK_BY_ID($id: uuid!) {
}
bodyshop{
shopname
convenient_company
}
job{
ro_number