import { wrapError } from '../client/error_wrapper' ; import { RouteInitialization } from '../types' ; import { jobAuditMessagesProvider } from '../models/job_audit_messages' ; import { jobAuditMessagesQuerySchema , jobAuditMessagesJobIdSchema , clearJobAuditMessagesBodySchema , } from './schemas/job_audit_messages_schema' ; /**
 * Routes for job audit message routes
 */ export function jobAuditMessagesRoutes ( { router , routeGuard } ) { apiGroup api apiName apiDescription apiSchema apiSchema router . get ( { path : '/api/ml/job_audit_messages/messages/{jobId}' , validate : { params : jobAuditMessagesJobIdSchema , query : jobAuditMessagesQuerySchema , } , options : { tags : [ 'access:ml:canGetJobs' ] , } , } , routeGuard . fullLicenseAPIGuard ( async ( { client , mlClient , request , response , jobSavedObjectService } ) => { try { const { getJobAuditMessages } = jobAuditMessagesProvider ( client , mlClient ) ; const { jobId } = request . params ; const { from , start , end } = request . query ; const resp = await getJobAuditMessages ( jobSavedObjectService , { jobId , from , start , end , } ) ; return response . ok ( { body : resp , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; apiGroup api apiName apiDescription apiSchema router . get ( { path : '/api/ml/job_audit_messages/messages' , validate : { query : jobAuditMessagesQuerySchema , } , options : { tags : [ 'access:ml:canGetJobs' ] , } , } , routeGuard . fullLicenseAPIGuard ( async ( { client , mlClient , request , response , jobSavedObjectService } ) => { try { const { getJobAuditMessages } = jobAuditMessagesProvider ( client , mlClient ) ; const { from } = request . query ; const resp = await getJobAuditMessages ( jobSavedObjectService , { from } ) ; return response . ok ( { body : resp , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; apiGroup api apiName apiDescription apiSchema router . put ( { path : '/api/ml/job_audit_messages/clear_messages' , validate : { body : clearJobAuditMessagesBodySchema , } , options : { tags : [ 'access:ml:canCreateJob' ] , } , } , routeGuard . fullLicenseAPIGuard ( async ( { client , mlClient , request , response , jobSavedObjectService } ) => { try { const { clearJobAuditMessages } = jobAuditMessagesProvider ( client , mlClient ) ; const { jobId , notificationIndices } = request . body ; const resp = await clearJobAuditMessages ( jobId , notificationIndices ) ; return response . ok ( { body : resp , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; }