Skip to content

Commit

Permalink
chore: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo committed Nov 4, 2024
1 parent f67034e commit 402cd8b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/safira/activities/activity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ defmodule Safira.Activities.Activity do
date = get_field(activity, :date)

# Validate if the activity's date is within the event's start and end date
if date != nil do
if Date.compare(date, event_start) in [:lt] do
cond do
date == nil ->
activity
|> Ecto.Changeset.add_error(

Date.compare(date, event_start) == :lt ->
Ecto.Changeset.add_error(
activity,
:date,
"must be after or in the event's start date (#{Date.to_string(event_start)})"
)
else
if Date.compare(date, event_end) in [:gt] do
activity
|> Ecto.Changeset.add_error(
:date,
"must be before or in the event's end date (#{Date.to_string(event_end)})"
)
else
activity
end
end
else
activity

Date.compare(date, event_end) == :gt ->
Ecto.Changeset.add_error(
activity,
:date,
"must be before or in the event's end date (#{Date.to_string(event_end)})"
)

true ->
activity
end
end

Expand Down

0 comments on commit 402cd8b

Please sign in to comment.