wedding-planner/app/controllers/tables_arrangements_controller.rb
Manuel Bustillo 066fdea504
Some checks failed
Add copyright notice / copyright_notice (pull_request) Successful in 3m52s
Run unit tests / unit_tests (pull_request) Successful in 7m40s
Build Nginx-based docker image / build-static-assets (pull_request) Failing after 1h10m25s
Assign a name to every tables arrangement
2024-11-03 08:44:31 +01:00

17 lines
626 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
class TablesArrangementsController < ApplicationController
def index
render json: TablesArrangement.all.order(discomfort: :asc).limit(3).as_json(only: %i[id name discomfort])
end
def show
Seat.joins(:guest).where(tables_arrangement_id: params[:id])
.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