1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/services/training_service.rb

24 lines
789 B
Ruby

# frozen_string_literal: true
# Provides methods for Trainings
class TrainingService
def self.list(filters)
trainings = Training.includes(:training_image, :plans, :machines)
if filters[:disabled].present?
state = filters[:disabled] == 'false' ? [nil, false] : true
trainings = trainings.where(disabled: state)
end
if filters[:public_page].present?
state = filters[:public_page] == 'false' ? [nil, false] : true
trainings = trainings.where(public_page: state)
end
if filters[:requested_attributes].try(:include?, 'availabilities')
trainings = trainings.includes(availabilities: [slots: [reservation: [user: %i[profile trainings]]]])
.order('availabilities.start_at DESC')
end
trainings
end
end