Skip to content

Commit

Permalink
add handlers for receiving action notifications (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa authored Jan 14, 2025
1 parent 1ccc283 commit 9f05a4f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/api/custom-event/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@
*/
import * as Hapi from '@hapi/hapi'
import { tennisClubMembershipEvent } from '@countryconfig/form/tennis-club-membership'
import { EventDocument } from '@opencrvs/toolkit/events'

export const customEventHandler = (
export function getCustomEventsHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) => {
) {
return h.response([tennisClubMembershipEvent]).code(200)
}

export function onRegisterHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) {
const event = EventDocument.parse(request.payload)
console.log(event)
return h.response().code(200)
}

export function onAnyActionHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) {
console.log(request.params.event, request.params.action)
const event = EventDocument.parse(request.payload)
console.log(event)
return h.response().code(200)
}
28 changes: 26 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ import { trackingIDHandler } from './api/tracking-id/handler'
import { dashboardQueriesHandler } from './api/dashboards/handler'
import { fontsHandler } from './api/fonts/handler'
import { recordNotificationHandler } from './api/record-notification/handler'
import { customEventHandler } from '@countryconfig/api/custom-event/handler'
import {
getCustomEventsHandler,
onAnyActionHandler,
onRegisterHandler
} from '@countryconfig/api/custom-event/handler'

export interface ITokenPayload {
sub: string
Expand Down Expand Up @@ -548,13 +552,33 @@ export async function createServer() {
server.route({
method: 'GET',
path: '/events',
handler: customEventHandler,
handler: getCustomEventsHandler,
options: {
tags: ['api', 'custom-event'],
description: 'Serves custom events'
}
})

server.route({
method: 'POST',
path: '/events/TENNIS_CLUB_MEMBERSHIP/actions/register',
handler: onRegisterHandler,
options: {
tags: ['api', 'custom-event'],
description: 'Receives notifications on event actions'
}
})

server.route({
method: 'POST',
path: '/events/{event}/actions/{action}',
handler: onAnyActionHandler,
options: {
tags: ['api', 'custom-event'],
description: 'Receives notifications on event actions'
}
})

server.ext({
type: 'onRequest',
method(request: Hapi.Request & { sentryScope?: any }, h) {
Expand Down

0 comments on commit 9f05a4f

Please sign in to comment.