Account controller #185

This commit is contained in:
James Cole 2016-03-12 11:05:26 +01:00
parent 1aea4045a3
commit 919aa70251
3 changed files with 8 additions and 9 deletions

View File

@ -87,7 +87,7 @@ class AccountController extends Controller
$type = $account->accountType->type; $type = $account->accountType->type;
$typeName = Config::get('firefly.shortNamesByFullName.' . $type); $typeName = Config::get('firefly.shortNamesByFullName.' . $type);
$name = $account->name; $name = $account->name;
$moveTo = Auth::user()->accounts()->find(intval(Input::get('move_account_before_delete'))); $moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
$repository->destroy($account, $moveTo); $repository->destroy($account, $moveTo);

View File

@ -66,9 +66,9 @@ class AccountRepository implements AccountRepositoryInterface
* *
* @return bool * @return bool
*/ */
public function destroy(Account $account, Account $moveTo = null): bool public function destroy(Account $account, Account $moveTo): bool
{ {
if (!is_null($moveTo)) { if (!is_null($moveTo->id)) {
// update all transactions: // update all transactions:
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
} }
@ -79,15 +79,16 @@ class AccountRepository implements AccountRepositoryInterface
} }
/** /**
* @deprecated
*
* @param int $accountId * @param int $accountId
* *
* @return Account * @return Account
*/ */
public function find(int $accountId): Account public function find(int $accountId): Account
{ {
return $this->user->accounts()->findOrNew($accountId); $entry = $this->user->accounts()->find($accountId);
if (is_null($entry)) {
return new Account;
}
} }
/** /**

View File

@ -32,13 +32,11 @@ interface AccountRepositoryInterface
* *
* @return boolean * @return boolean
*/ */
public function destroy(Account $account, Account $moveTo = null): bool; public function destroy(Account $account, Account $moveTo): bool;
/** /**
* @param int $accountId * @param int $accountId
* *
* @deprecated
*
* @return Account * @return Account
*/ */
public function find(int $accountId): Account; public function find(int $accountId): Account;