This commit is contained in:
James Cole
2020-07-21 06:20:31 +02:00
parent b207100074
commit 62fd701808
4 changed files with 8 additions and 7 deletions

View File

@@ -63,7 +63,6 @@ class AccountController extends Controller
} }
/** /**
* TODO add limit
* @param AutocompleteRequest $request * @param AutocompleteRequest $request
* *
* @return JsonResponse * @return JsonResponse
@@ -78,7 +77,7 @@ class AccountController extends Controller
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$return = []; $return = [];
$result = $repository->searchAccount((string) $query, $types); $result = $repository->searchAccount((string) $query, $types, $data['limit']);
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */ /** @var Account $account */

View File

@@ -559,10 +559,11 @@ class AccountRepository implements AccountRepositoryInterface
/** /**
* @param string $query * @param string $query
* @param array $types * @param array $types
* @param int $limit
* *
* @return Collection * @return Collection
*/ */
public function searchAccount(string $query, array $types): Collection public function searchAccount(string $query, array $types, int $limit): Collection
{ {
$dbQuery = $this->user->accounts() $dbQuery = $this->user->accounts()
->where('active', 1) ->where('active', 1)
@@ -582,7 +583,7 @@ class AccountRepository implements AccountRepositoryInterface
$dbQuery->whereIn('account_types.type', $types); $dbQuery->whereIn('account_types.type', $types);
} }
return $dbQuery->get(['accounts.*']); return $dbQuery->take($limit)->get(['accounts.*']);
} }
/** /**

View File

@@ -276,10 +276,11 @@ interface AccountRepositoryInterface
/** /**
* @param string $query * @param string $query
* @param array $types * @param array $types
* @param int $limit
* *
* @return Collection * @return Collection
*/ */
public function searchAccount(string $query, array $types): Collection; public function searchAccount(string $query, array $types, int $limit): Collection;
/** /**
* @param User $user * @param User $user

View File

@@ -214,7 +214,7 @@ class Search implements SearchInterface
case 'source': case 'source':
// source can only be asset, liability or revenue account: // source can only be asset, liability or revenue account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE]; $searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE];
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes); $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) { if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts); $totalAccounts = $accounts->merge($totalAccounts);
} }
@@ -223,7 +223,7 @@ class Search implements SearchInterface
case 'destination': case 'destination':
// source can only be asset, liability or expense account: // source can only be asset, liability or expense account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE]; $searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE];
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes); $accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) { if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts); $totalAccounts = $accounts->merge($totalAccounts);
} }