-
Notifications
You must be signed in to change notification settings - Fork 3
CHI-3954-beacon_mappers_per_helpline #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stephenhand
merged 7 commits into
copilot/refactor-beacon-dispatcher-poller-lambdas
from
CHI-3954-beacon_mappers_per_helpline
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52401e7
Reorganise beacon poller to easily drop in helpline specific document…
stephenhand ae2fccd
Update import path for types module
stephenhand 5c4c4a7
Adjust maxItemsInChunk based on apiType
stephenhand fad04bf
linter
stephenhand 1c67c12
Make dispatcher mappings selectable by helpline code
stephenhand 46300db
Remove redundant type information from incidents returned from dispat…
stephenhand 5967fcd
Fix import path
stephenhand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
hrm-domain/lambdas/custom-integrations/beacon-dispatcher/mapping/gyMapping.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Copyright (C) 2021-2023 Technology Matters | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
|
|
||
| import type { CreateIncidentParams } from '../beacon-service'; | ||
| import type { CaseService, Contact } from '@tech-matters/hrm-types'; | ||
|
|
||
| export const toCreateIncident = ({ | ||
| caseObj, | ||
| contact, | ||
| }: { | ||
| caseObj: CaseService; | ||
| contact: Contact; | ||
| }): CreateIncidentParams => { | ||
| return { | ||
| contact_id: contact.id.toString(), | ||
| case_id: parseInt(caseObj.id), | ||
| }; | ||
| }; |
30 changes: 30 additions & 0 deletions
30
hrm-domain/lambdas/custom-integrations/beacon-dispatcher/mapping/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright (C) 2021-2026 Technology Matters | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
|
|
||
| import * as uscr from './uscrMapping'; | ||
| import * as gy from './gyMapping'; | ||
|
|
||
| export const newCreateIncidentMapper = (helplineCode: string | undefined) => { | ||
| switch (helplineCode) { | ||
| case 'gy': | ||
| return gy.toCreateIncident; | ||
| case 'as': | ||
| case 'uscr': | ||
| return uscr.toCreateIncident; | ||
| default: | ||
| throw new Error(`No mappings configured for for helpline code: ${helplineCode}`); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ustom-integrations/beacon-poller/src/beaconDocumentProcessors/extractContentNodeValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * Copyright (C) 2021-2023 Technology Matters | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
|
|
||
| export type CaseReportContentNode = { | ||
| type: | ||
| | 'text' | ||
| | 'section' | ||
| | 'text_field' | ||
| | 'date_time_field' | ||
| | 'option' | ||
| | 'dropdown' | ||
| | 'date_time_field_calc' | ||
| | 'checkbox' | ||
| | 'documents'; | ||
| value: string | null; | ||
| fields: CaseReportContentNode[] | null; | ||
| label: string; | ||
| } & Record<string, string | null | number | CaseReportContentNode[]>; | ||
|
|
||
| export type CaseReportContentValues = { | ||
| [key: string]: string | null | number | boolean | CaseReportContentValues; | ||
| }; | ||
|
|
||
| export const extractContentNodeValues = ({ | ||
| type, | ||
| value, | ||
| fields, | ||
| label, | ||
| }: CaseReportContentNode): CaseReportContentValues[keyof CaseReportContentValues] => { | ||
| switch (type) { | ||
| case 'section': { | ||
| const sectionEntries = (fields || []).map(node => [ | ||
| node.label, | ||
| extractContentNodeValues(node), | ||
| ]); | ||
| return Object.fromEntries(sectionEntries); | ||
| } | ||
| case 'checkbox': { | ||
| return value === label; | ||
| } | ||
| default: { | ||
| return value; | ||
| } | ||
| } | ||
| }; |
82 changes: 82 additions & 0 deletions
82
...n/lambdas/custom-integrations/beacon-poller/src/beaconDocumentProcessors/gy/caseReport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
| /** | ||
| * Copyright (C) 2021-2026 Technology Matters | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
|
|
||
| import { BeaconDocumentProcessor, NewCaseSectionInfo } from '../../types'; | ||
| import { addSectionToAseloCase, updateAseloCaseStatus } from '../../caseUpdater'; | ||
| import { isErr, isOk, newErr } from '@tech-matters/types'; | ||
| import { CaseReportContentNode } from '../extractContentNodeValues'; | ||
|
|
||
| type RelevantRawCaseReportApiPayload = { | ||
| id: number; | ||
| case_id: string | null; | ||
| incident_id: number; | ||
| created_at: string; | ||
| updated_at: string; | ||
| content: { | ||
| fields: CaseReportContentNode[]; | ||
| }; | ||
| }; | ||
|
|
||
| const caseReportToCaseReportCaseSection = ({ | ||
| id, | ||
| case_id, | ||
| updated_at, | ||
| }: RelevantRawCaseReportApiPayload): NewCaseSectionInfo => { | ||
| return { | ||
| caseId: case_id as string, | ||
| lastUpdated: updated_at, | ||
| section: { | ||
| sectionId: id.toString(), | ||
| sectionTypeSpecificData: {}, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| export type RawCaseReportApiPayload = RelevantRawCaseReportApiPayload & | ||
| Omit<Record<string, any>, keyof RelevantRawCaseReportApiPayload>; | ||
|
|
||
| export const createCaseReportProcessor = ( | ||
| accountSid: string, | ||
| ): BeaconDocumentProcessor<RawCaseReportApiPayload> => { | ||
| const addCaseReportSectionToAseloCase = addSectionToAseloCase( | ||
| 'caseReport', | ||
| caseReportToCaseReportCaseSection, | ||
| accountSid, | ||
| ); | ||
|
|
||
| return async (caseReport: RawCaseReportApiPayload, lastSeen: string) => { | ||
| const caseReportResult = await addCaseReportSectionToAseloCase(caseReport, lastSeen); | ||
| if (isOk(caseReportResult)) { | ||
| const caseStatusUpdateResult = await updateAseloCaseStatus( | ||
| caseReport.case_id!, | ||
| 'open', | ||
| accountSid, | ||
| ); | ||
| if (isErr(caseStatusUpdateResult)) { | ||
| return newErr({ | ||
| message: 'Failed to update status for Aselo case', | ||
| error: { | ||
| type: caseStatusUpdateResult.error.type, | ||
| level: caseStatusUpdateResult.error.level, | ||
| lastUpdated: caseReportResult.unwrap(), | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| return caseReportResult; | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other places where we do this, we use
helplineCode.toUpperCase(). Can we consolidate this one as well?