added weekdays enum and week_start_at for user records
This commit is contained in:
parent
4fb0e2df7b
commit
4031640e1d
4 changed files with 11 additions and 0 deletions
|
@ -3,6 +3,7 @@ defmodule Shift73k.Accounts.User do
|
|||
import Ecto.Changeset
|
||||
import EctoEnum
|
||||
|
||||
alias Shift73k.EctoEnums.WeekdayEnum
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Shift
|
||||
|
||||
|
@ -28,6 +29,7 @@ defmodule Shift73k.Accounts.User do
|
|||
field(:confirmed_at, :naive_datetime)
|
||||
|
||||
field(:role, RolesEnum, default: :user)
|
||||
field(:week_start_at, WeekdayEnum, default: 1)
|
||||
|
||||
has_many(:shift_templates, ShiftTemplate)
|
||||
belongs_to(:fave_shift_template, ShiftTemplate)
|
||||
|
|
7
lib/shift73k/ecto_enums.ex
Normal file
7
lib/shift73k/ecto_enums.ex
Normal file
|
@ -0,0 +1,7 @@
|
|||
defmodule Shift73k.EctoEnums do
|
||||
import EctoEnum
|
||||
|
||||
@weekdays [:mon, :tue, :wed, :thu, :fri, :sat, :sun] |> Enum.with_index(1)
|
||||
|
||||
defenum(WeekdayEnum, @weekdays)
|
||||
end
|
|
@ -8,6 +8,7 @@ defmodule Shift73k.Repo.Migrations.CreateUsersAuthTables do
|
|||
add(:id, :binary_id, primary_key: true)
|
||||
add(:email, :citext, null: false)
|
||||
add(:hashed_password, :string, null: false)
|
||||
add(:week_start_at, :integer, null: false)
|
||||
add(:confirmed_at, :naive_datetime)
|
||||
timestamps()
|
||||
end
|
||||
|
|
|
@ -66,6 +66,7 @@ mock_users =
|
|||
email: e["email"],
|
||||
role: String.to_existing_atom(e["role"]),
|
||||
hashed_password: Bcrypt.hash_pwd_salt(e["password"]),
|
||||
week_start_at: :rand.uniform(2),
|
||||
inserted_at: add_dt,
|
||||
updated_at: add_dt,
|
||||
confirmed_at: (e["confirmed_at"] && NaiveDateTime.add(add_dt, 300, :second)) || nil
|
||||
|
|
Loading…
Reference in a new issue