2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-13 08:12:46 +00:00
|
|
|
# == 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
|
2024-12-08 11:30:38 +01:00
|
|
|
# group_id :uuid
|
2024-11-30 20:04:17 +01:00
|
|
|
# wedding_id :uuid not null
|
2024-11-13 08:12:46 +00:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2024-11-30 20:04:17 +01:00
|
|
|
# index_guests_on_group_id (group_id)
|
|
|
|
# index_guests_on_wedding_id (wedding_id)
|
2024-11-13 08:12:46 +00:00
|
|
|
#
|
|
|
|
# Foreign Keys
|
|
|
|
#
|
|
|
|
# fk_rails_... (group_id => groups.id)
|
2024-11-30 20:04:17 +01:00
|
|
|
# fk_rails_... (wedding_id => weddings.id)
|
2024-11-13 08:12:46 +00:00
|
|
|
#
|
2024-07-11 20:08:26 +02:00
|
|
|
class Guest < ApplicationRecord
|
2024-11-30 20:04:17 +01:00
|
|
|
acts_as_tenant :wedding
|
2024-12-08 13:10:49 +01:00
|
|
|
belongs_to :group, optional: true
|
2024-08-11 19:24:24 +02:00
|
|
|
|
2024-11-09 17:45:23 +01:00
|
|
|
enum :status, {
|
2024-08-11 19:24:24 +02:00
|
|
|
considered: 0,
|
|
|
|
invited: 10,
|
|
|
|
confirmed: 20,
|
2024-10-27 19:25:24 +01:00
|
|
|
declined: 30,
|
2024-11-03 09:15:48 +01:00
|
|
|
tentative: 40
|
2024-11-16 02:16:19 +01:00
|
|
|
}, validate: true
|
|
|
|
|
|
|
|
validates :name, presence: true
|
2024-08-11 19:24:24 +02:00
|
|
|
|
2024-11-03 09:15:48 +01:00
|
|
|
scope :potential, -> { where.not(status: %i[declined considered]) }
|
2024-11-17 17:07:29 +01:00
|
|
|
|
2024-11-17 18:25:38 +01:00
|
|
|
after_destroy :recalculate_simulations
|
2024-12-28 18:13:57 +01:00
|
|
|
after_save :recalculate_simulations, if: :saved_change_to_status?
|
2024-11-17 17:07:29 +01:00
|
|
|
|
2024-11-17 18:24:43 +01:00
|
|
|
has_many :seats, dependent: :delete_all
|
|
|
|
|
2024-11-17 17:07:29 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def recalculate_simulations
|
|
|
|
TablesArrangement.delete_all
|
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) })
|
2024-11-17 17:07:29 +01:00
|
|
|
end
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|