diff --git a/client/src/components/jobs-available-table/jobs-available-supplement.estlines.util.js b/client/src/components/jobs-available-table/jobs-available-supplement.estlines.util.js index f87901e1c..a29a17de4 100644 --- a/client/src/components/jobs-available-table/jobs-available-supplement.estlines.util.js +++ b/client/src/components/jobs-available-table/jobs-available-supplement.estlines.util.js @@ -15,23 +15,43 @@ export const GetSupplementDelta = async (client, jobId, newLines) => { const linesToUpdate = []; newLines.forEach((newLine) => { - const matchingIndex = existingLines.findIndex((eL) => eL.unq_seq === newLine.unq_seq); + const matchingIndexLines = []; + existingLines.forEach((eL, index) => { + if (eL.unq_seq === newLine.unq_seq) { + matchingIndexLines.push({ index, record: eL }); + } + }); - //Should do a check to make sure there is only 1 matching unq sequence number. - - if (matchingIndex >= 0) { - //Found a relevant matching line. Add it to lines to update. - linesToUpdate.push({ - id: existingLines[matchingIndex].id, - newData: { ...newLine, removed: false, act_price_before_ppc: null } - }); - - //Splice out item we found for performance. - existingLines.splice(matchingIndex, 1); - } else { + if (matchingIndexLines.length === 0) { //Didn't find a match. Must be a new line. linesToInsert.push(newLine); } + //If we find only 1, we can use the old logic. + else if (matchingIndexLines.length === 1) { + //Found a relevant matching line. Add it to lines to update. + linesToUpdate.push({ + id: matchingIndexLines[0].record.id, + newData: { ...newLine, removed: false, act_price_before_ppc: null } + }); + //Splice out item we found for performance. + existingLines.splice(matchingIndexLines[0].index, 1); + } else if (matchingIndexLines.length === 2) { + //if we find 2, we need to separate it out by the non-refinish lines and splice one out. + //Find the mathcing one depending on whether this is the refiniish one or not. + const matchingLine = matchingIndexLines.find((i) => + newLine.mod_lbr_ty === "LAR" ? i.record.mod_lbr_ty === "LAR" : i.record.mod_lbr_ty !== "LAR" + ); + + linesToUpdate.push({ + id: matchingLine.record.id, + newData: { ...newLine, removed: false, act_price_before_ppc: null } + }); + //Splice out item we found for performance. + existingLines.splice(matchingLine.index, 1); + } else { + //We found more than 2 matching lines. We should never get here. Throw a warning and back out! + throw new Error("Too many matching lines found. Ensure EMS file is valid."); + } }); //Wahtever is left in the existing lines, are lines that should be removed. diff --git a/hasura/metadata/cron_triggers.yaml b/hasura/metadata/cron_triggers.yaml index 1e3ec7217..31b24a000 100644 --- a/hasura/metadata/cron_triggers.yaml +++ b/hasura/metadata/cron_triggers.yaml @@ -1 +1,8 @@ -[ ] +- name: Task Reminders + webhook: '{{HASURA_API_URL}}/tasks-remind-handler' + schedule: '*/15 * * * *' + include_in_metadata: true + payload: {} + headers: + - name: event-secret + value_from_env: EVENT_SECRET diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index 67888b140..24c33ea50 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -5797,6 +5797,29 @@ - active: _eq: true check: null + event_triggers: + - name: tasks_assigned_changed + definition: + enable_manual: false + insert: + columns: '*' + update: + columns: + - assigned_to + retry_conf: + interval_sec: 10 + num_retries: 3 + timeout_sec: 60 + webhook_from_env: HASURA_API_URL + headers: + - name: event-secret + value_from_env: EVENT_SECRET + request_transform: + method: POST + query_params: {} + template_engine: Kriti + url: '{{$base_url}}/tasks-assigned-handler' + version: 2 - table: name: timetickets schema: public diff --git a/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/down.sql b/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/down.sql new file mode 100644 index 000000000..e99e3e8d7 --- /dev/null +++ b/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/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 "remind_at_sent" timestamptz +-- null; diff --git a/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/up.sql b/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/up.sql new file mode 100644 index 000000000..601b9d8b5 --- /dev/null +++ b/hasura/migrations/1712675814937_alter_table_public_tasks_add_column_remind_at_sent/up.sql @@ -0,0 +1,2 @@ +alter table "public"."tasks" add column "remind_at_sent" timestamptz + null;