Skip to content

Commit 887e443

Browse files
authored
feat: serve tennis-club-membership-event as example custom-event (#330)
1 parent 78a2071 commit 887e443

File tree

7 files changed

+178
-2
lines changed

7 files changed

+178
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@hapi/boom": "^9.1.1",
6565
"@hapi/hapi": "^20.0.1",
6666
"@hapi/inert": "^6.0.3",
67+
"@opencrvs/toolkit": "^0.0.5",
6768
"@types/chalk": "^2.2.0",
6869
"@types/csv2json": "^1.4.0",
6970
"@types/fhir": "^0.0.30",

src/api/custom-event/handler.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* OpenCRVS is also distributed under the terms of the Civil Registration
7+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
8+
*
9+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
10+
*/
11+
import * as Hapi from '@hapi/hapi'
12+
import { tennisClubMembershipEvent } from '@countryconfig/form/tennis-club-membership'
13+
14+
export const customEventHandler = (
15+
request: Hapi.Request,
16+
h: Hapi.ResponseToolkit
17+
) => {
18+
return h.response([tennisClubMembershipEvent]).code(200)
19+
}

src/api/event-registration/handler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
confirmRegistration
1717
// rejectRegistration
1818
} from '@countryconfig/utils/gateway-api'
19+
import { tennisClubMembershipEvent } from '@countryconfig/form/tennis-club-membership'
1920

2021
export async function eventRegistrationHandler(
2122
request: Hapi.Request,
@@ -67,3 +68,10 @@ export async function eventRegistrationHandler(
6768

6869
return h.response().code(202)
6970
}
71+
72+
export const tennisClubMembershipEventHandler = (
73+
request: Hapi.Request,
74+
h: Hapi.ResponseToolkit
75+
) => {
76+
return h.response(tennisClubMembershipEvent).code(200)
77+
}

src/form/tennis-club-membership.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* OpenCRVS is also distributed under the terms of the Civil Registration
7+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
8+
*
9+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
10+
*/
11+
12+
import { defineConfig } from '@opencrvs/toolkit/events'
13+
14+
export const tennisClubMembershipEvent = defineConfig({
15+
id: 'TENNIS_CLUB_MEMBERSHIP',
16+
label: {
17+
defaultMessage: 'Tennis club membership application',
18+
description: 'This is what this event is referred as in the system',
19+
id: 'event.tennis-club-membership.label'
20+
},
21+
actions: [
22+
{
23+
type: 'DECLARE',
24+
label: {
25+
defaultMessage: 'Send an application',
26+
description:
27+
'This is shown as the action name anywhere the user can trigger the action from',
28+
id: 'event.tennis-club-membership.action.declare.label'
29+
},
30+
forms: [
31+
{
32+
label: {
33+
id: 'event.tennis-club-membership.action.declare.form.label',
34+
defaultMessage: 'Tennis club membership application',
35+
description: 'This is what this form is referred as in the system'
36+
},
37+
active: true,
38+
version: {
39+
id: '1.0.0',
40+
label: {
41+
id: 'event.tennis-club-membership.action.declare.form.version.1',
42+
defaultMessage: 'Version 1',
43+
description: 'This is the first version of the form'
44+
}
45+
},
46+
pages: [
47+
{
48+
id: 'applicant',
49+
title: {
50+
id: 'event.tennis-club-membership.action.declare.form.section.who.title',
51+
defaultMessage: 'Who is applying for the membership?',
52+
description: 'This is the title of the section'
53+
},
54+
fields: [
55+
{
56+
id: 'applicant.firstname',
57+
type: 'TEXT',
58+
required: true,
59+
label: {
60+
defaultMessage: "Applicant's first name",
61+
description: 'This is the label for the field',
62+
id: 'event.tennis-club-membership.action.declare.form.section.who.field.firstname.label'
63+
}
64+
},
65+
{
66+
id: 'applicant.surname',
67+
type: 'TEXT',
68+
required: true,
69+
label: {
70+
defaultMessage: "Applicant's surname",
71+
description: 'This is the label for the field',
72+
id: 'event.tennis-club-membership.action.declare.form.section.who.field.surname.label'
73+
}
74+
},
75+
{
76+
id: 'applicant.dob',
77+
type: 'DATE',
78+
required: true,
79+
label: {
80+
defaultMessage: "Applicant's date of birth",
81+
description: 'This is the label for the field',
82+
id: 'event.tennis-club-membership.action.declare.form.section.who.field.dob.label'
83+
}
84+
}
85+
]
86+
},
87+
{
88+
id: 'recommender',
89+
title: {
90+
id: 'event.tennis-club-membership.action.declare.form.section.recommender.title',
91+
defaultMessage: 'Who is recommending the applicant?',
92+
description: 'This is the title of the section'
93+
},
94+
fields: [
95+
{
96+
id: 'recommender.firstname',
97+
type: 'TEXT',
98+
required: true,
99+
label: {
100+
defaultMessage: "Recommender's first name",
101+
description: 'This is the label for the field',
102+
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.firstname.label'
103+
}
104+
},
105+
{
106+
id: 'recommender.surname',
107+
type: 'TEXT',
108+
required: true,
109+
label: {
110+
defaultMessage: "Recommender's surname",
111+
description: 'This is the label for the field',
112+
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.surname.label'
113+
}
114+
},
115+
{
116+
id: 'recommender.id',
117+
type: 'TEXT',
118+
required: true,
119+
label: {
120+
defaultMessage: "Recommender's membership ID",
121+
description: 'This is the label for the field',
122+
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.id.label'
123+
}
124+
}
125+
]
126+
}
127+
]
128+
}
129+
]
130+
}
131+
]
132+
})

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { dashboardQueriesHandler } from './api/dashboards/handler'
6262
import { fontsHandler } from './api/fonts/handler'
6363
import { certificateConfigurationHandler } from './api/certificate-configuration/handler'
6464
import { recordNotificationHandler } from './api/record-notification/handler'
65+
import { customEventHandler } from '@countryconfig/api/custom-event/handler'
6566

6667
export interface ITokenPayload {
6768
sub: string
@@ -545,6 +546,16 @@ export async function createServer() {
545546
}
546547
})
547548

