import express from 'express' ; import { PipelineSuccessEvent , isValidPipelineSuccessEvent , } from '../pipelineEvent' ; import { TriggerEventHandler } from '../triggerEventHandler' ; import { asyncHandler } from './utils' ; export class NotificationExecutionEndpoint { constructor ( private readonly triggerEventHandler ) { } registerRoutes = ( app ) : void => { app . post ( '/trigger' , asyncHandler ( this . triggerNotification ) ) ; } ; triggerNotification = async ( req , res ) : Promise < void > => { if ( ! isValidPipelineSuccessEvent ( req . body ) ) { res . status ( 400 ) . send ( 'Malformed notification trigger request.' ) ; return ; } const triggerEvent = req . body ; await this . triggerEventHandler . handleEvent ( triggerEvent ) ; res . status ( 200 ) . send ( `Successfully sent all notifications for pipeline ${ triggerEvent . pipelineId }` ) ; } ; }