Skip to content

Commit

Permalink
TOP-203 add in new serializer for database
Browse files Browse the repository at this point in the history
  • Loading branch information
apricot13 committed Jun 20, 2024
1 parent 02a8090 commit 8760d69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/serializers/indexed_services_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class IndexedServicesSerializer < ActiveModel::Serializer
object.locations.where(visible: true)
end

has_many :service_at_locations do
object.service_at_locations.includes(:location).where(locations: { visible: true })
end

# uses a modified version of the RegularScheduleSerializer that includes regular_schedules to prevent loops
has_many :regular_schedules, serializer: RegularScheduleServiceAtLocationSerializer

has_many :contacts do
object.contacts.where(visible: true)
end
Expand All @@ -47,7 +54,6 @@ class IndexedServicesSerializer < ActiveModel::Serializer
belongs_to :organisation

has_many :taxonomies
has_many :regular_schedules
has_many :cost_options
has_many :links
has_many :send_needs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include RegularScheduleHelper

class RegularScheduleServiceAtLocationSerializer < RegularScheduleSerializer
belongs_to :service_at_location, serializer: ServiceAtLocationSerializer
end
9 changes: 9 additions & 0 deletions app/serializers/service_at_location_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class ServiceAtLocationSerializer < ActiveModel::Serializer
attribute :id
attribute :service_id
attribute :location_id
belongs_to :location, serializer: LocationSerializer
has_many :regular_schedules, serializer: RegularScheduleSerializer, key: :regular_schedule
# @TODO add holiday_schedule here (holidayScheduleCollection)
end

0 comments on commit 8760d69

Please sign in to comment.