549+
server.route({
550+
method: 'GET',
551+
path: '/events',
552+
handler: customEventHandler,
553+
options: {
554+
tags: ['api', 'custom-event'],
555+
description: 'Serves custom events'
556+
}
557+
})
558+
548559
server.ext({
549560
type: 'onRequest',
550561
method(request: Hapi.Request & { sentryScope?: any }, h) {

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"@countryconfig/*": ["./*"]
66
},
77
"target": "es6",
8-
"module": "commonjs",
8+
"module": "Node16",
99
"outDir": "build/dist",
1010
"sourceMap": true,
11-
"moduleResolution": "node",
11+
"moduleResolution": "node16",
1212
"rootDir": ".",
1313
"lib": ["esnext.asynciterable", "es6", "es2017", "es2019", "es2022"],
1414
"forceConsistentCasingInFileNames": true,

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,11 @@
790790
dependencies:
791791
"@octokit/openapi-types" "^18.0.0"
792792

793+
"@opencrvs/toolkit@^0.0.5":
794+
version "0.0.5"
795+
resolved "https://registry.yarnpkg.com/@opencrvs/toolkit/-/toolkit-0.0.5.tgz#dbd3395b561c1eb3527b8cfc28b6e1dd301671f3"
796+
integrity sha512-Ex45aFUJ1iQwpYGMHhxVbhpuQFqVlmdSkNXz1phkM7KAzNtngL2KGIJCc6TFv4GKOHU/lLEfmGyrhIDCKlA7fQ==
797+
793798
794799
version "4.24.0"
795800
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.0.tgz#1661ff5ea9beb362795304cb916049aba7ac9c54"

0 commit comments

Comments
 (0)