Skip to content

Commit

Permalink
Fix seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Aug 12, 2023
1 parent 1a8e48f commit cb66bfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 4 additions & 3 deletions priv/repo/seeds/accounts.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ defmodule Atomic.Repo.Seeds.Accounts do
"password" => "password1234",
"role" => role,
"course_id" => Enum.random(courses).id,
"default_organization_id" => Enum.random(organizations).id
"default_organization_id" => Enum.random(organizations).id,
"confirmed_at" => DateTime.utc_now()
}

case Accounts.register_user(user) do
{:error, changeset} ->
Mix.shell().error(Kernel.inspect(changeset.errors))

{:ok, _} ->
:ok
{:ok, changeset} ->
Repo.update!(Accounts.User.confirm_changeset(changeset))
end
end
end
Expand Down
14 changes: 6 additions & 8 deletions priv/repo/seeds/activities.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Atomic.Repo.Seeds.Activities do

alias Atomic.Accounts.User
alias Atomic.Organizations.Department
alias Atomic.Activities
alias Atomic.Activities.SessionDepartment
alias Atomic.Activities.Session
alias Atomic.Organizations.Organization
Expand Down Expand Up @@ -211,14 +212,11 @@ defmodule Atomic.Repo.Seeds.Activities do
case Repo.all(Enrollment) do
[] ->
for user <- Repo.all(User) do
for _ <- 1..Enum.random(1..3) do
%Enrollment{}
|> Enrollment.changeset(%{
user_id: user.id,
session_id: Enum.random(sessions).id,
present: Enum.random([true, false])
})
|> Repo.insert!()
for _ <- 1..Enum.random(1..2) do
Activities.create_enrollment(
Enum.random(sessions).id,
user
)
end
end
end
Expand Down

0 comments on commit cb66bfb

Please sign in to comment.