ems-backend
ems-backend copied to clipboard
Email notification system Phase 1
Phase 1
- Creating Email Alert
- Selecting the datasets dynamically
- Applying conditions(Filters)
- Selecting fields(To be sent in the email)
- Preview(For Phase 1 we are doing only the table view)
- Selecting the recipient list from the data set
- Adding cc and Bcc fields
- Importing email ids from excel
- Creating the email service in the App builder backend
- Sending email on Manual trigger
- Layout styling(with header, footer and banner)
Description
Email Notification Model – The Mongoose schema file used to represent an Email Notification configuration follows the same principles as all other models used in the App Builder. It exposes a type representing the same object, and uses the permissions system as other models.
File index.ts in routes/notification - Provides REST endpoint for sending emails (Phase 1 - point 10); an email notification configuration is fetched from the database given a configuration ID, records are fetched according to user selected fields and filters, and are presented in a table with converted macros (e.g. {{today.now}}).Email is sent to the selected distribution list.
en.json - WHO copyright for sending emails
routes - upload/download – Fetch endpoints for importing email addresses from Excel, download for getting import template.
getFilter - added InTheLast case for dynamically calculating time offsets when filtering (e.g. new events in the last 24hr).
GraphQL Mutations - responsible for persisting email configurations and distribution lists.
Queries – responsible for fetching data for previews in notification configurations and distribution lists
Useful links
- Please insert link to ticket - https://dev.azure.com/WHOHQ/EMSSAFE/_workitems/edit/16252
- Please insert link to front-end pull request - https://github.com/ReliefApplications/ems-frontend/pull/2344
Type of change
- [X] New feature (non-breaking change which adds functionality)
- [X] This change requires a documentation update
Hi @SianaDicheva,
I found a bug when using a resource with an array field, this part of the aggregation fails: { emailFields: { $filter: { input: "$matchingFields", as: "field", cond: { $regexMatch: { input: { $toString: "$$field.v", }, regex: {}, options: "i", }, }, }, }, } Error: PlanExecutor error during aggregation :: caused by :: Unsupported conversion from array to string in $convert with no onError value Reproduce: Create a resource with a multi-select dropdown, and try to create a notification with it.
Hi @SianaDicheva,
I found a bug when using a resource with an array field, this part of the aggregation fails: { emailFields: { $filter: { input: "$matchingFields", as: "field", cond: { $regexMatch: { input: { toString:"$field.v", }, regex: {}, options: "i", }, }, }, }, } Error: PlanExecutor error during aggregation :: caused by :: Unsupported conversion from array to string in $convert with no onError value Reproduce: Create a resource with a multi-select dropdown, and try to create a notification with it.
Hi, thanks for pointing out this issue, we've debugged the problem and will push a fix soon :)
Hi @SianaDicheva @morgang-adappt getting this error when trying to save/send email in the preview phase: { "errors": [ { "message": "Cannot query field "blockType" on type "DataSet".", "locations": [ { "line": 8, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } }, { "message": "Cannot query field "textStyle" on type "DataSet". Did you mean "tableStyle"?", "locations": [ { "line": 9, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } } ] }
Hi @SianaDicheva @morgang-adappt getting this error when trying to save/send email in the preview phase: { "errors": [ { "message": "Cannot query field "blockType" on type "DataSet".", "locations": [ { "line": 8, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } }, { "message": "Cannot query field "textStyle" on type "DataSet". Did you mean "tableStyle"?", "locations": [ { "line": 9, "column": 7 } ], "extensions": { "code": "GRAPHQL_VALIDATION_FAILED", "stacktrace": [ ] } } ] }
Hi @MwanPygmay ,
I have added a commit, which hopefully resolves these errors.
Let me know if there is anything else which pops up.
Have a lovely weekend!
@HasnatL-Adapptlimited
closing this one as it's outdated