Skip to content

Commit

Permalink
feat(events): setup/breakdown events
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfox committed Sep 22, 2023
1 parent fe12ba1 commit eccd3f2
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/controllers/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,45 @@ class Events < Application
meta.host_email = event.host.as(String).downcase
meta.tenant_id = tenant.id
meta.cancelled = cancelled

if meta.setup_time > 0
# update setup event if it does exist
# create setup event if it doesn't exist
if setup_event_id = meta.setup_event_id
setup_event = client.get_event(meta.resource_calendar, id: setup_event_id, calendar_id: meta.resource_calendar)
setup_event.start_time = event_start - meta.setup_time
setup_event.end_time = event_start
else
setup_event = client.create_event(
user_id: meta.resource_calendar,
calendar_id: meta.resource_calendar,
subject: "Setup for #{event.subject}",
start_time: event_start - meta.setup_time,
end_time: event_start,
)
meta.setup_event_id = setup_event.id
end
end

if meta.breakdown_time > 0
# update breakdown event if it does exist
# create breakdown event if it doesn't exist
if breakdown_event_id = meta.breakdown_event_id
breakdown_event = client.get_event(meta.resource_calendar, id: breakdown_event_id, calendar_id: meta.resource_calendar)
breakdown_event.start_time = event_end
breakdown_event.end_time = event_end + meta.breakdown_time
else
breakdown_event = client.create_event(
user_id: meta.resource_calendar,
calendar_id: meta.resource_calendar,
subject: "Breakdown for #{event.subject}",
start_time: event_end,
end_time: event_end + meta.breakdown_time,
)
meta.breakdown_event_id = breakdown_event.id
end
end

meta.save!

return if skip_signal
Expand All @@ -1255,6 +1294,24 @@ class Events < Application
end

def notify_destroyed(system, event_id, event_ical_uid, event = nil)
# delete any setup/breakdown events associated with this event
if meta = EventMetadata.by_tenant(tenant.id).find_by?(event_id: event_id, system_id: system.id)
if setup_event_id = meta.setup_event_id
client.delete_event(
user_id: meta.resource_calendar,
id: setup_event_id,
calendar_id: meta.resource_calendar,
)
end
if breakdown_event_id = meta.breakdown_event_id
client.delete_event(
user_id: meta.resource_calendar,
id: breakdown_event_id,
calendar_id: meta.resource_calendar,
)
end
end

get_placeos_client.root.signal("staff/event/changed", {
action: :cancelled,
system_id: system.id,
Expand Down

0 comments on commit eccd3f2

Please sign in to comment.