diff --git a/src/api/custom-event/handler.ts b/src/api/custom-event/handler.ts index ebc656b26..70ae575f6 100644 --- a/src/api/custom-event/handler.ts +++ b/src/api/custom-event/handler.ts @@ -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) +} diff --git a/src/index.ts b/src/index.ts index 1b3fedf1a..de3527e12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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) {