IO-2667 Tasks Email Generation

Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
Allan Carr
2024-04-19 11:25:02 -07:00
parent 13569a1785
commit dbc2d10d6d
2 changed files with 34 additions and 6 deletions

View File

@@ -99,14 +99,16 @@ const formatPriority = (priority) => {
* @param priority
* @param description
* @param dueDate
* @param bodyshop
* @param job
* @param taskId
* @returns {{header, body: string, subHeader: string}}
*/
const generateTemplateArgs = (title, priority, description, dueDate, taskId) => {
const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, job, taskId) => {
return {
header: title,
subHeader: `Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
body: `${description || ""}<br><a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">View this task.</a>`
subHeader: `Body Shop: ${bodyshop.shopname} | Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
body: `Reference: ${job.ro_number} | ${job.ownr_co_nm ? job.ownr_co_nm : `${job.ownr_fn || ""} ${job.ownr_ln || ""}`.trim()} | ${`${job.v_model_yr || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""}`.trim()}<br>${description ? description + "<br>" : ""}<a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">View this task.</a>`
};
};
@@ -175,7 +177,15 @@ const taskAssignedEmail = async (req, res) => {
user_email,
`A ${formatPriority(newTask.priority)} priority task has been ${dirty ? "reassigned to" : "created for"} you - ${newTask.title}`,
generateEmailTemplate(
generateTemplateArgs(newTask.title, newTask.priority, newTask.description, newTask.due_date, newTask.id)
generateTemplateArgs(
newTask.title,
newTask.priority,
newTask.description,
newTask.due_date,
newTask.bodyshop,
newTask.job,
newTask.id
)
)
);
@@ -240,7 +250,15 @@ const tasksRemindEmail = async (req, res) => {
`New ${formatPriority(onlyTask.priority)} Priority Task Reminder - ${onlyTask.title} ${onlyTask.due_date ? `- ${formatDate(onlyTask.due_date)}` : ""}`.trim();
emailData.html = generateEmailTemplate(
generateTemplateArgs(onlyTask.title, onlyTask.priority, onlyTask.description, onlyTask.due_date, onlyTask.id)
generateTemplateArgs(
onlyTask.title,
onlyTask.priority,
onlyTask.description,
onlyTask.due_date,
onlyTask.bodyshop,
onlyTask.job,
onlyTask.id
)
);
}
// There are multiple emails to send to this author.
@@ -253,7 +271,7 @@ const tasksRemindEmail = async (req, res) => {
body: `<ul>
${allTasks
.map((task) =>
`<li><a href="${endPoints}/manage/tasks/alltasks?taskid=${task.id}">${task.title} - Priority: ${formatPriority(task.priority)} ${task.due_date ? `${formatDate(task.due_date)}` : ""}</a></li>`.trim()
`<li><a href="${endPoints}/manage/tasks/alltasks?taskid=${task.id}">${task.title} - Priority: ${formatPriority(task.priority)} ${task.due_date ? `${formatDate(task.due_date)}` : ""} | Bodyshop: ${task.bodyshop.shopname}</a></li>`.trim()
)
.join("")}
</ul>`

View File

@@ -2420,9 +2420,19 @@ exports.QUERY_REMIND_TASKS = `
priority
job {
id
ownr_co_nm
ownr_fn
ownr_ln
v_make_desc
v_model_desc
v_model_yr
ro_number
}
jobid
bodyshop {
shopname
}
bodyshopid
}
}
`;