mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-02 13:24:20 +01:00
bbd613f2a5
also: copy nb_total_places to n+1 instances when creating recurrent availabilities
29 lines
1014 B
Ruby
29 lines
1014 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Provides helper methods to create an Availability with multiple occurrences
|
|
class Availabilities::CreateAvailabilitiesService
|
|
def create(availability, occurrences = [])
|
|
availability.update_attributes(occurrence_id: availability.id)
|
|
|
|
occurrences.each do |o|
|
|
next if availability.start_at == o[:start_at] && availability.end_at == o[:end_at]
|
|
|
|
Availability.new(
|
|
start_at: o[:start_at],
|
|
end_at: o[:end_at],
|
|
available_type: availability.available_type,
|
|
is_recurrent: availability.is_recurrent,
|
|
period: availability.period,
|
|
nb_periods: availability.nb_periods,
|
|
end_date: availability.end_date,
|
|
occurrence_id: availability.occurrence_id,
|
|
machine_ids: availability.machine_ids,
|
|
training_ids: availability.training_ids,
|
|
space_ids: availability.space_ids,
|
|
tag_ids: availability.tag_ids,
|
|
nb_total_places: availability.nb_total_places
|
|
).save!
|
|
end
|
|
end
|
|
end
|