import { IRouter } from 'kibana/server' ; import { schema } from '@kbn/config-schema' ; import { ILicenseState , AlertTypeDisabledError } from '../lib' ; import { MuteOptions } from '../rules_client' ; import { RewriteRequestCase , verifyAccessAndContext } from './lib' ; import { AlertingRequestHandlerContext , BASE_ALERTING_API_PATH } from '../types' ; const paramSchema = schema . object ( { rule_id : schema . string ( ) , alert_id : schema . string ( ) , } ) ; const rewriteParamsReq = ( { rule_id : alertId , alert_id : alertInstanceId , } ) => ( { alertId , alertInstanceId , } ) ; export const unmuteAlertRoute = ( router , licenseState ) => { router . post ( { path : `${ BASE_ALERTING_API_PATH }/rule/{rule_id}/alert/{alert_id}/_unmute` , validate : { params : paramSchema , } , } , router . handleLegacyErrors ( verifyAccessAndContext ( licenseState , async function ( context , req , res ) { const rulesClient = context . alerting . getRulesClient ( ) ; const params = rewriteParamsReq ( req . params ) ; try { await rulesClient . unmuteInstance ( params ) ; return res . noContent ( ) ; } catch ( e ) { if ( e instanceof AlertTypeDisabledError ) { return e . sendResponse ( res ) ; } throw e ; } } ) ) ) ; } ;