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

Tidy up code

- Reword changelog
parent d4ba84a2
...@@ -13,20 +13,20 @@ module Mutations ...@@ -13,20 +13,20 @@ module Mutations
alert = authorized_find!(project_path: args[:project_path], iid: args[:iid]) alert = authorized_find!(project_path: args[:project_path], iid: args[:iid])
result = update_status(alert, args[:status]) result = update_status(alert, args[:status])
prepare_response(result) prepare_response(result)
end end
private private
def update_status(alert, status) def update_status(alert, status)
service = ::AlertManagement::UpdateAlertStatusService.new(alert, status) ::AlertManagement::UpdateAlertStatusService.new(alert, status).execute
service.execute
end end
def prepare_response(result) def prepare_response(result)
{ {
alert: result.payload[:alert], alert: result.payload[:alert],
errors: result.error? ? [result.message].compact : [] errors: result.error? ? [result.message] : []
} }
end end
end end
......
...@@ -8,20 +8,27 @@ module AlertManagement ...@@ -8,20 +8,27 @@ module AlertManagement
end end
def execute 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 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 end
private private
def error_response(message) attr_reader :alert, :status
ServiceResponse.error(payload: { alert: alert }, message: message)
def success
ServiceResponse.success(payload: { alert: alert })
end end
attr_reader :alert, :status def error(message)
ServiceResponse.error(payload: { alert: alert }, message: message)
end
end end
end end
--- ---
title: Add mutation for AlertManagementAlert status title: Add mutation for AlertManagement's Alert status
merge_request: 30576 merge_request: 30576
author: author:
type: added 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