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