Skip to content

Commit

Permalink
feat: Radio backend + reorder CSV (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathcolo authored Oct 28, 2024
1 parent 8ca4828 commit a7fcd70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/orbit/operator_sign_in.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Orbit.OperatorSignIn do
signed_in_by_user: User.t(),
signed_in_at: DateTime.t(),
rail_line: RailLine.t(),
radio_number: String.t() | nil,
sign_in_method: SignInMethod.t()
}

Expand All @@ -20,14 +21,15 @@ defmodule Orbit.OperatorSignIn do
belongs_to(:signed_in_by_user, User)
field(:signed_in_at, :utc_datetime)
field(:rail_line, RailLine)
field(:radio_number, :string)
field(:sign_in_method, SignInMethod)

timestamps()
end

def changeset(operator_sign_in, attrs \\ %{}) do
operator_sign_in
|> cast(attrs, [:signed_in_at, :rail_line, :sign_in_method])
|> cast(attrs, [:signed_in_at, :rail_line, :radio_number, :sign_in_method])
|> cast_assoc(:signed_in_employee)
|> cast_assoc(:signed_in_by_user)
|> validate_required([:signed_in_at, :rail_line, :sign_in_method])
Expand Down
6 changes: 4 additions & 2 deletions lib/orbit_web/controllers/sign_in_export_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ defmodule OrbitWeb.SignInExportController do
&1.operator_sign_in.signed_in_at
|> DateTime.shift_zone!(@timezone)
|> Timex.format!("{YYYY}-{0M}-{0D} {0h24}:{0m}:{0s}"),
location: "Orient Heights",
signer_badge: &1.operator_sign_in.signed_in_employee.badge_number,
signer_name: Employee.display_name(&1.operator_sign_in.signed_in_employee),
radio_number: &1.operator_sign_in.radio_number,
official_badge:
if &1.signed_in_by_employee do
&1.signed_in_by_employee.badge_number
Expand All @@ -72,6 +72,7 @@ defmodule OrbitWeb.SignInExportController do
else
&1.operator_sign_in.signed_in_by_user.email
end,
location: "Orient Heights",
method:
case &1.operator_sign_in.sign_in_method do
:nfc -> "tap"
Expand All @@ -83,11 +84,12 @@ defmodule OrbitWeb.SignInExportController do
|> CSV.encode(
headers: [
time: "Time",
location: "Location",
signer_badge: "Signer Badge #",
signer_name: "Signer Name",
radio_number: "Radio",
official_badge: "Official Badge #",
official_name: "Official Name",
location: "Location",
method: "Method",
text_version: "Text Version"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Orbit.Repo.Migrations.AlterSigninsRadio do
use Ecto.Migration

def change do
alter table(:operator_sign_ins) do
add :radio_number, :string
end
end
end
18 changes: 10 additions & 8 deletions test/orbit_web/controllers/sign_in_export_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,26 @@ defmodule OrbitWeb.SignInExportControllerTest do

assert [
%{
"Location" => "Orient Heights",
"Method" => "type",
"Time" => "2024-08-28 17:00:00",
"Signer Badge #" => "1234",
"Signer Name" => "Preferredy Person",
"Radio" => "22",
"Official Badge #" => "9898",
"Official Name" => "Fake Official",
"Text Version" => "1",
"Time" => "2024-08-28 17:00:00"
"Location" => "Orient Heights",
"Method" => "type",
"Text Version" => "1"
},
%{
"Location" => "Orient Heights",
"Method" => "tap",
"Time" => "2024-08-28 17:10:00",
"Signer Badge #" => "5678",
"Signer Name" => "Preferredy Person",
"Radio" => "22",
"Official Badge #" => "",
"Official Name" => "[email protected]",
"Text Version" => "1",
"Time" => "2024-08-28 17:10:00"
"Location" => "Orient Heights",
"Method" => "tap",
"Text Version" => "1"
}
] = result
end
Expand Down
1 change: 1 addition & 0 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule Orbit.Factory do
signed_in_by_user: build(:user),
signed_in_at: DateTime.add(base_dt, sequence(:operator_sign_in_time_offset, & &1), :minute),
rail_line: :blue,
radio_number: "22",
sign_in_method: :manual
}
end
Expand Down

0 comments on commit a7fcd70

Please sign in to comment.