Specs › events-programme · version 1 ·
tags
#events

events-programme✎ edit

The double-booking guard. Two sessions can't share a room at the same time. When a session is made or moved, this checks it against the other sessions in the same room: a clash is reported, with both titles and the time. A flow can't stop a save that has already happened, so the trigger in Init takes a new clashing session out again, and flags a moved one (status: "clash") for the organizers to fix.

$when events.clashes (id: String) {
  s = dom.find(cls = "Session", key = id)
  a = toMillis(s.start as Date)
  b = toMillis(s.end as Date)
  payload = dom.list(cls = "Session").data filter (o => o.id != id and o.room is s.room and o.status != "clash" and toMillis(o.start as Date) < b and toMillis(o.end as Date) > a) map (o => o.title)
}
$when events.sessionAdded (id: String) {
  s = dom.find(cls = "Session", key = id)
  clash = events.clashes(id = id)
  if (clash is empty) {
    payload = "ok"
  } else {
    dom.remove(cls = "Session", key = id)
    events.tellOrganizers(text = "Not added: \"${s.title}\" clashes with \"${clash[0]}\" in ${s.room}")
    payload = "refused"
  }
}
$when events.sessionMoved (id: String) {
  s = dom.find(cls = "Session", key = id)
  clash = events.clashes(id = id)
  if (clash is empty) {
    payload = "ok"
  } else {
    dom.upsert(cls = "Session", entity = s + {status: "clash"})
    events.tellOrganizers(text = "Clash: \"${s.title}\" and \"${clash[0]}\" are both in ${s.room}")
    payload = "clash"
  }
}