Update assigned_to handling on front end & debug task assignment.
This commit is contained in:
@@ -105,8 +105,8 @@ const formatPriority = (priority) => {
|
||||
const generateTemplateArgs = (title, priority, description, dueDate, taskId) => {
|
||||
return {
|
||||
header: title,
|
||||
subHeader: `Priority: ${formatPriority(priority)} ${priority} ${formatDate(dueDate)}`,
|
||||
body: `${description}<br><a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">Please sign in to your account to view the further details of the Task.</a>`
|
||||
subHeader: `Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
|
||||
body: `${description || ""}<br><a href="${endPoints}/manage/tasks/alltasks?taskid=${taskId}">View this task.</a>`
|
||||
};
|
||||
};
|
||||
|
||||
@@ -154,19 +154,26 @@ const sendMail = (type, to, subject, html, taskIds, successCallback) => {
|
||||
*/
|
||||
const taskAssignedEmail = async (req, res) => {
|
||||
// We have no event Data, bail
|
||||
if (!req?.payload?.event?.data?.new) {
|
||||
return res.status(400).json({ message: "No data in the event payload" });
|
||||
if (!req?.body?.event?.data?.new) {
|
||||
return res.status(400).json({ message: "No data in the event body" });
|
||||
}
|
||||
|
||||
const { new: newTask } = req.payload.event.data;
|
||||
const { new: newTask } = req.body.event.data;
|
||||
|
||||
// This is not a new task, but a reassignment.
|
||||
const dirty = req.payload.event.data?.old && req.payload.event.data?.old?.assigned_to;
|
||||
const dirty = req.body.event.data?.old && req.body.event.data?.old?.assigned_to;
|
||||
|
||||
//Query to get the employee assigned currently.
|
||||
const {
|
||||
employees_by_pk: { user_email }
|
||||
} = await client.request(queries.QUERY_EMPLOYEE_EMAIL_BY_ID, {
|
||||
id: newTask.assigned_to
|
||||
});
|
||||
|
||||
sendMail(
|
||||
"assigned",
|
||||
newTask.assigned_to,
|
||||
`A ${formatPriority(newTask.priority)} PriorityTask has been ${dirty ? "reassigned" : "created"} for you - ${newTask.title}`,
|
||||
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)
|
||||
)
|
||||
@@ -195,7 +202,7 @@ const tasksRemindEmail = async (req, res) => {
|
||||
|
||||
// Group tasks by assigned_to, to avoid sending multiple emails to the same recipient.
|
||||
const groupedTasks = tasksRequest.tasks.reduce((acc, task) => {
|
||||
const key = task.assigned_to;
|
||||
const key = task.assigned_to_email.user_email;
|
||||
if (!acc[key]) {
|
||||
acc[key] = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user