New method to collect a users accounts by the given ids.

This commit is contained in:
James Cole 2016-02-04 08:53:15 +01:00
parent 5c3165efa2
commit 55e4875662
2 changed files with 23 additions and 3 deletions

View File

@ -72,6 +72,18 @@ class AccountRepository implements AccountRepositoryInterface
return Auth::user()->accounts()->findOrNew($accountId); return Auth::user()->accounts()->findOrNew($accountId);
} }
/**
* Gets all the accounts by ID, for a given set.
*
* @param array $ids
*
* @return Collection
*/
public function get(array $ids)
{
return Auth::user()->accounts()->whereIn('id', $ids)->get(['accounts.*']);
}
/** /**
* @param array $types * @param array $types
* *
@ -464,9 +476,7 @@ class AccountRepository implements AccountRepositoryInterface
if (!$existingAccount) { if (!$existingAccount) {
Log::error('Account create error: ' . $newAccount->getErrors()->toJson()); Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
abort(500); abort(500);
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd
$newAccount = $existingAccount; $newAccount = $existingAccount;
} }
@ -554,7 +564,7 @@ class AccountRepository implements AccountRepositoryInterface
{ {
$journal->date = $data['openingBalanceDate']; $journal->date = $data['openingBalanceDate'];
$journal->save(); $journal->save();
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) { foreach ($journal->transactions()->get() as $transaction) {
if ($account->id == $transaction->account_id) { if ($account->id == $transaction->account_id) {

View File

@ -17,6 +17,7 @@ use Illuminate\Support\Collection;
*/ */
interface AccountRepositoryInterface interface AccountRepositoryInterface
{ {
/** /**
* @param array $types * @param array $types
* *
@ -41,6 +42,15 @@ interface AccountRepositoryInterface
*/ */
public function find($accountId); public function find($accountId);
/**
* Gets all the accounts by ID, for a given set.
*
* @param array $ids
*
* @return Collection
*/
public function get(array $ids);
/** /**
* @param array $types * @param array $types
* *