Fix sort params

This commit is contained in:
James Cole
2024-08-03 06:18:46 +02:00
parent b213148ae8
commit ff80cedd6b
6 changed files with 40 additions and 19 deletions

View File

@@ -35,13 +35,13 @@ class AccountSchema extends Schema
Attribute::make('updated_at'),
// basic info and meta data
Attribute::make('name'),
Attribute::make('active'),
Attribute::make('order'),
Attribute::make('iban'),
Attribute::make('name')->sortable(),
Attribute::make('active')->sortable(),
Attribute::make('order')->sortable(),
Attribute::make('iban')->sortable(),
Attribute::make('type'),
Attribute::make('account_role'),
Attribute::make('account_number'),
Attribute::make('account_number')->sortable(),
// currency
Attribute::make('currency_id'),
@@ -52,17 +52,18 @@ class AccountSchema extends Schema
Attribute::make('is_multi_currency'),
// balance
Attribute::make('balance'),
Attribute::make('native_balance'),
Attribute::make('balance')->sortable(),
Attribute::make('native_balance')->sortable(),
// liability things
Attribute::make('liability_direction'),
Attribute::make('interest'),
Attribute::make('interest_period'),
Attribute::make('current_debt'),
Attribute::make('current_debt')->sortable(),
// dynamic data
Attribute::make('last_activity'),
Attribute::make('balance_difference')->sortable(), // only used for sort.
// group
Attribute::make('object_group_id'),

View File

@@ -62,6 +62,7 @@ class AccountQuery extends QueryAll implements HasPagination
// collect sort options
$sort = $this->queryParameters->sortFields();
// collect pagination based on the page
$pagination = $this->filtersPagination($this->queryParameters->page());
// check if we need all accounts, regardless of pagination
@@ -76,14 +77,14 @@ class AccountQuery extends QueryAll implements HasPagination
// add pagination to the query, limiting the results.
if (!$needsAll) {
Log::debug('Need full dataset');
$query = $this->addPagination($query, $pagination);
}
// add sort and filter parameters to the query.
$query = $this->addSortParams($query, $sort);
$query = $this->addSortParams(Account::class, $query, $sort);
$query = $this->addFilterParams(Account::class, $query, $filters);
// collect the result.
$collection = $query->get(['accounts.*']);
@@ -93,10 +94,10 @@ class AccountQuery extends QueryAll implements HasPagination
$enrichment->setEnd($otherParams['end'] ?? null);
$collection = $enrichment->enrich($collection);
// TODO add filters after the query, if there are filters that cannot be applied to the database but only
// to the enriched results.
// TODO add filters after the query, if there are filters that cannot be applied to the database
// TODO same for sort things.
// sort the data after the query, and return it right away.
return $this->sortCollection($collection, $sort);
return $this->sortCollection(Account::class, $collection, $sort);
}
}