Skip to content

Commit

Permalink
Prevent DB constraint error when editing 0 minute long events
Browse files Browse the repository at this point in the history
  • Loading branch information
francois committed Aug 24, 2016
1 parent ca3cba1 commit 4b58bc9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ def table_name_from_user_id(user_id)
end

put %r{\A/me/#{UUID_RE}/#{UUID_RE}} do |user_id, event_id|
tz = TZInfo::Timezone.get(params.fetch("timezone"))
sleep_type = %w(nap night).detect{|value| value == params.fetch("sleep_type")}
tz = TZInfo::Timezone.get(params.fetch("timezone"))
sleep_type = %w(nap night).detect{|value| value == params.fetch("sleep_type")}
local_start_at = Time.parse(params.fetch("local_start_at"))
local_end_at = Time.parse(params.fetch("local_end_at"))
local_end_at += 1 if local_start_at == local_end_at
# TODO: things that make you go hummm... if local_start_at > local_end_at

DB[table_name_from_user_id(user_id)].filter(event_id: event_id).update(
timezone: tz.name,
Expand Down

0 comments on commit 4b58bc9

Please sign in to comment.