-
-
Notifications
You must be signed in to change notification settings - Fork 408
feat(#11192): support extension libs in messages #11244
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
896ac57
4bbaa2b
54db099
23aa74b
5bedc44
3255635
c9be1a6
d66df23
1fd7c74
e727210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| const lineageFactory = require('@medic/lineage'); | ||
| const messageUtils = require('@medic/message-utils'); | ||
| const registrationUtils = require('@medic/registration-utils'); | ||
| const extensionLibs = require('@medic/extension-libs'); | ||
| const constants = require('@medic/constants'); | ||
| const DOC_TYPES = constants.DOC_TYPES; | ||
|
|
||
|
|
@@ -15,6 +16,7 @@ angular.module('services').factory('MessageQueueUtils', | |
|
|
||
| return { | ||
| lineage: lineageFactory($q, DB({ remote: true })), | ||
| loadExtensionLibs: () => extensionLibs.load(DB({ remote: true })), | ||
| messages: messageUtils, | ||
| registrations: registrationUtils | ||
| }; | ||
|
|
@@ -47,7 +49,7 @@ angular.module('services').factory('MessageQueue', | |
|
|
||
| const findIdByKey = (contactsByReference, key) => { | ||
| const row = contactsByReference.rows.find((row) => row.key[1] === key); | ||
| return row && row.id; | ||
| return row && row.id; // NOSONAR: browserify-ngannotate does not support optional chaining. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. misplaced comment? |
||
| }; | ||
|
|
||
| const findPatientUuid = (contactsByReference, message) => { | ||
|
|
@@ -184,7 +186,7 @@ angular.module('services').factory('MessageQueue', | |
| }); | ||
| }; | ||
|
|
||
| const generateScheduledMessages = function(messages, settings) { | ||
| const generateScheduledMessages = function(messages, settings, extensionLibs) { | ||
| const translate = function(key, locale) { | ||
| return $translate.instant(key, null, 'no-interpolation', locale, null); | ||
| }; | ||
|
|
@@ -199,14 +201,15 @@ angular.module('services').factory('MessageQueue', | |
| message: message.scheduled_sms.content | ||
| }; | ||
|
|
||
| message.sms = MessageQueueUtils.messages.generate( | ||
| settings, | ||
| message.sms = MessageQueueUtils.messages.generate({ | ||
| config: settings, | ||
| translate, | ||
| message.doc, | ||
| doc: message.doc, | ||
| content, | ||
| message.scheduled_sms.recipient, | ||
| message.context | ||
| )[0]; | ||
| recipient: message.scheduled_sms.recipient, | ||
| extraContext: message.context, | ||
| extensionLibs, | ||
| })[0]; | ||
| }); | ||
|
|
||
| return messages; | ||
|
|
@@ -314,9 +317,10 @@ angular.module('services').factory('MessageQueue', | |
| .all([ | ||
| Settings(), | ||
| DB({ remote: true }).query('medic-admin/message_queue', params.list), | ||
| DB({ remote: true }).query('medic-admin/message_queue', params.count) | ||
| DB({ remote: true }).query('medic-admin/message_queue', params.count), | ||
| MessageQueueUtils.loadExtensionLibs(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admin message queue hard-fails if extension-libs can't load. API and Sentinel tolerate load failures but admin's Suggestion: catch and fall back to |
||
| ]) | ||
| .then(([settings, messagesList, messagesCount]) => { | ||
| .then(([settings, messagesList, messagesCount, extensionLibs]) => { | ||
| const messages = messagesList.rows.map((row) => { | ||
| const extras = { | ||
| doc: row.doc, | ||
|
|
@@ -331,7 +335,7 @@ angular.module('services').factory('MessageQueue', | |
|
|
||
| return getSubjectsAndRegistrations(messages, settings) | ||
| .then(hydrateContacts) | ||
| .then((messages) => generateScheduledMessages(messages, settings)) | ||
| .then((messages) => generateScheduledMessages(messages, settings, extensionLibs)) | ||
| .then(getRecipients) | ||
| .then((messages) => { | ||
| return { | ||
|
|
||
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.
Let's not include this image in the PR. It can stay on the PR body.