Define an endpoint with table simulation stats
Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 4m40s
Run unit tests / check-licenses (pull_request) Failing after 1m28s
Run unit tests / rubocop (pull_request) Failing after 1m38s
Run unit tests / unit_tests (pull_request) Failing after 2m35s
Run unit tests / build-static-assets (pull_request) Has been skipped
Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 4m40s
Run unit tests / check-licenses (pull_request) Failing after 1m28s
Run unit tests / rubocop (pull_request) Failing after 1m38s
Run unit tests / unit_tests (pull_request) Failing after 2m35s
Run unit tests / build-static-assets (pull_request) Has been skipped
This commit is contained in:
parent
db5b0809fa
commit
1e1b3f19fc
@ -4,17 +4,28 @@
|
|||||||
|
|
||||||
class TablesArrangementsController < ApplicationController
|
class TablesArrangementsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
current_digest = Tables::Distribution.digest(current_tenant)
|
query = TablesArrangement
|
||||||
|
.order(valid: :desc)
|
||||||
|
.order(discomfort: :asc)
|
||||||
|
.select(:id, :name, :discomfort, :status, :progress)
|
||||||
|
.select("digest = '#{current_digest}'::uuid OR discomfort IS NULL as valid")
|
||||||
|
.limit((params[:limit].presence&.to_i || 20).clamp(1..20))
|
||||||
|
|
||||||
render json: TablesArrangement
|
query = query.where(status: params[:status]) if params[:status].present?
|
||||||
.order(valid: :desc)
|
|
||||||
.order(discomfort: :asc)
|
render json: query
|
||||||
.select(:id, :name, :discomfort, :status, :progress)
|
|
||||||
.select("digest = '#{current_digest}'::uuid OR discomfort IS NULL as valid")
|
|
||||||
.limit(20)
|
|
||||||
.as_json(only: %i[id name discomfort valid status progress])
|
.as_json(only: %i[id name discomfort valid status progress])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stats
|
||||||
|
scope = TablesArrangement.where('digest = ?::uuid OR discomfort IS NULL', current_digest)
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
count: scope.group(:status).count,
|
||||||
|
in_progress: scope.where(status: :in_progress).limit(10).order(progress: :desc).pluck(:progress)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
Guest.joins(:seats, :group)
|
Guest.joins(:seats, :group)
|
||||||
.where(seats: { tables_arrangement_id: params[:id] })
|
.where(seats: { tables_arrangement_id: params[:id] })
|
||||||
@ -35,6 +46,10 @@ class TablesArrangementsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def current_digest
|
||||||
|
@current_digest ||= Tables::Distribution.digest(current_tenant)
|
||||||
|
end
|
||||||
|
|
||||||
def format(number:, guests:)
|
def format(number:, guests:)
|
||||||
{
|
{
|
||||||
number: number,
|
number: number,
|
||||||
|
|||||||
@ -40,7 +40,9 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
resource :website, only: [:show, :update]
|
resource :website, only: [:show, :update]
|
||||||
|
|
||||||
resources :tables_arrangements, only: %i[index show create]
|
resources :tables_arrangements, only: %i[index show create] do
|
||||||
|
get :stats, on: :collection
|
||||||
|
end
|
||||||
resources :summary, only: :index
|
resources :summary, only: :index
|
||||||
resources :invitations, only: %i[show index create update destroy] do
|
resources :invitations, only: %i[show index create update destroy] do
|
||||||
post :email, on: :collection
|
post :email, on: :collection
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user