WIP: dynamic list filtering.

This commit is contained in:
a.bouhuolia
2021-07-31 17:07:37 +02:00
parent 9186076676
commit 3546b6b7ae
34 changed files with 569 additions and 314 deletions

View File

@@ -8,6 +8,7 @@ import DependencyGraph from 'lib/DependencyGraph';
import AccountTypesUtils from 'lib/AccountTypes';
import AccountSettings from './Account.Settings';
import ModelSettings from './ModelSetting';
import { ACCOUNT_TYPES } from 'data/AccountTypes';
export default class Account extends mixin(TenantModel, [ModelSettings]) {
/**
@@ -98,7 +99,7 @@ export default class Account extends mixin(TenantModel, [ModelSettings]) {
* Inactive/Active mode.
*/
inactiveMode(query, active = false) {
query.where('active', !active);
query.where('accounts.active', !active);
},
filterAccounts(query, accountIds) {
@@ -117,6 +118,28 @@ export default class Account extends mixin(TenantModel, [ModelSettings]) {
sortColumnBuilder(query, columnKey, direction) {
buildSortColumnQuery(Account.tableName, columnKey, direction)(query);
},
/**
* Filter by root type.
*/
filterByRootType(query, rootType) {
const filterTypes = ACCOUNT_TYPES.filter(
(accountType) => accountType.rootType === rootType
).map((accountType) => accountType.key);
query.whereIn('account_type', filterTypes);
},
/**
* Filter by account normal
*/
filterByAccountNormal(query, accountNormal) {
const filterTypes = ACCOUNT_TYPES.filter(
(accountType) => accountType.normal === accountNormal,
).map((accountType) => accountType.key);
query.whereIn('account_type', filterTypes);
},
};
}