2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-08-01 18:27:41 +00:00
|
|
|
class TablesArrangementsController < ApplicationController
|
|
|
|
def index
|
2024-11-03 08:44:31 +01:00
|
|
|
render json: TablesArrangement.all.order(discomfort: :asc).limit(3).as_json(only: %i[id name discomfort])
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2024-11-03 14:41:09 +01:00
|
|
|
Seat.joins(guest: :group)
|
|
|
|
.where(tables_arrangement_id: params[:id])
|
2024-11-03 14:48:49 +01:00
|
|
|
.order('guests.group_id')
|
2024-11-03 14:41:09 +01:00
|
|
|
.pluck(
|
|
|
|
:table_number,
|
2024-11-11 07:43:42 +01:00
|
|
|
'guests.name',
|
|
|
|
'guests.id',
|
2024-11-03 14:41:09 +01:00
|
|
|
'groups.color'
|
|
|
|
)
|
2024-11-02 11:23:00 +01:00
|
|
|
.group_by(&:first)
|
2024-11-03 14:41:09 +01:00
|
|
|
.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 }
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
end
|