diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b17fc8cba..a3c1564f2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/workflow/src/features/registration/sms-notification-utils.ts b/packages/workflow/src/features/registration/sms-notification-utils.ts index 68c8a9c43b..885a716335 100644 --- a/packages/workflow/src/features/registration/sms-notification-utils.ts +++ b/packages/workflow/src/features/registration/sms-notification-utils.ts @@ -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 diff --git a/packages/workflow/src/records/notification.ts b/packages/workflow/src/records/notification.ts index c735c01ba2..5480ff5cf5 100644 --- a/packages/workflow/src/records/notification.ts +++ b/packages/workflow/src/records/notification.ts @@ -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' @@ -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 -> = { - [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 {} } } @@ -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 }