Update repositories, remove references to admin id

This commit is contained in:
James Cole
2023-09-23 07:15:41 +02:00
parent de7638c502
commit 75e5115aa3
16 changed files with 1047 additions and 1011 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/**
* Class AccountRepository
@@ -40,6 +41,32 @@ class AccountRepository implements AccountRepositoryInterface
{
use UserGroupTrait;
/**
* @inheritDoc
*/
public function findByName(string $name, array $types): ?Account
{
$query = $this->userGroup->accounts();
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
$query->where('accounts.name', $name);
/** @var Account $account */
$account = $query->first(['accounts.*']);
if (null === $account) {
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
return null;
}
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account;
}
/**
* @param Account $account
*