From 57b3b3a9cd6b3ae8c03310e46218a51abaaefb77 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 18 Apr 2024 16:42:10 -0700 Subject: [PATCH 1/4] Remove hasura constraint. --- .../down.sql | 2 ++ .../up.sql | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/down.sql create mode 100644 hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/up.sql diff --git a/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/down.sql b/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/down.sql new file mode 100644 index 000000000..d7c377ccd --- /dev/null +++ b/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/down.sql @@ -0,0 +1,2 @@ +alter table "public"."employees" drop constraint "employees_user_email_shopid_key"; +alter table "public"."employees" add constraint "employees_user_email_key" unique ("user_email"); diff --git a/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/up.sql b/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/up.sql new file mode 100644 index 000000000..424fc090a --- /dev/null +++ b/hasura/migrations/1713483639240_alter_table_public_employees_add_unique_user_email_shopid/up.sql @@ -0,0 +1,2 @@ +alter table "public"."employees" drop constraint "employees_user_email_key"; +alter table "public"."employees" add constraint "employees_user_email_shopid_key" unique ("user_email", "shopid"); From 0b9f71810634542e94ba4d20166c78a8b9be2bf6 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Thu, 18 Apr 2024 18:25:52 -0700 Subject: [PATCH 2/4] IO-2667 Adjust Email messages Signed-off-by: Allan Carr --- server/email/tasksEmails.js | 35 ++++++++++++++++++++++---------- server/graphql-client/queries.js | 1 + 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/server/email/tasksEmails.js b/server/email/tasksEmails.js index d31eb7b8f..1378a6758 100644 --- a/server/email/tasksEmails.js +++ b/server/email/tasksEmails.js @@ -80,22 +80,33 @@ const endPoints = InstanceManager({ * @returns {string|string} */ const formatDate = (date) => { - return date ? `| Due on ${moment(date).format("MM/DD/YYYY")}` : ""; + return date ? `| Due on: ${moment(date).format("MM/DD/YYYY")}` : ""; +}; + +const formatPriority = (priority) => { + if (priority === 1) { + return "High"; + } else if (priority === 3) { + return "Low"; + } else { + return "Medium"; + } }; /** * Generate the email template arguments. * @param title - * @param createdBy + * @param priority + * @param description * @param dueDate * @param taskId * @returns {{header, body: string, subHeader: string}} */ -const generateTemplateArgs = (title, createdBy, dueDate, taskId) => { +const generateTemplateArgs = (title, priority, description, dueDate, taskId) => { return { header: title, - subHeader: `Assigned by ${createdBy} ${formatDate(dueDate)}`, - body: `Please sign in to your account to view the Task details.` + subHeader: `Priority: ${formatPriority(priority)} ${priority} ${formatDate(dueDate)}`, + body: `${description}
Please sign in to your account to view the further details of the Task.` }; }; @@ -155,8 +166,10 @@ const taskAssignedEmail = async (req, res) => { sendMail( "assigned", newTask.assigned_to, - `A Task has been ${dirty ? "reassigned" : "created"} for you - ${newTask.title}`, - generateEmailTemplate(generateTemplateArgs(newTask.title, newTask.created_by, newTask.due_date, newTask.id)) + `A ${formatPriority(newTask.priority)} PriorityTask has been ${dirty ? "reassigned" : "created"} for you - ${newTask.title}`, + generateEmailTemplate( + generateTemplateArgs(newTask.title, newTask.priority, newTask.description, newTask.due_date, newTask.id) + ) ); // We return success regardless because we don't want to block the event trigger. @@ -217,23 +230,23 @@ const tasksRemindEmail = async (req, res) => { const onlyTask = groupedTasks[recipient.email][0]; emailData.subject = - `New Task Reminder - ${onlyTask.title} ${onlyTask.due_date ? `- ${formatDate(onlyTask.due_date)}` : ""}`.trim(); + `New ${formatPriority(onlyTask.priority)} Priority Task Reminder - ${onlyTask.title} ${onlyTask.due_date ? `- ${formatDate(onlyTask.due_date)}` : ""}`.trim(); emailData.html = generateEmailTemplate( - generateTemplateArgs(onlyTask.title, onlyTask.created_by, onlyTask.due_date, onlyTask.id) + generateTemplateArgs(onlyTask.title, onlyTask.priority, onlyTask.description, onlyTask.due_date, onlyTask.id) ); } // There are multiple emails to send to this author. else { const allTasks = groupedTasks[recipient.email]; - emailData.subject = `New Task Reminder - ${allTasks.length} Tasks require your attention`; + emailData.subject = `New Tasks Reminder - ${allTasks.length} Tasks require your attention`; emailData.html = generateEmailTemplate({ header: `${allTasks.length} Tasks require your attention`, subHeader: `Please sign in to your account to view the Task details.`, body: `` diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index 1ffe8c858..dbd3a851f 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -2407,6 +2407,7 @@ exports.QUERY_REMIND_TASKS = ` ) { id title + description due_date created_by assigned_to From fb322f760f6963fa5dae1343ba08357876877b39 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 19 Apr 2024 08:10:45 -0700 Subject: [PATCH 3/4] Hasura migration changes to change assigned_to to uuid not email. --- hasura/metadata/tables.yaml | 48 +++++++++---------- .../down.sql | 1 + .../up.sql | 5 ++ .../down.sql | 5 ++ .../up.sql | 1 + .../down.sql | 5 ++ .../up.sql | 1 + .../down.sql | 2 + .../up.sql | 1 + .../down.sql | 4 ++ .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 5 ++ 13 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 hasura/migrations/1713538919138_set_fk_public_tasks_created_by/down.sql create mode 100644 hasura/migrations/1713538919138_set_fk_public_tasks_created_by/up.sql create mode 100644 hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/down.sql create mode 100644 hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/up.sql create mode 100644 hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/down.sql create mode 100644 hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/up.sql create mode 100644 hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/down.sql create mode 100644 hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/up.sql create mode 100644 hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/down.sql create mode 100644 hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/up.sql create mode 100644 hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/down.sql create mode 100644 hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/up.sql diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index d8d16cc5d..052a3971d 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -5684,6 +5684,9 @@ - name: bodyshop using: foreign_key_constraint_on: bodyshopid + - name: employee + using: + foreign_key_constraint_on: assigned_to - name: job using: foreign_key_constraint_on: jobid @@ -5693,9 +5696,6 @@ - name: parts_order using: foreign_key_constraint_on: partsorderid - - name: user - using: - foreign_key_constraint_on: assigned_to - name: userByCreatedBy using: foreign_key_constraint_on: created_by @@ -5736,25 +5736,25 @@ - role: user permission: columns: - - completed - - deleted - - priority - - assigned_to - - created_by - - description - - title - - completed_at - - created_at - - deleted_at - - due_date - - remind_at - - updated_at - billid - bodyshopid + - completed + - completed_at + - created_at + - created_by + - deleted + - deleted_at + - description + - due_date - id - jobid - joblineid - partsorderid + - priority + - remind_at + - remind_at_sent + - title + - updated_at filter: bodyshop: associations: @@ -5807,7 +5807,7 @@ columns: '*' update: columns: - - assigned_to + - bodyshopid retry_conf: interval_sec: 10 num_retries: 3 @@ -6191,6 +6191,13 @@ table: name: email_audit_trail schema: public + - name: employees + using: + foreign_key_constraint_on: + column: user_email + table: + name: employees + schema: public - name: eula_acceptances using: foreign_key_constraint_on: @@ -6240,13 +6247,6 @@ table: name: parts_orders schema: public - - name: tasks - using: - foreign_key_constraint_on: - column: assigned_to - table: - name: tasks - schema: public - name: tasksByCreatedBy using: foreign_key_constraint_on: diff --git a/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/down.sql b/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/down.sql new file mode 100644 index 000000000..d7a340297 --- /dev/null +++ b/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/down.sql @@ -0,0 +1 @@ +alter table "public"."tasks" drop constraint "tasks_created_by_fkey2"; diff --git a/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/up.sql b/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/up.sql new file mode 100644 index 000000000..5f2ac1e1a --- /dev/null +++ b/hasura/migrations/1713538919138_set_fk_public_tasks_created_by/up.sql @@ -0,0 +1,5 @@ +alter table "public"."tasks" + add constraint "tasks_created_by_fkey2" + foreign key ("created_by") + references "public"."users" + ("email") on update restrict on delete restrict; diff --git a/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/down.sql b/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/down.sql new file mode 100644 index 000000000..5f2ac1e1a --- /dev/null +++ b/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/down.sql @@ -0,0 +1,5 @@ +alter table "public"."tasks" + add constraint "tasks_created_by_fkey2" + foreign key ("created_by") + references "public"."users" + ("email") on update restrict on delete restrict; diff --git a/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/up.sql b/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/up.sql new file mode 100644 index 000000000..d7a340297 --- /dev/null +++ b/hasura/migrations/1713538981238_delete_fk_public_tasks_tasks_created_by_fkey2/up.sql @@ -0,0 +1 @@ +alter table "public"."tasks" drop constraint "tasks_created_by_fkey2"; diff --git a/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/down.sql b/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/down.sql new file mode 100644 index 000000000..0e6148686 --- /dev/null +++ b/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/down.sql @@ -0,0 +1,5 @@ +alter table "public"."tasks" + add constraint "tasks_assigned_to_fkey" + foreign key ("assigned_to") + references "public"."users" + ("email") on update restrict on delete restrict; diff --git a/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/up.sql b/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/up.sql new file mode 100644 index 000000000..02f3ee3bc --- /dev/null +++ b/hasura/migrations/1713539133324_delete_fk_public_tasks_tasks_assigned_to_fkey/up.sql @@ -0,0 +1 @@ +alter table "public"."tasks" drop constraint "tasks_assigned_to_fkey"; diff --git a/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/down.sql b/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/down.sql new file mode 100644 index 000000000..386ccb288 --- /dev/null +++ b/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/down.sql @@ -0,0 +1,2 @@ +alter table "public"."tasks" alter column "assigned_to" drop not null; +alter table "public"."tasks" add column "assigned_to" text; diff --git a/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/up.sql b/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/up.sql new file mode 100644 index 000000000..a8e8b2d10 --- /dev/null +++ b/hasura/migrations/1713539322925_alter_table_public_tasks_drop_column_assigned_to/up.sql @@ -0,0 +1 @@ +alter table "public"."tasks" drop column "assigned_to" cascade; diff --git a/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/down.sql b/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/down.sql new file mode 100644 index 000000000..852c6cf0f --- /dev/null +++ b/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."tasks" add column "assigned_to" uuid +-- null; diff --git a/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/up.sql b/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/up.sql new file mode 100644 index 000000000..397b556e2 --- /dev/null +++ b/hasura/migrations/1713539337814_alter_table_public_tasks_add_column_assigned_to/up.sql @@ -0,0 +1,2 @@ +alter table "public"."tasks" add column "assigned_to" uuid + null; diff --git a/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/down.sql b/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/down.sql new file mode 100644 index 000000000..02f3ee3bc --- /dev/null +++ b/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/down.sql @@ -0,0 +1 @@ +alter table "public"."tasks" drop constraint "tasks_assigned_to_fkey"; diff --git a/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/up.sql b/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/up.sql new file mode 100644 index 000000000..e4e06f671 --- /dev/null +++ b/hasura/migrations/1713539359261_set_fk_public_tasks_assigned_to/up.sql @@ -0,0 +1,5 @@ +alter table "public"."tasks" + add constraint "tasks_assigned_to_fkey" + foreign key ("assigned_to") + references "public"."employees" + ("id") on update restrict on delete restrict; From 2a8846297f4f4b6948148161ddaf15c9931df17d Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 19 Apr 2024 09:22:20 -0700 Subject: [PATCH 4/4] Update assigned_to handling on front end & debug task assignment. --- .../report-center-modal.component.jsx | 1 + .../task-list/task-list.component.jsx | 2 +- .../task-list/task-list.container.jsx | 4 +-- .../task-upsert-modal.component.jsx | 6 ++--- client/src/graphql/tasks.queries.js | 20 +++++++++------ .../src/pages/tasks/tasks.page.component.jsx | 11 ++++---- client/src/utils/TemplateConstants.js | 2 +- hasura/metadata/tables.yaml | 16 +++++++++--- .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 2 ++ server/email/tasksEmails.js | 25 ++++++++++++------- server/graphql-client/queries.js | 14 +++++++++++ 24 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 hasura/migrations/1713541358566_create_index_tasks_jobid/down.sql create mode 100644 hasura/migrations/1713541358566_create_index_tasks_jobid/up.sql create mode 100644 hasura/migrations/1713541372519_create_index_tasks_assigned-to/down.sql create mode 100644 hasura/migrations/1713541372519_create_index_tasks_assigned-to/up.sql create mode 100644 hasura/migrations/1713541390310_create_index_tasks_joblineid/down.sql create mode 100644 hasura/migrations/1713541390310_create_index_tasks_joblineid/up.sql create mode 100644 hasura/migrations/1713541406066_create_index_tasks_partsorderid/down.sql create mode 100644 hasura/migrations/1713541406066_create_index_tasks_partsorderid/up.sql create mode 100644 hasura/migrations/1713541425057_create_index_tasks_remind_at/down.sql create mode 100644 hasura/migrations/1713541425057_create_index_tasks_remind_at/up.sql create mode 100644 hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/down.sql create mode 100644 hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/up.sql create mode 100644 hasura/migrations/1713541475901_create_index_tasks_bodyshopid/down.sql create mode 100644 hasura/migrations/1713541475901_create_index_tasks_bodyshopid/up.sql diff --git a/client/src/components/report-center-modal/report-center-modal.component.jsx b/client/src/components/report-center-modal/report-center-modal.component.jsx index 49a5372ff..71439f287 100644 --- a/client/src/components/report-center-modal/report-center-modal.component.jsx +++ b/client/src/components/report-center-modal/report-center-modal.component.jsx @@ -236,6 +236,7 @@ export function ReportCenterModalComponent({ reportCenterModal, bodyshop }) { ); + //This was introduced with tasks before assigned_to was shifted to UUID. Keeping in place for reference in the future if needed. if (idtype === "employeeWithEmail") return ( { - const employee = bodyshop?.employees?.find((e) => e.user_email === record.assigned_to); + const employee = bodyshop?.employees?.find((e) => e.id === record.assigned_to); return employee ? `${employee.first_name} ${employee.last_name}` : t("general.labels.na"); } }); diff --git a/client/src/components/task-list/task-list.container.jsx b/client/src/components/task-list/task-list.container.jsx index 1bc801fff..c36d660b8 100644 --- a/client/src/components/task-list/task-list.container.jsx +++ b/client/src/components/task-list/task-list.container.jsx @@ -48,8 +48,8 @@ export function TaskListContainer({ bodyshop: bodyshop.id, [relationshipType]: relationshipId, deleted: deleted === "true", - completed: completed === "true", - assigned_to: mine === "true" ? currentUser.email : undefined, // replace currentUserID with the actual ID of the current user + completed: completed === "true", //TODO: Find where mine is set. + assigned_to: onlyMine ? bodyshop?.employees?.find((e) => e.user_email === currentUser.email)?.id : undefined, // replace currentUserID with the actual ID of the current user offset: page ? (page - 1) * pageLimit : 0, limit: pageLimit, order: [ diff --git a/client/src/components/task-upsert-modal/task-upsert-modal.component.jsx b/client/src/components/task-upsert-modal/task-upsert-modal.component.jsx index 2c5eff0a7..356c59f15 100644 --- a/client/src/components/task-upsert-modal/task-upsert-modal.component.jsx +++ b/client/src/components/task-upsert-modal/task-upsert-modal.component.jsx @@ -224,9 +224,7 @@ export function TaskUpsertModalComponent({ label={t("tasks.fields.assigned_to")} name="assigned_to" initialValue={ - bodyshop.employees.find((employee) => employee?.user_email === currentUser.email && employee.active) - ? currentUser.email - : undefined + bodyshop.employees.find((employee) => employee?.user_email === currentUser.email && employee.active)?.id } rules={[ { @@ -240,7 +238,7 @@ export function TaskUpsertModalComponent({ .filter((x) => x.active && x.user_email) .map((employee) => ({ key: employee.id, - value: employee.user_email, + value: employee.id, label: `${employee.first_name} ${employee.last_name}` }))} /> diff --git a/client/src/graphql/tasks.queries.js b/client/src/graphql/tasks.queries.js index 2bc4893df..90d5606c7 100644 --- a/client/src/graphql/tasks.queries.js +++ b/client/src/graphql/tasks.queries.js @@ -12,6 +12,10 @@ export const PARTIAL_TASK_FIELDS = gql` due_date created_by assigned_to + assigned_to_employee { + id + user_email + } completed completed_at remind_at @@ -80,7 +84,7 @@ export const QUERY_ALL_TASKS_PAGINATED = gql` $bodyshop: uuid! $deleted: Boolean $completed: Boolean - $assigned_to: String + $assigned_to: uuid $order: [tasks_order_by!]! ) { tasks( @@ -121,7 +125,7 @@ export const QUERY_JOBLINE_TASKS_PAGINATED = gql` $bodyshop: uuid! $deleted: Boolean $completed: Boolean - $assigned_to: String + $assigned_to: uuid $order: [tasks_order_by!]! ) { tasks( @@ -164,7 +168,7 @@ export const QUERY_PARTSORDER_TASKS_PAGINATED = gql` $bodyshop: uuid! $deleted: Boolean $completed: Boolean - $assigned_to: String + $assigned_to: uuid $order: [tasks_order_by!]! ) { tasks( @@ -207,7 +211,7 @@ export const QUERY_BILL_TASKS_PAGINATED = gql` $bodyshop: uuid! $deleted: Boolean $completed: Boolean - $assigned_to: String + $assigned_to: uuid $order: [tasks_order_by!]! ) { tasks( @@ -250,7 +254,7 @@ export const QUERY_JOB_TASKS_PAGINATED = gql` $bodyshop: uuid! $deleted: Boolean $completed: Boolean - $assigned_to: String + $assigned_to: uuid $order: [tasks_order_by!]! ) { tasks( @@ -288,7 +292,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql` query QUERY_MY_TASKS_PAGINATED( $offset: Int $limit: Int - $user: String! + $assigned_to: uuid! $bodyshop: uuid! $deleted: Boolean $completed: Boolean @@ -299,7 +303,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql` limit: $limit order_by: $order where: { - assigned_to: { _eq: $user } + assigned_to: { _eq: $assigned_to } bodyshopid: { _eq: $bodyshop } deleted: { _eq: $deleted } completed: { _eq: $completed } @@ -309,7 +313,7 @@ export const QUERY_MY_TASKS_PAGINATED = gql` } tasks_aggregate( where: { - assigned_to: { _eq: $user } + assigned_to: { _eq: $assigned_to } bodyshopid: { _eq: $bodyshop } deleted: { _eq: $deleted } completed: { _eq: $completed } diff --git a/client/src/pages/tasks/tasks.page.component.jsx b/client/src/pages/tasks/tasks.page.component.jsx index 658c34d7b..75aa9092c 100644 --- a/client/src/pages/tasks/tasks.page.component.jsx +++ b/client/src/pages/tasks/tasks.page.component.jsx @@ -3,24 +3,25 @@ import TaskListContainer from "../../components/task-list/task-list.container.js import { QUERY_ALL_TASKS_PAGINATED, QUERY_MY_TASKS_PAGINATED } from "../../graphql/tasks.queries.js"; import taskPageTypes from "./taskPageTypes.jsx"; import { createStructuredSelector } from "reselect"; -import { selectCurrentUser } from "../../redux/user/user.selectors.js"; +import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors.js"; import { connect } from "react-redux"; const mapStateToProps = createStructuredSelector({ - currentUser: selectCurrentUser + currentUser: selectCurrentUser, + bodyshop: selectBodyshop }); const mapDispatchToProps = (dispatch) => ({}); export default connect(mapStateToProps, mapDispatchToProps)(TasksPageComponent); -export function TasksPageComponent({ currentUser, type }) { +export function TasksPageComponent({ bodyshop, currentUser, type }) { switch (type) { case taskPageTypes.MY_TASKS: return ( e.user_email === currentUser.email)?.id} + relationshipType={"assigned_to"} query={{ QUERY_MY_TASKS_PAGINATED }} titleTranslation={"tasks.titles.my_tasks"} disableJobRefetch={true} diff --git a/client/src/utils/TemplateConstants.js b/client/src/utils/TemplateConstants.js index 7415622b9..0296fc317 100644 --- a/client/src/utils/TemplateConstants.js +++ b/client/src/utils/TemplateConstants.js @@ -2114,7 +2114,7 @@ export const TemplateList = (type, context) => { title: i18n.t("reportcenter.templates.tasks_date_employee"), subject: i18n.t("reportcenter.templates.tasks_date_employee"), key: "tasks_date_employee", - idtype: "employeeWithEmail", + idtype: "employee", disabled: false, rangeFilter: { object: i18n.t("reportcenter.labels.objects.tasks"), diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index 052a3971d..d1ad52033 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -2335,6 +2335,13 @@ table: name: jobs schema: public + - name: tasks + using: + foreign_key_constraint_on: + column: assigned_to + table: + name: tasks + schema: public - name: timetickets using: foreign_key_constraint_on: @@ -5678,15 +5685,15 @@ name: tasks schema: public object_relationships: + - name: assigned_to_employee + using: + foreign_key_constraint_on: assigned_to - name: bill using: foreign_key_constraint_on: billid - name: bodyshop using: foreign_key_constraint_on: bodyshopid - - name: employee - using: - foreign_key_constraint_on: assigned_to - name: job using: foreign_key_constraint_on: jobid @@ -5736,6 +5743,7 @@ - role: user permission: columns: + - assigned_to - billid - bodyshopid - completed @@ -5807,7 +5815,7 @@ columns: '*' update: columns: - - bodyshopid + - assigned_to retry_conf: interval_sec: 10 num_retries: 3 diff --git a/hasura/migrations/1713541358566_create_index_tasks_jobid/down.sql b/hasura/migrations/1713541358566_create_index_tasks_jobid/down.sql new file mode 100644 index 000000000..f7d6b496b --- /dev/null +++ b/hasura/migrations/1713541358566_create_index_tasks_jobid/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_jobid"; diff --git a/hasura/migrations/1713541358566_create_index_tasks_jobid/up.sql b/hasura/migrations/1713541358566_create_index_tasks_jobid/up.sql new file mode 100644 index 000000000..f065485c6 --- /dev/null +++ b/hasura/migrations/1713541358566_create_index_tasks_jobid/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_jobid" on + "public"."tasks" using btree ("jobid"); diff --git a/hasura/migrations/1713541372519_create_index_tasks_assigned-to/down.sql b/hasura/migrations/1713541372519_create_index_tasks_assigned-to/down.sql new file mode 100644 index 000000000..41e0992c9 --- /dev/null +++ b/hasura/migrations/1713541372519_create_index_tasks_assigned-to/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_assigned-to"; diff --git a/hasura/migrations/1713541372519_create_index_tasks_assigned-to/up.sql b/hasura/migrations/1713541372519_create_index_tasks_assigned-to/up.sql new file mode 100644 index 000000000..973dc5185 --- /dev/null +++ b/hasura/migrations/1713541372519_create_index_tasks_assigned-to/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_assigned-to" on + "public"."tasks" using btree ("assigned_to"); diff --git a/hasura/migrations/1713541390310_create_index_tasks_joblineid/down.sql b/hasura/migrations/1713541390310_create_index_tasks_joblineid/down.sql new file mode 100644 index 000000000..729f961f2 --- /dev/null +++ b/hasura/migrations/1713541390310_create_index_tasks_joblineid/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_joblineid"; diff --git a/hasura/migrations/1713541390310_create_index_tasks_joblineid/up.sql b/hasura/migrations/1713541390310_create_index_tasks_joblineid/up.sql new file mode 100644 index 000000000..f7222c1b8 --- /dev/null +++ b/hasura/migrations/1713541390310_create_index_tasks_joblineid/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_joblineid" on + "public"."tasks" using btree ("joblineid"); diff --git a/hasura/migrations/1713541406066_create_index_tasks_partsorderid/down.sql b/hasura/migrations/1713541406066_create_index_tasks_partsorderid/down.sql new file mode 100644 index 000000000..a6f8e76ea --- /dev/null +++ b/hasura/migrations/1713541406066_create_index_tasks_partsorderid/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_partsorderid"; diff --git a/hasura/migrations/1713541406066_create_index_tasks_partsorderid/up.sql b/hasura/migrations/1713541406066_create_index_tasks_partsorderid/up.sql new file mode 100644 index 000000000..325c2200b --- /dev/null +++ b/hasura/migrations/1713541406066_create_index_tasks_partsorderid/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_partsorderid" on + "public"."tasks" using btree ("partsorderid"); diff --git a/hasura/migrations/1713541425057_create_index_tasks_remind_at/down.sql b/hasura/migrations/1713541425057_create_index_tasks_remind_at/down.sql new file mode 100644 index 000000000..91c5c470c --- /dev/null +++ b/hasura/migrations/1713541425057_create_index_tasks_remind_at/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_remind_at"; diff --git a/hasura/migrations/1713541425057_create_index_tasks_remind_at/up.sql b/hasura/migrations/1713541425057_create_index_tasks_remind_at/up.sql new file mode 100644 index 000000000..3d630e28c --- /dev/null +++ b/hasura/migrations/1713541425057_create_index_tasks_remind_at/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_remind_at" on + "public"."tasks" using btree ("remind_at"); diff --git a/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/down.sql b/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/down.sql new file mode 100644 index 000000000..4010e7d10 --- /dev/null +++ b/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_remind_at_sent"; diff --git a/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/up.sql b/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/up.sql new file mode 100644 index 000000000..9101bbe24 --- /dev/null +++ b/hasura/migrations/1713541438204_create_index_tasks_remind_at_sent/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_remind_at_sent" on + "public"."tasks" using btree ("remind_at_sent"); diff --git a/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/down.sql b/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/down.sql new file mode 100644 index 000000000..53e784b5d --- /dev/null +++ b/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."tasks_bodyshopid"; diff --git a/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/up.sql b/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/up.sql new file mode 100644 index 000000000..c3dda80b7 --- /dev/null +++ b/hasura/migrations/1713541475901_create_index_tasks_bodyshopid/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "tasks_bodyshopid" on + "public"."tasks" using btree ("bodyshopid"); diff --git a/server/email/tasksEmails.js b/server/email/tasksEmails.js index 1378a6758..913540ef9 100644 --- a/server/email/tasksEmails.js +++ b/server/email/tasksEmails.js @@ -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}
Please sign in to your account to view the further details of the Task.` + subHeader: `Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`, + body: `${description || ""}
View this task.` }; }; @@ -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] = []; } diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index dbd3a851f..42506f897 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -2411,6 +2411,10 @@ exports.QUERY_REMIND_TASKS = ` due_date created_by assigned_to + assigned_to_employee { + id + user_email + } remind_at remind_at_sent priority @@ -2428,3 +2432,13 @@ exports.UPDATE_TASKS_REMIND_AT_SENT = `mutation UPDATE_TASK_REMIND_AT_SENT($task affected_rows } }`; + +exports.QUERY_EMPLOYEE_EMAIL_BY_ID = ` +query QUERY_EMPLOYEE_EMAIL_BY_ID($id: uuid!) { + employees_by_pk(id: $id) { + id + user_email + } +} + +`;