Commit 3627c31d authored by Sean Arnold's avatar Sean Arnold

Tidy up code

- Reword changelog
parent d4ba84a2
......@@ -13,20 +13,20 @@ module Mutations
alert = authorized_find!(project_path: args[:project_path], iid: args[:iid])
result = update_status(alert, args[:status])
prepare_response(result)
end
private
def update_status(alert, status)
service = ::AlertManagement::UpdateAlertStatusService.new(alert, status)
service.execute
::AlertManagement::UpdateAlertStatusService.new(alert, status).execute
end
def prepare_response(result)
{
alert: result.payload[:alert],
errors: result.error? ? [result.message].compact : []
errors: result.error? ? [result.message] : []
}
end
end
......
......@@ -8,20 +8,27 @@ module AlertManagement
end
def execute
return error_response('Invalid status') unless AlertManagement::Alert.statuses.key?(status.to_s)
return error('Invalid status') unless AlertManagement::Alert.statuses.key?(status.to_s)
alert.status = status
return ServiceResponse.success(payload: { alert: alert }) if alert.save
error_response(alert.errors.full_messages.to_sentence)
if alert.save
success
else
error(alert.errors.full_messages.to_sentence)
end
end
private
def error_response(message)
ServiceResponse.error(payload: { alert: alert }, message: message)
attr_reader :alert, :status
def success
ServiceResponse.success(payload: { alert: alert })
end
attr_reader :alert, :status
def error(message)
ServiceResponse.error(payload: { alert: alert }, message: message)
end
end
end
---
title: Add mutation for AlertManagementAlert status
title: Add mutation for AlertManagement's Alert status
merge_request: 30576
author:
type: added
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment