WIP: Define and seed an invitation model #224
@ -9,7 +9,7 @@ class GuestsController < ApplicationController
|
||||
render json: Guest.includes(:group)
|
||||
.left_joins(:group)
|
||||
.order('groups.name' => :asc, name: :asc)
|
||||
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
|
||||
.as_json(only: %i[id name status invitation_id], include: { group: { only: %i[id name] } })
|
||||
end
|
||||
|
||||
def create
|
||||
|
17
db/seeds.rb
17
db/seeds.rb
@ -60,18 +60,29 @@ ActsAsTenant.with_tenant(wedding) do
|
||||
|
||||
groups = Group.all
|
||||
|
||||
invitations = ([{}] * (NUMBER_OF_GUESTS * 0.8)).then { Invitation.insert_all!(it) }.rows.flatten
|
||||
|
||||
NUMBER_OF_GUESTS.times.map do |i|
|
||||
{
|
||||
name: Faker::Name.name,
|
||||
phone: Faker::PhoneNumber.cell_phone,
|
||||
group_id: groups.sample.id,
|
||||
status: Guest.statuses.keys.sample,
|
||||
invitation_id: invitations[i]
|
||||
}
|
||||
end.then { Guest.insert_all!(it) }
|
||||
|
||||
Group.includes(:guests).each do |group|
|
||||
guests = group.guests.potential.to_a
|
||||
|
||||
while guests.any?
|
||||
invitation = Invitation.create!
|
||||
|
||||
guests.shift(rand(1..3)).each do |guest|
|
||||
guest.update!(invitation:)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Clean up invitations with no guests
|
||||
|
||||
ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new(wedding.id) })
|
||||
|
||||
"red".dup.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user