Waitlist
When an event is full, put new people on a waitlist. If someone cancels, give their place to the first person waiting and email them.
The agent wrote a test that fills an event, cancels a place and checks who gets the email.
- Full
- A place opens
See the code app/lib/rsvp.lua
17-- Cancelling a place gives it to the first person waiting, and emails them. 18-- Their RSVP and their address are another user's, so that read and that 19-- write cross users on purpose. 20function M.cancel(event_id) 21 eql.transaction(function() 22 local mine = eql.one [[ 23 select rsvps { id, status } 24 where .event_id = $event_id and .user_id = $auth.id 25 ]] 26 if not mine then 27 return 28 end 29 eql "delete rsvps where .id = $mine.id" 30 if mine.status == "waitlist" then 31 return 32 end 33 34 local first = eql.unscoped([[ 35 select rsvps { 36 id, 37 users { email, name }, 38 events { id, title, starts_at, venue } 39 } 40 where .event_id = $event_id and .status = 'waitlist' 41 order by .created_at, .id 42 limit 1 43 ]])[1] 44 if not first then 45 return 46 end 47 48 eql.unscoped [[ 49 update rsvps set { status: 'going' } 50 where .id = $first.id 51 ]] 52 assert(mail.send { 53 to = first.users.email, 54 template = "promoted", 55 queue = true, 56 data = { name = first.users.name:match("^%S+"), event = first.events }, 57 }) 58 end) 59end




