2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ResourceEvents
|
2020-10-24 23:57:45 +05:30
|
|
|
class ChangeMilestoneService < BaseChangeTimeboxService
|
|
|
|
attr_reader :milestone, :old_milestone
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def initialize(resource, user, created_at: Time.current, old_milestone:)
|
2020-10-24 23:57:45 +05:30
|
|
|
super(resource, user, created_at: created_at)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
@milestone = resource&.milestone
|
2020-05-24 23:13:21 +05:30
|
|
|
@old_milestone = old_milestone
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
private
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def create_event
|
|
|
|
ResourceMilestoneEvent.create(build_resource_args)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def build_resource_args
|
|
|
|
action = milestone.blank? ? :remove : :add
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
super.merge({
|
2020-04-08 14:13:33 +05:30
|
|
|
state: ResourceMilestoneEvent.states[resource.state],
|
2020-10-24 23:57:45 +05:30
|
|
|
action: ResourceTimeboxEvent.actions[action],
|
|
|
|
milestone_id: milestone.blank? ? old_milestone&.id : milestone&.id
|
|
|
|
})
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|