Refine arrangement detail endpoint
All checks were successful
Add copyright notice / copyright_notice (pull_request) Successful in 1m21s
Run unit tests / unit_tests (pull_request) Successful in 2m17s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 25m8s

This commit is contained in:
Manuel Bustillo 2024-11-02 11:23:00 +01:00
parent d4c1e5aab0
commit 612cb9a789

View File

@ -7,8 +7,10 @@ class TablesArrangementsController < ApplicationController
def show
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) }
.pluck(:table_number, Arel.sql("guests.first_name || ' ' || guests.last_name "), 'guests.id')
.group_by(&:first)
.transform_values { |table| table.map { |(_, name, id)| { id:, name: } } }
.map { |number, guests| { number:, guests: } }
.then { |result| render json: result }
end
end