2019-11-13 12:13:22 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-11-18 17:29:51 +01:00
|
|
|
# Provides helper methods to create an Availability with multiple occurrences
|
2019-11-13 12:13:22 +01:00
|
|
|
class Availabilities::CreateAvailabilitiesService
|
2019-11-18 11:50:20 +01:00
|
|
|
def create(availability, occurrences = [])
|
2019-11-13 12:13:22 +01:00
|
|
|
availability.update_attributes(occurrence_id: availability.id)
|
|
|
|
|
|
|
|
occurrences.each do |o|
|
2019-11-18 11:50:20 +01:00
|
|
|
next if availability.start_at == o[:start_at] && availability.end_at == o[:end_at]
|
|
|
|
|
2019-11-13 12:13:22 +01:00
|
|
|
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,
|
2019-11-25 10:30:03 +01:00
|
|
|
tag_ids: availability.tag_ids,
|
2020-05-25 11:02:49 +02:00
|
|
|
nb_total_places: availability.nb_total_places,
|
|
|
|
slot_duration: availability.slot_duration
|
2019-11-13 12:13:22 +01:00
|
|
|
).save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|