IO-3020 IO-3036 Initial removal of ProManager

This commit is contained in:
Patrick Fic
2024-11-21 13:37:36 -08:00
parent 289a666b6d
commit 9ccbca2678
124 changed files with 3199 additions and 1140 deletions

View File

@@ -4,8 +4,7 @@ const Dinero = require("dinero.js");
const InstanceManager = require("../utils/instanceMgr").default;
const { DiscountNotAlreadyCounted } = InstanceManager({
imex: require("../job/job-totals"),
rome: require("../job/job-totals-USA"),
promanager: "USE_ROME"
rome: require("../job/job-totals-USA")
});
const logger = require("../utils/logger");
@@ -554,7 +553,7 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
const state_tax = Dinero(job_totals.totals.state_tax);
const local_tax = Dinero(job_totals.totals.local_tax);
const RulesetToUse = InstanceManager({ imex: "CANADA", rome: "US", promanager: "US" });
const RulesetToUse = InstanceManager({ imex: "CANADA", rome: "US" });
if (RulesetToUse === "CANADA") {
if (federal_tax.getAmount() > 0) {

View File

@@ -12,8 +12,7 @@ const _ = require("lodash");
const InstanceManager = require("../utils/instanceMgr").default;
const { DiscountNotAlreadyCounted } = InstanceManager({
imex: require("../job/job-totals"),
rome: require("../job/job-totals-USA"),
promanager: "USE_ROME"
rome: require("../job/job-totals-USA")
});
exports.defaultRoute = async function (req, res) {

View File

@@ -14,8 +14,7 @@ const { header, end, start } = require("./html");
const defaultFooter = () => {
return RenderInstanceManager({
imex: "ImEX Online Collision Repair Management System",
rome: "Rome Technologies",
promanager: "ProManager"
rome: "Rome Technologies"
});
};

View File

@@ -53,8 +53,7 @@ const sendServerEmail = async ({ subject, text }) => {
{
from: InstanceManager({
imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`,
promanager: `ProManager API - ${process.env.NODE_ENV} <noreply@promanager.web-est.com>`
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
}),
to: ["patrick@imexsystems.ca", "support@thinkimex.com"],
subject: subject,
@@ -78,27 +77,13 @@ const sendServerEmail = async ({ subject, text }) => {
}
};
const sendProManagerWelcomeEmail = async ({ to, subject, html }) => {
try {
await mailer.sendMail({
from: `ProManager <noreply@promanager.web-est.com>`,
to,
subject,
html
});
} catch (error) {
logger.log("server-email-failure", "error", null, null, { error });
}
};
const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachments }) => {
try {
mailer.sendMail(
{
from: InstanceManager({
imex: `ImEX Online <noreply@imex.online>`,
rome: `Rome Online <noreply@romeonline.io>`,
promanager: `ProManager <noreply@promanager.web-est.com>`
rome: `Rome Online <noreply@romeonline.io>`
}),
to: to,
subject: subject,
@@ -247,8 +232,7 @@ const emailBounce = async (req, res) => {
replyTo ===
InstanceManager({
imex: "noreply@imex.online",
rome: "noreply@romeonline.io",
promanager: "noreply@promanager.web-est.com"
rome: "noreply@romeonline.io"
})
) {
res.sendStatus(200);
@@ -270,13 +254,11 @@ const emailBounce = async (req, res) => {
//bcc: "patrick@snapt.ca",
subject: `${InstanceMgr({
imex: "ImEX Online",
rome: "Rome Online",
promanager: "ProManager"
rome: "Rome Online"
})} Bounced Email - RE: ${subject}`,
text: `${InstanceMgr({
imex: "ImEX Online",
rome: "Rome Online",
promanager: "ProManager"
rome: "Rome Online"
})} has tried to deliver an email with the subject: ${subject} to the intended recipients but encountered an error.
${body.bounce?.bouncedRecipients.map(
@@ -305,6 +287,5 @@ module.exports = {
sendEmail,
sendServerEmail,
sendTaskEmail,
sendProManagerWelcomeEmail,
emailBounce
};

View File

@@ -87,14 +87,7 @@ const formatPriority = (priority) => {
const getEndpoints = (bodyshop) =>
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"
rome: process.env?.NODE_ENV === "test" ? "https//test.romeonline.io" : "https://romeonline.io"
});
const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, job, taskId, dateLine, createdBy) => {
@@ -120,10 +113,7 @@ const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, j
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>"
rome: "Rome Online <noreply@romeonline.io>"
});
mailer.sendMail(
@@ -239,10 +229,7 @@ const tasksRemindEmail = async (req, res) => {
recipientCounts.forEach((recipient) => {
const fromEmails = InstanceManager({
imex: "ImEX Online <noreply@imex.online>",
rome:
tasksRequest?.tasks[0].bodyshop.convenient_company === "promanager"
? "ProManager <noreply@promanager.web-est.com>"
: "Rome Online <noreply@romeonline.io>"
rome: "Rome Online <noreply@romeonline.io>"
});
const emailData = {
@@ -279,14 +266,7 @@ const tasksRemindEmail = async (req, res) => {
else {
const endPoints = InstanceManager({
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
rome:
tasksRequest?.tasks[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"
rome: process.env?.NODE_ENV === "test" ? "https//test.romeonline.io" : "https://romeonline.io"
});
const allTasks = groupedTasks[recipient.email];

View File

@@ -57,108 +57,108 @@ const createUser = async (req, res) => {
}
};
const sendPromanagerWelcomeEmail = (req, res) => {
const { authid, email } = req.body;
// const sendPromanagerWelcomeEmail = (req, res) => {
// const { authid, email } = req.body;
// Fetch user from Firebase
admin
.auth()
.getUser(authid)
.then((userRecord) => {
if (!userRecord) {
return Promise.reject({ status: 404, message: "User not found in Firebase." });
}
// // Fetch user from Firebase
// admin
// .auth()
// .getUser(authid)
// .then((userRecord) => {
// if (!userRecord) {
// return Promise.reject({ status: 404, message: "User not found in Firebase." });
// }
// Fetch user data from the database using GraphQL
return client.request(
`
query GET_USER_BY_EMAIL($email: String!) {
users(where: { email: { _eq: $email } }) {
email
validemail
associations {
id
shopid
bodyshop {
id
convenient_company
}
}
}
}`,
{ email: email.toLowerCase() }
);
})
.then((dbUserResult) => {
const dbUser = dbUserResult?.users?.[0];
if (!dbUser) {
return Promise.reject({ status: 404, message: "User not found in database." });
}
// // Fetch user data from the database using GraphQL
// return client.request(
// `
// query GET_USER_BY_EMAIL($email: String!) {
// users(where: { email: { _eq: $email } }) {
// email
// validemail
// associations {
// id
// shopid
// bodyshop {
// id
// convenient_company
// }
// }
// }
// }`,
// { email: email.toLowerCase() }
// );
// })
// .then((dbUserResult) => {
// const dbUser = dbUserResult?.users?.[0];
// if (!dbUser) {
// return Promise.reject({ status: 404, message: "User not found in database." });
// }
// Validate email before proceeding
if (!dbUser.validemail) {
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
message: "User email is not valid, skipping email.",
email
});
return res.status(200).json({ message: "User email is not valid, email not sent." });
}
// // Validate email before proceeding
// if (!dbUser.validemail) {
// logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
// message: "User email is not valid, skipping email.",
// email
// });
// return res.status(200).json({ message: "User email is not valid, email not sent." });
// }
// Check if the user's company is ProManager
const convenientCompany = dbUser.associations?.[0]?.bodyshop?.convenient_company;
if (convenientCompany !== "promanager") {
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
message: 'convenient_company is not "promanager", skipping email.',
convenientCompany
});
return res.status(200).json({ message: `convenient_company is not "promanager", email not sent.` });
}
// // Check if the user's company is ProManager
// const convenientCompany = dbUser.associations?.[0]?.bodyshop?.convenient_company;
// if (convenientCompany !== "promanager") {
// logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
// message: 'convenient_company is not "promanager", skipping email.',
// convenientCompany
// });
// return res.status(200).json({ message: `convenient_company is not "promanager", email not sent.` });
// }
// Generate password reset link
return admin
.auth()
.generatePasswordResetLink(dbUser.email)
.then((resetLink) => ({ dbUser, resetLink }));
})
.then(({ dbUser, resetLink }) => {
// Send welcome email (replace with your actual email-sending service)
return sendProManagerWelcomeEmail({
to: dbUser.email,
subject: "Welcome to the ProManager platform.",
html: generateEmailTemplate({
header: "",
subHeader: "",
body: `
<p>Welcome to the ProManager platform. Please click the link below to reset your password:</p>
<p><a href="${resetLink}">Reset your password</a></p>
<p>User Details:</p>
<ul>
<li>Email: ${dbUser.email}</li>
</ul>
`
})
});
})
.then(() => {
// Log success and return response
logger.log("admin-send-welcome-email", "debug", req.user.email, null, {
request: req.body,
ioadmin: true,
emailSentTo: email
});
res.status(200).json({ message: "Welcome email sent successfully." });
})
.catch((error) => {
logger.log("admin-send-welcome-email-error", "ERROR", req.user.email, null, { error });
// // Generate password reset link
// return admin
// .auth()
// .generatePasswordResetLink(dbUser.email)
// .then((resetLink) => ({ dbUser, resetLink }));
// })
// .then(({ dbUser, resetLink }) => {
// // Send welcome email (replace with your actual email-sending service)
// return sendProManagerWelcomeEmail({
// to: dbUser.email,
// subject: "Welcome to the ProManager platform.",
// html: generateEmailTemplate({
// header: "",
// subHeader: "",
// body: `
// <p>Welcome to the ProManager platform. Please click the link below to reset your password:</p>
// <p><a href="${resetLink}">Reset your password</a></p>
// <p>User Details:</p>
// <ul>
// <li>Email: ${dbUser.email}</li>
// </ul>
// `
// })
// });
// })
// .then(() => {
// // Log success and return response
// logger.log("admin-send-welcome-email", "debug", req.user.email, null, {
// request: req.body,
// ioadmin: true,
// emailSentTo: email
// });
// res.status(200).json({ message: "Welcome email sent successfully." });
// })
// .catch((error) => {
// logger.log("admin-send-welcome-email-error", "ERROR", req.user.email, null, { error });
if (!res.headersSent) {
res.status(error.status || 500).json({
message: error.message || "Error sending welcome email.",
error
});
}
});
};
// if (!res.headersSent) {
// res.status(error.status || 500).json({
// message: error.message || "Error sending welcome email.",
// error
// });
// }
// });
// };
const updateUser = (req, res) => {
logger.log("admin-update-user", "debug", req.user.email, null, {

View File

@@ -10,7 +10,11 @@
function InstanceManager({ args, instance, debug, executeFunction, rome, promanager, imex }) {
let propToReturn = null;
//TODO: Remove after debugging.
if (promanager) {
console.trace("ProManager Prop was used");
}
switch (instance || process.env.INSTANCE) {
case "IMEX":
propToReturn = imex;