Skip to content

Commit a3cef71

Browse files
authored
Merge pull request #1142 from opencrvs/ocrvs-10720-init
Add WIP custom action to birth config
2 parents 2630210 + 09e0da2 commit a3cef71

File tree

10 files changed

+66
-27
lines changed

10 files changed

+66
-27
lines changed

infrastructure/postgres/setup-analytics.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ CREATE TABLE IF NOT EXISTS analytics.event_actions (
8585
UNIQUE (id, event_id)
8686
);
8787
88+
ALTER TABLE analytics.event_actions ADD COLUMN IF NOT EXISTS custom_action_type TEXT;
89+
8890
CREATE TABLE IF NOT EXISTS analytics.location_levels (
8991
id text PRIMARY KEY,
9092
level int NOT NULL,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"@hapi/boom": "^9.1.1",
7070
"@hapi/hapi": "^20.0.1",
7171
"@hapi/inert": "^6.0.3",
72-
"@opencrvs/toolkit": "1.9.0-rc.d3d43c3",
72+
"@opencrvs/toolkit": "1.9.0-rc.d748ac1",
7373
"@types/chalk": "^2.2.0",
7474
"@types/csv2json": "^1.4.0",
7575
"@types/fhir": "^0.0.30",

src/api/custom-event/handler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export function getCustomEventsHandler(
2424
.code(200)
2525
}
2626

27+
export async function onCustomActionHandler(
28+
request: ActionConfirmationRequest,
29+
h: Hapi.ResponseToolkit
30+
) {
31+
return h.response().code(200)
32+
}
33+
2734
export async function onAnyActionHandler(
2835
request: ActionConfirmationRequest,
2936
h: Hapi.ResponseToolkit
@@ -33,6 +40,7 @@ export async function onAnyActionHandler(
3340
const token = request.auth.artifacts.token as string
3441

3542
const event = request.payload
43+
3644
await sendInformantNotification({ event, token })
3745

3846
return h.response().code(200)

src/api/notification/informantNotification.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import { InformantType as BirthInformantType } from '@countryconfig/form/v2/birt
2626
import { InformantTemplateType } from './sms-service'
2727
import { generateFailureLog, NotificationParams, notify } from './handler'
2828
import { InformantType as DeathInformantType } from '@countryconfig/form/v2/death/forms/pages/informant'
29-
import { birthEvent } from '@countryconfig/form/v2/birth'
30-
import { deathEvent } from '@countryconfig/form/v2/death'
3129

3230
const resolveName = (name: FieldUpdateValue) => {
3331
const nameObj = {
@@ -77,18 +75,6 @@ function getInformant(eventType: string, declaration: Record<string, any>) {
7775
throw new Error('Invalid event type')
7876
}
7977

80-
function getEventConfig(eventType: string) {
81-
if (eventType === Event.Birth) {
82-
return birthEvent
83-
}
84-
85-
if (eventType === Event.Death) {
86-
return deathEvent
87-
}
88-
89-
throw new Error('Invalid event type')
90-
}
91-
9278
async function getNotificationParams(
9379
event: EventDocument,
9480
token: string,

src/data-seeding/roles/roles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ export const roles: Role[] = [
221221
'record.register[event=birth|death|tennis-club-membership]',
222222
'record.registered.print-certified-copies[event=birth|death|tennis-club-membership]',
223223
'record.registered.correct[event=birth|death|tennis-club-membership]',
224-
'record.unassign-others[event=birth|death|tennis-club-membership]'
224+
'record.unassign-others[event=birth|death|tennis-club-membership]',
225+
'record.custom-action[event=birth,customActionType=Approve]'
225226
]
226227
},
227228
{

src/form/v2/birth/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,32 @@ export const birthEvent = defineConfig({
219219
}
220220
]
221221
},
222+
{
223+
type: ActionType.CUSTOM,
224+
customActionType: 'Approve',
225+
label: {
226+
defaultMessage: 'Approve',
227+
description:
228+
'This is shown as the action name anywhere the user can trigger the action from',
229+
id: 'event.birth.action.approve.label'
230+
},
231+
supportingCopy: {
232+
defaultMessage:
233+
'This birth has been registered late. You are now approving it for further validation and registration.',
234+
description: 'This is the confirmation text for the approve action',
235+
id: 'event.birth.action.approve.confirmationText'
236+
},
237+
form: [],
238+
flags: [
239+
{ id: 'approval-required-for-late-registration', operation: 'remove' }
240+
],
241+
auditHistoryLabel: {
242+
defaultMessage: 'Approved',
243+
description:
244+
'The label to show in audit history for the approve action',
245+
id: 'event.birth.action.approve.audit-history-label'
246+
}
247+
},
222248
{
223249
type: ActionType.VALIDATE,
224250
label: {

src/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ import { fontsHandler } from './api/fonts/handler'
5858
import { recordNotificationHandler } from './api/record-notification/handler'
5959
import {
6060
getCustomEventsHandler,
61-
onAnyActionHandler
61+
onAnyActionHandler,
62+
onCustomActionHandler
6263
} from '@countryconfig/api/custom-event/handler'
63-
import { readFileSync } from 'fs'
6464
import {
6565
ActionDocument,
6666
ActionStatus,
@@ -92,7 +92,7 @@ export interface ITokenPayload {
9292
export default function getPlugins() {
9393
const plugins: any[] = [inert, JWT]
9494

95-
if (process.env.NODE_ENV === 'production') {
95+
if (process.env.NODE_ENV !== 'test') {
9696
plugins.push({
9797
plugin: Pino,
9898
options: {
@@ -641,6 +641,16 @@ export async function createServer() {
641641
}
642642
})
643643

644+
server.route({
645+
method: 'POST',
646+
path: `/trigger/events/{event}/actions/${ActionType.CUSTOM}`,
647+
handler: onCustomActionHandler,
648+
options: {
649+
tags: ['api', 'events'],
650+
description: 'Receives notifications on event custom action'
651+
}
652+
})
653+
644654
server.route({
645655
method: 'POST',
646656
path: '/trigger/events/{event}/actions/{action}',
@@ -748,9 +758,9 @@ export async function createServer() {
748758
await syncLocationLevels()
749759
await syncLocationStatistics()
750760

751-
const logMsg = `Server successfully started on ${COUNTRY_CONFIG_HOST}:${COUNTRY_CONFIG_PORT}`
752-
logger.info(logMsg)
753-
server.log('info', logMsg)
761+
logger.info(
762+
`Server successfully started on ${COUNTRY_CONFIG_HOST}:${COUNTRY_CONFIG_PORT}`
763+
)
754764
}
755765

756766
return { server, start, stop }

src/logger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export const logger =
1919
]
2020
})
2121
: pino({
22+
serializers: {
23+
req: () => undefined,
24+
res: () => undefined,
25+
responseTime: () => undefined
26+
},
2227
transport: {
2328
target: 'pino-pretty',
2429
options: {

src/translations/client.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ event.birth.action.mark-as-duplicate.label,Label for review potential duplicate
862862
event.birth.action.register.label,Label for review record button in dropdown menu,Register,Enregistrer
863863
event.birth.action.request-correction.label,This is shown as the action name anywhere the user can trigger the action from,Correct record,Enregistrement correct
864864
event.birth.action.validate.label,This is shown as the action name anywhere the user can trigger the action from,Validate,Valider
865+
event.birth.action.approve.confirmationText,This is the confirmation text for the approve action,This birth has been registered late. You are now approving it for further validation and registration.,Cette naissance a été enregistrée en retard. Vous l'approuvez maintenant pour une validation et un enregistrement supplémentaires.
865866
event.birth.label,This is what this event is referred as in the system,Birth,Naissance
866867
event.birth.summary.child.dob.empty,Label for date of birth not available,No date of birth,Pas de date de naissance
867868
event.birth.summary.child.placeOfBirth.empty,Label for place of birth not available,No place of birth,Pas de lieu de naissance
@@ -1113,7 +1114,7 @@ event.tennis-club-membership.summary.field.recommender.id.empty,Shown when the r
11131114
event.tennis-club-membership.summary.field.recommender.id.label,Label for the recommender's ID field,Recommender's ID,Recommender's ID
11141115
events.overview.tabs.record,Title of the Record tab,Record,Enregistrement
11151116
events.overview.tabs.audit,Title of the Audit tab,Audit,Audit
1116-
events.history.status,Events status history,"{status, select, Requested {Waiting for external validation} other {{action, select, CREATE {Declaration started} NOTIFY {Sent incomplete} VALIDATE {Sent for approval} DRAFT {Draft} DECLARE {Sent for review} REGISTER {Registered} PRINT_CERTIFICATE {Certified} REJECT {Rejected} ARCHIVE {Archived} DUPLICATE_DETECTED {Flagged as potential duplicate} MARKED_AS_DUPLICATE {Marked as a duplicate} MARK_AS_NOT_DUPLICATE {Marked not a duplicate} CORRECTED {Record corrected} REQUEST_CORRECTION {Correction requested} APPROVE_CORRECTION {Correction approved} REJECT_CORRECTION {Correction rejected} READ {Viewed} ASSIGN {Assigned} UNASSIGN {Unassigned} UPDATE {Updated} other {Unknown}}}}","{status, select, Requested {En attente de validation externe} other {{action, select, CREATE {Déclaration commencée} NOTIFY {Envoyé incomplet} VALIDATE {Envoyé pour approbation} DRAFT {Brouillon} DECLARE {Envoyé pour révision} REGISTER {Enregistré} PRINT_CERTIFICATE {Certifié} REJECT {Rejeté} ARCHIVE {Archivé} DUPLICATE_DETECTED {Marqué comme doublon} MARKED_AS_DUPLICATE {Marqué comme doublon} MARK_AS_NOT_DUPLICATE {Marqué comme non en doublon} CORRECTED {Enregistrement corrigé} REQUEST_CORRECTION {Correction demandée} APPROVE_CORRECTION {Correction approuvée} REJECT_CORRECTION {Correction refusée} READ {Consulté} ASSIGN {Attribué} UNASSIGN {Désattribué} UPDATE {Mis à jour} other {Inconnu}}}}"
1117+
events.history.status,Events status history,"{status, select, Requested {Waiting for external validation} other {{action, select, CREATE {Declaration started} NOTIFY {Notified} VALIDATE {Sent for approval} DRAFT {Draft} DECLARE {Sent for review} REGISTER {Registered} PRINT_CERTIFICATE {Certified} REJECT {Rejected} ARCHIVE {Archived} DUPLICATE_DETECTED {Flagged as potential duplicate} MARKED_AS_DUPLICATE {Marked as a duplicate} MARK_AS_NOT_DUPLICATE {Marked not a duplicate} CORRECTED {Record corrected} REQUEST_CORRECTION {Correction requested} APPROVE_CORRECTION {Correction approved} REJECT_CORRECTION {Correction rejected} READ {Viewed} ASSIGN {Assigned} UNASSIGN {Unassigned} UPDATE {Updated} other {Unknown}}}}","{status, select, Requested {En attente de validation externe} other {{action, select, CREATE {Déclaration commencée} NOTIFY {Envoyé incomplet} VALIDATE {Envoyé pour approbation} DRAFT {Brouillon} DECLARE {Envoyé pour révision} REGISTER {Enregistré} PRINT_CERTIFICATE {Certifié} REJECT {Rejeté} ARCHIVE {Archivé} DUPLICATE_DETECTED {Marqué comme doublon} MARKED_AS_DUPLICATE {Marqué comme doublon} MARK_AS_NOT_DUPLICATE {Marqué comme non en doublon} CORRECTED {Enregistrement corrigé} REQUEST_CORRECTION {Correction demandée} APPROVE_CORRECTION {Correction approuvée} REJECT_CORRECTION {Correction refusée} READ {Consulté} ASSIGN {Attribué} UNASSIGN {Désattribué} UPDATE {Mis à jour} other {Inconnu}}}}"
11171118
events.outbox.processingAction,Message in outbox when processing action,"{action, select, DECLARE {Sending} REGISTER {Registering} VALIDATE {Sending for approval} NOTIFY {Sending} REJECT {Sending for updates} ARCHIVE {Archiving} PRINT_CERTIFICATE {Certifying} REQUEST_CORRECTION {Requesting correction} APPROVE_CORRECTION {Approving correction} REJECT_CORRECTION {Rejecting correction} ASSIGN {Assigning} UNASSIGN {Unassigning} other {processing action}}","{action, select, DECLARE {Envoi} REGISTER {Enregistrement} VALIDATE {Envoi pour approbation} NOTIFY {Envoi} REJECT {Envoi pour mise à jour} ARCHIVE {Archivage} PRINT_CERTIFICATE {Certification} REQUEST_CORRECTION {Demande de correction} APPROVE_CORRECTION {Approbation de la correction} REJECT_CORRECTION {Rejet de la correction} ASSIGN {Attribution} UNASSIGN {Désattribution} other {action en cours}}"
11181119
events.outbox.waitingForAction,Message in outbox when waiting for action,"Waiting to {action, select, DECLARE {send} CREATE {send} REGISTER {register} VALIDATE {send for approval} NOTIFY {send} REJECT {send for updates} ARCHIVE {archive} PRINT_CERTIFICATE {certify} REQUEST_CORRECTION {request correction} APPROVE_CORRECTION {approve correction} REJECT_CORRECTION {reject correction} ASSIGN {assign} UNASSIGN {unassign} other {action}}","En attente de {action, select, DECLARE {l'envoi} CREATE {l'envoi} REGISTER {l'enregistrement} VALIDATE {l'envoi pour approbation} NOTIFY {l'envoi} REJECT {l'envoi pour mise à jour} ARCHIVE {l'archivage} PRINT_CERTIFICATE {la certification} REQUEST_CORRECTION {la demande de correction} APPROVE_CORRECTION {l'approbation de la correction} REJECT_CORRECTION {le rejet de la correction} ASSIGN {l'attribution} UNASSIGN {la désattribution} other {l'action}}"
11191120
events.status,Dynamic event status,"{status, select, OUTBOX {Syncing..} CREATED {Draft} VALIDATED {Validated} DRAFT {Draft} DECLARED {Declared} REGISTERED {Registered} CERTIFIED {Certified} REJECTED {Rejected} ARCHIVED {Archived} MARKED_AS_DUPLICATE {Marked as a duplicate} MARK_AS_NOT_DUPLICATE {Marked not a duplicate} NOTIFIED {In progress} other {Unknown}}","{status, select, OUTBOX {Synchronisation..} CREATED {Brouillon} VALIDATED {Validé} DRAFT {Brouillon} DECLARED {Déclaré} REGISTERED {Enregistré} CERTIFIED {Certifié} REJECTED {Nécessite une mise à jour} ARCHIVED {Archivé} MARKED_AS_DUPLICATE {Marqué comme doublon} MARK_AS_NOT_DUPLICATE {Marqué comme non en doublon} NOTIFIED {Notifié} other {Inconnu}}"

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,10 @@
834834
dependencies:
835835
"@octokit/openapi-types" "^18.0.0"
836836

837-
"@opencrvs/[email protected].d3d43c3":
838-
version "1.9.0-rc.d3d43c3"
839-
resolved "https://registry.yarnpkg.com/@opencrvs/toolkit/-/toolkit-1.9.0-rc.d3d43c3.tgz#f78a25338ec6305216009472b2ac06f150717a0b"
840-
integrity sha512-wqVrQLevWZ7RzrZKtZHFAeWZQDszV5cPH3AIMs8V2Yx6kdFS/xTXzwUVbHZWvi+hX/8uw4uwHPadgqT0nsqHyA==
837+
"@opencrvs/[email protected].d748ac1":
838+
version "1.9.0-rc.d748ac1"
839+
resolved "https://registry.yarnpkg.com/@opencrvs/toolkit/-/toolkit-1.9.0-rc.d748ac1.tgz#7f082546ebcf136aff204e50f2fcfbc86087c1c8"
840+
integrity sha512-jrOHw/G3Ikm9SckvgC4J0bceoyxiIVflzeyiX8BJEqrj+rzzzMx+UojpAzr5uJglbxXTVOkZ4UFvLf63MovEGw==
841841
dependencies:
842842
"@trpc/client" "11.4.3"
843843
"@trpc/server" "11.4.3"

0 commit comments

Comments
 (0)