mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: Bank rules conditions column
This commit is contained in:
@@ -39,6 +39,7 @@ export class BankRule extends TenantModel {
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const { BankRuleCondition } = require('models/BankRuleCondition');
|
||||
const Account = require('models/Account');
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -52,6 +53,15 @@ export class BankRule extends TenantModel {
|
||||
to: 'bank_rule_conditions.ruleId',
|
||||
},
|
||||
},
|
||||
|
||||
assignAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'bank_rules.assignAccountId',
|
||||
to: 'accounts.id'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,16 @@ export class GetBankRulesService {
|
||||
|
||||
/**
|
||||
* Retrieves the bank rules of the given account.
|
||||
* @param {number} tenantId
|
||||
* @param {number} accountId
|
||||
* @param {number} tenantId
|
||||
* @param {number} accountId
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
public async getBankRules(tenantId: number): Promise<any> {
|
||||
const { BankRule } = this.tenancy.models(tenantId);
|
||||
|
||||
const bankRule = await BankRule.query();
|
||||
const bankRule = await BankRule.query()
|
||||
.withGraphFetched('conditions')
|
||||
.withGraphFetched('assignAccount');
|
||||
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { upperFirst, camelCase } from 'lodash';
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||
|
||||
export class GetBankRulesTransformer extends Transformer {
|
||||
/**
|
||||
@@ -6,6 +8,44 @@ export class GetBankRulesTransformer extends Transformer {
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return [];
|
||||
return [
|
||||
'assignAccountName',
|
||||
'assignCategoryFormatted',
|
||||
'conditionsFormatted',
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the assign account name.
|
||||
* @param bankRule
|
||||
* @returns {string}
|
||||
*/
|
||||
protected assignAccountName(bankRule: any) {
|
||||
return bankRule.assignAccount.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigned category formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
protected assignCategoryFormatted(bankRule: any) {
|
||||
const assignCategory = upperFirst(camelCase(bankRule.assignCategory));
|
||||
return getTransactionTypeLabel(assignCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bank rule formatted conditions.
|
||||
* @param bankRule
|
||||
* @returns {string}
|
||||
*/
|
||||
protected conditionsFormatted(bankRule: any) {
|
||||
return bankRule.conditions
|
||||
.map((condition) => {
|
||||
const field =
|
||||
condition.field.charAt(0).toUpperCase() + condition.field.slice(1);
|
||||
|
||||
return `${field} ${condition.comparator} ${condition.value}`;
|
||||
})
|
||||
.join(bankRule.conditionsType === 'and' ? ' and ' : ' or ');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user