@@ -5,6 +5,7 @@ defmodule Helix.Universe.Bank.Action.Flow.BankAccount do
55 alias Helix.Event
66 alias Helix.Entity.Query.Entity , as: EntityQuery
77 alias Helix.Network.Action.Flow.Tunnel , as: TunnelFlow
8+ alias Helix.Network.Model.Connection
89 alias Helix.Network.Query.Network , as: NetworkQuery
910 alias Helix.Process.Model.Process
1011 alias Helix.Server.Model.Server
@@ -15,6 +16,8 @@ defmodule Helix.Universe.Bank.Action.Flow.BankAccount do
1516
1617 alias Helix.Universe.Bank.Process.Bank.Account.RevealPassword ,
1718 as: BankAccountRevealPasswordProcess
19+ alias Helix.Universe.Bank.Process.Bank.Account.ChangePassword ,
20+ as: BankAccountChangePasswordProcess
1821
1922 @ typep relay :: Event . relay
2023
@@ -29,7 +32,12 @@ defmodule Helix.Universe.Bank.Action.Flow.BankAccount do
2932
3033 Emits: ProcessCreatedEvent
3134 """
32- @ spec reveal_password ( BankAccount . t , BankToken . id , Server . t , Server . t , relay ) ::
35+ @ spec reveal_password (
36+ BankAccount . t ,
37+ BankToken . id ,
38+ Server . t ,
39+ Server . t ,
40+ relay ) ::
3341 { :ok , Process . t }
3442 | BankAccountRevealPasswordProcess . executable_error
3543 def reveal_password ( account , token_id , gateway , atm , relay ) do
@@ -46,6 +54,41 @@ defmodule Helix.Universe.Bank.Action.Flow.BankAccount do
4654 BankAccountRevealPasswordProcess . execute ( gateway , atm , params , meta , relay )
4755 end
4856
57+ @ spec open ( Account . id , ATM . id ) ::
58+ { :ok , BankAccount . t }
59+ | { :error , :internal }
60+ @ doc """
61+ Opens a new BankAccount to given Account.id
62+ """
63+ def open ( account_id , atm_id ) do
64+ bank_account =
65+ BankAction . open_account ( account_id , atm_id )
66+ case bank_account do
67+ { :ok , bank_account } ->
68+ { :ok , bank_account }
69+ { :error , _ } ->
70+ { :error , :internal }
71+ end
72+ end
73+
74+ @ spec change_password ( BankAccount . t , Server . t , Server . t , relay ) ::
75+ { :ok , Process . t }
76+ | BankAccountChangePasswordProcess . executable_error
77+ @ doc """
78+ Starts a ChangePasswordProcess
79+
80+ Emits: ProcessCreatedEvent
81+ """
82+ def change_password ( account , gateway , atm , relay ) do
83+ meta = % {
84+ network_id: NetworkQuery . internet ( ) . network_id ,
85+ src_atm_id: atm . server_id ,
86+ src_acc_number: account . account_number ,
87+ bounce: nil
88+ }
89+
90+ BankAccountChangePasswordProcess . execute ( gateway , atm , % { } , meta , relay )
91+ end
4992 @ doc """
5093 Logs into a bank account using a password. If the given password matches the
5194 current account password, the login is successful, in which case a BankLogin
@@ -74,9 +117,9 @@ defmodule Helix.Universe.Bank.Action.Flow.BankAccount do
74117 { :ok , _ , events } <- BankAction . login_password ( acc , password , entity ) ,
75118 on_success ( fn -> Event . emit ( events ) end ) ,
76119
77- { :ok , _ , connection } <- start_connection . ( )
120+ { :ok , tunnel , connection } <- start_connection . ( )
78121 do
79- { :ok , connection }
122+ { :ok , tunnel , connection }
80123 end
81124 end
82125 end
0 commit comments