generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feature] Integrate d2-logger (coding dojo ----DO NOT MERGE----- ) #23
Open
deeonwuli
wants to merge
13
commits into
development
Choose a base branch
from
feat/d2-logger
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e47d3cc
feat: setup d2-logger config
deeonwuli 1122a06
feat: reduce indentation
deeonwuli c946d9e
refactor: move script logic to a use case
deeonwuli c52aafe
refactor: use smaller functions on alert data d2 repo
deeonwuli 510a53c
feat: move dhis2 ids to data layer
deeonwuli 16efe26
Merge branch 'development' of https://github.com/EyeSeeTea/zebra-dev …
deeonwuli 34f5483
fix: failing test
deeonwuli abf700b
fix: import AlertSyncData type correctly
deeonwuli 649fa13
feat: use options object for repositories
deeonwuli df2d1ea
refactor: use ts record instead of ternary, clean archi fixes
deeonwuli f564237
Merge branch 'development' of https://github.com/EyeSeeTea/zebra-dev …
deeonwuli 8ac3279
refactor: move static outbreak mappings
deeonwuli fb29557
fix: error on executing script
deeonwuli 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 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 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,23 @@ | ||
export interface InstanceData { | ||
url: string; | ||
username?: string; | ||
password?: string; | ||
} | ||
|
||
export class Instance { | ||
public readonly url: string; | ||
private username: string | undefined; | ||
private password: string | undefined; | ||
|
||
constructor(data: InstanceData) { | ||
this.url = data.url; | ||
this.username = data.username; | ||
this.password = data.password; | ||
} | ||
|
||
public get auth(): { username: string; password: string } | undefined { | ||
return this.username && this.password | ||
? { username: this.username, password: this.password } | ||
: undefined; | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,17 +1,45 @@ | ||
import { D2Api } from "@eyeseetea/d2-api/2.36"; | ||
import { | ||
Notification, | ||
NotificationOptions, | ||
NotificationRepository, | ||
} from "../../domain/repositories/NotificationRepository"; | ||
import { apiToFuture, FutureData } from "../api-futures"; | ||
import { Future } from "../../domain/entities/generic/Future"; | ||
import { UserGroup } from "../../domain/entities/UserGroup"; | ||
import { OutbreakAlert } from "../../domain/entities/alert/OutbreakAlert"; | ||
import i18n from "../../utils/i18n"; | ||
|
||
export class NotificationD2Repository implements NotificationRepository { | ||
constructor(private api: D2Api) {} | ||
|
||
save(notification: Notification): FutureData<void> { | ||
return apiToFuture(this.api.messageConversations.post(notification)).flatMap(() => | ||
Future.success(undefined) | ||
); | ||
notifyNationalWatchStaff( | ||
alertData: OutbreakAlert, | ||
outbreakName: string, | ||
userGroups: UserGroup[] | ||
): FutureData<void> { | ||
const { notificationOptions } = alertData; | ||
|
||
return apiToFuture( | ||
this.api.messageConversations.post({ | ||
subject: `New Outbreak Alert: ${outbreakName} in zm Zambia Ministry of Health`, | ||
text: buildNotificationText(outbreakName, notificationOptions), | ||
userGroups: userGroups, | ||
}) | ||
).flatMap(() => Future.success(undefined)); | ||
} | ||
} | ||
|
||
function buildNotificationText(outbreakKey: string, notificationData: NotificationOptions): string { | ||
const { detectionDate, emergenceDate, incidentManager, notificationDate, verificationStatus } = | ||
notificationData; | ||
|
||
return i18n.t(`There has been a new Outbreak detected for ${outbreakKey} in zm Zambia Ministry of Health. | ||
|
||
Please see the details of the outbreak below: | ||
|
||
Emergence date: ${emergenceDate} | ||
Detection Date : ${detectionDate} | ||
Notification Date : ${notificationDate} | ||
Incident Manager : ${incidentManager} | ||
Verification Status : ${verificationStatus}`); | ||
} |
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.
As the mapping is static, it can be defined at the root level and the function.