Rewrite table arrangements endpoints

This commit is contained in:
Manuel Bustillo 2024-11-02 10:40:43 +01:00
parent 83fbac76f6
commit d4c1e5aab0
2 changed files with 6 additions and 2 deletions

View File

@ -2,10 +2,13 @@
class TablesArrangementsController < ApplicationController
def index
render json: TablesArrangement.all.order(discomfort: :asc).limit(10)
render json: TablesArrangement.all.order(discomfort: :asc).limit(10).as_json(only: %i[id discomfort])
end
def show
render json: TablesArrangement.find(params[:id])
Seat.joins(:guest).where(tables_arrangement_id: params[:id])
.pluck(:table_number, Arel.sql("guests.first_name || ' ' ||guests.last_name "))
.group_by(&:first).transform_values { |table| table.map(&:last) }
.then { |result| render json: result }
end
end

View File

@ -2,4 +2,5 @@
class TablesArrangement < ApplicationRecord
has_many :seats
has_many :guests, through: :seats
end