import { RouteInitialization } from '../types' ; import { wrapError } from '../client/error_wrapper' ; import { mlAnomalyDetectionAlertPreviewRequest } from './schemas/alerting_schema' ; import type { SharedServices } from '../shared_services' ; export function alertingRoutes ( { router , routeGuard } , sharedServicesProviders ) { apiGroup api apiName apiDescription apiSchema router . post ( { path : '/api/ml/alerting/preview' , validate : { body : mlAnomalyDetectionAlertPreviewRequest , } , options : { tags : [ 'access:ml:canGetJobs' ] , } , } , routeGuard . fullLicenseAPIGuard ( async ( { mlClient , request , response , client , context } ) => { try { const alertingService = sharedServicesProviders . alertingServiceProvider ( context . core . savedObjects . client , request ) ; const result = await alertingService . preview ( request . body ) ; return response . ok ( { body : result , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; }