Skip to content
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

chore: get informant notification from country config #7627

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

### Breaking changes

- Remove informant notification configuration from the UI and read notification configuration settings from `record-notification` endpoint in countryconfig
- **Gateways searchEvents API updated** `operationHistories` only returns `operationType` & `operatedOn` due to the other fields being unused in OpenCRVS
- **Config changes to review/preview and signatures** Core used to provide review/preview section by default which are now removed and need to be provided from countryconfig. The signature field definitions (e.g. informant signature, bride signature etc.) were hard coded in core which also have now been removed. The signatures can now be added through the review/preview sections defined in countryconfig just like any other field. You can use the following section definition as the default which is without any additional fields. We highly recommend checking out our reference country repository which has the signature fields in it's review/preview sections

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,38 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { APPLICATION_CONFIG_URL } from '@workflow/constants'
import { COUNTRY_CONFIG_URL } from '@workflow/constants'
import fetch from 'node-fetch'
import { logger } from '@opencrvs/commons'

export enum InformantNotificationName {
birthInProgressSMS = 'birthInProgressSMS',
birthDeclarationSMS = 'birthDeclarationSMS',
birthRegistrationSMS = 'birthRegistrationSMS',
birthRejectionSMS = 'birthRejectionSMS',
deathRegistrationSMS = 'deathRegistrationSMS',
deathInProgressSMS = 'deathInProgressSMS',
deathDeclarationSMS = 'deathDeclarationSMS',
deathRejectionSMS = 'deathRejectionSMS'
type EventNotificationFlags = {
'sent-notification'?: boolean
'sent-notification-for-review'?: boolean
'sent-for-approval'?: boolean
registered?: boolean
'sent-for-updates'?: boolean
}

interface IInformantSMSNotification {
_id: string
name: InformantNotificationName
enabled: boolean
updatedAt: number
createdAt: number
type NotificationFlags = {
BIRTH?: EventNotificationFlags
DEATH?: EventNotificationFlags
MARRIAGE?: EventNotificationFlags
}

export async function getInformantSMSNotification(token: string) {
try {
const informantSMSNotificationURL = new URL(
'informantSMSNotification',
APPLICATION_CONFIG_URL
const recordNotificationURL = new URL(
'record-notification',
COUNTRY_CONFIG_URL
).toString()
const res = await fetch(informantSMSNotificationURL, {
const res = await fetch(recordNotificationURL, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
return (await res.json()) as IInformantSMSNotification[]
return (await res.json()) as NotificationFlags
} catch (err) {
logger.error(`Unable to get informant SMS Notifications for error : ${err}`)
throw err
Expand Down
44 changes: 3 additions & 41 deletions packages/workflow/src/records/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import fetch from 'node-fetch'
import { getEventType } from '@workflow/features/registration/utils'
import { EVENT_TYPE, ValidRecord } from '@opencrvs/commons/types'
import { NOTIFICATION_SERVICE_URL } from '@workflow/constants'
import {
getInformantSMSNotification,
InformantNotificationName
} from '@workflow/features/registration/sms-notification-utils'
import { getInformantSMSNotification } from '@workflow/features/registration/sms-notification-utils'
import { internal } from '@hapi/boom'
import { RecordEvent } from './record-events'

Expand Down Expand Up @@ -60,37 +57,7 @@ async function getNotificationFlags(token: string) {
try {
return await getInformantSMSNotification(token)
} catch {
return []
}
}

/** If the mapping is null, the notification is not enabled and won't be sent. */
const MAPPING: Record<
EVENT_TYPE,
Record<NotificationEvent, InformantNotificationName | null>
> = {
[EVENT_TYPE.BIRTH]: {
'sent-notification': InformantNotificationName.birthInProgressSMS,
'sent-notification-for-review':
InformantNotificationName.birthDeclarationSMS,
'sent-for-approval': InformantNotificationName.birthDeclarationSMS,
registered: InformantNotificationName.birthRegistrationSMS,
'sent-for-updates': InformantNotificationName.birthRejectionSMS
},
[EVENT_TYPE.DEATH]: {
'sent-notification': InformantNotificationName.deathInProgressSMS,
'sent-notification-for-review':
InformantNotificationName.deathDeclarationSMS,
'sent-for-approval': InformantNotificationName.deathDeclarationSMS,
registered: InformantNotificationName.deathRegistrationSMS,
'sent-for-updates': InformantNotificationName.deathRejectionSMS
},
[EVENT_TYPE.MARRIAGE]: {
'sent-notification': null,
'sent-notification-for-review': null,
'sent-for-approval': null,
registered: null,
'sent-for-updates': null
return {}
}
}

Expand All @@ -99,11 +66,6 @@ export async function isNotificationEnabled(
event: EVENT_TYPE,
token: string
) {
if (MAPPING[event][action] === null) return false

const notificationFlags = await getNotificationFlags(token)
return (
notificationFlags.find(({ name }) => name === MAPPING[event][action])
?.enabled ?? false
)
return notificationFlags?.[event]?.[action] ?? false
}
Loading