diff options
Diffstat (limited to 'app/services/incident_management/issuable_escalation_statuses/create_service.rb')
-rw-r--r-- | app/services/incident_management/issuable_escalation_statuses/create_service.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/services/incident_management/issuable_escalation_statuses/create_service.rb b/app/services/incident_management/issuable_escalation_statuses/create_service.rb new file mode 100644 index 00000000000..e28debf0fa3 --- /dev/null +++ b/app/services/incident_management/issuable_escalation_statuses/create_service.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module IncidentManagement + module IssuableEscalationStatuses + class CreateService < BaseService + def initialize(issue) + @issue = issue + @alert = issue.alert_management_alert + end + + def execute + escalation_status = ::IncidentManagement::IssuableEscalationStatus.new(issue: issue, **alert_params) + + if escalation_status.save + ServiceResponse.success(payload: { escalation_status: escalation_status }) + else + ServiceResponse.error(message: escalation_status.errors&.full_messages) + end + end + + private + + attr_reader :issue, :alert + + def alert_params + return {} unless alert + + { + status_event: alert.status_event_for(alert.status_name) + } + end + end + end +end + +IncidentManagement::IssuableEscalationStatuses::CreateService.prepend_mod |