Manuel Bustillo 91bbae1c63
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 59s
Add copyright notice / copyright_notice (pull_request) Successful in 2m21s
Run unit tests / unit_tests (pull_request) Successful in 3m2s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 25m17s
Add copyright notice
2025-01-13 20:38:47 +00:00

59 lines
1.3 KiB
Ruby

# Copyright (C) 2024 Manuel Bustillo
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
# frozen_string_literal: true
# == Schema Information
#
# Table name: guests
#
# id :uuid not null, primary key
# name :string
# phone :string
# status :integer default("considered")
# created_at :datetime not null
# updated_at :datetime not null
# group_id :uuid
# wedding_id :uuid not null
#
# Indexes
#
# index_guests_on_group_id (group_id)
# index_guests_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (group_id => groups.id)
# fk_rails_... (wedding_id => weddings.id)
#
class Guest < ApplicationRecord
acts_as_tenant :wedding
belongs_to :group, optional: true
enum :status, {
considered: 0,
invited: 10,
confirmed: 20,
declined: 30,
tentative: 40
}, validate: true
validates :name, presence: true
scope :potential, -> { where.not(status: %i[declined considered]) }
after_destroy :recalculate_simulations
after_save :recalculate_simulations, if: :saved_change_to_status?
has_many :seats, dependent: :delete_all
private
def recalculate_simulations
TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) })
end
end