wedding-planner/app/controllers/tables_arrangements_controller.rb

23 lines
747 B
Ruby
Raw Permalink Normal View History

2024-10-27 21:42:45 +00:00
# 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: :group)
.where(tables_arrangement_id: params[:id])
.order('guests.group_id')
.pluck(
:table_number,
Arel.sql("guests.first_name || ' ' || guests.last_name "), 'guests.id',
'groups.color'
)
2024-11-02 11:23:00 +01:00
.group_by(&:first)
.transform_values { |table| table.map { |(_, name, id, color)| { id:, name:, color: } } }
2024-11-02 11:23:00 +01:00
.map { |number, guests| { number:, guests: } }
2024-11-02 10:40:43 +01:00
.then { |result| render json: result }
end
end