Skip to content

Commit 9f05a4f

Browse files
authored
add handlers for receiving action notifications (#361)
1 parent 1ccc283 commit 9f05a4f

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/api/custom-event/handler.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,30 @@
1010
*/
1111
import * as Hapi from '@hapi/hapi'
1212
import { tennisClubMembershipEvent } from '@countryconfig/form/tennis-club-membership'
13+
import { EventDocument } from '@opencrvs/toolkit/events'
1314

14-
export const customEventHandler = (
15+
export function getCustomEventsHandler(
1516
request: Hapi.Request,
1617
h: Hapi.ResponseToolkit
17-
) => {
18+
) {
1819
return h.response([tennisClubMembershipEvent]).code(200)
1920
}
21+
22+
export function onRegisterHandler(
23+
request: Hapi.Request,
24+
h: Hapi.ResponseToolkit
25+
) {
26+
const event = EventDocument.parse(request.payload)
27+
console.log(event)
28+
return h.response().code(200)
29+
}
30+
31+
export function onAnyActionHandler(
32+
request: Hapi.Request,
33+
h: Hapi.ResponseToolkit
34+
) {
35+
console.log(request.params.event, request.params.action)
36+
const event = EventDocument.parse(request.payload)
37+
console.log(event)
38+
return h.response().code(200)
39+
}

src/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ import { trackingIDHandler } from './api/tracking-id/handler'
6161
import { dashboardQueriesHandler } from './api/dashboards/handler'
6262
import { fontsHandler } from './api/fonts/handler'
6363
import { recordNotificationHandler } from './api/record-notification/handler'
64-
import { customEventHandler } from '@countryconfig/api/custom-event/handler'
64+
import {
65+
getCustomEventsHandler,
66+
onAnyActionHandler,
67+
onRegisterHandler
68+
} from '@countryconfig/api/custom-event/handler'
6569

6670
export interface ITokenPayload {
6771
sub: string
@@ -548,13 +552,33 @@ export async function createServer() {
548552
server.route({
549553
method: 'GET',
550554
path: '/events',
551-
handler: customEventHandler,
555+
handler: getCustomEventsHandler,
552556
options: {
553557
tags: ['api', 'custom-event'],
554558
description: 'Serves custom events'
555559
}
556560
})
557561

562+
server.route({
563+
method: 'POST',
564+
path: '/events/TENNIS_CLUB_MEMBERSHIP/actions/register',
565+
handler: onRegisterHandler,
566+
options: {
567+
tags: ['api', 'custom-event'],
568+
description: 'Receives notifications on event actions'
569+
}
570+
})
571+
572+
server.route({
573+
method: 'POST',
574+
path: '/events/{event}/actions/{action}',
575+
handler: onAnyActionHandler,
576+
options: {
577+
tags: ['api', 'custom-event'],
578+
description: 'Receives notifications on event actions'
579+
}
580+
})
581+
558582
server.ext({
559583
type: 'onRequest',
560584
method(request: Hapi.Request & { sentryScope?: any }, h) {

0 commit comments

Comments
 (0)