mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { upperFirst, camelCase } from 'lodash';
|
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
|
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
|
|
|
export class GetBankRulesTransformer extends Transformer {
|
|
/**
|
|
* Include these attributes to sale invoice object.
|
|
* @returns {Array}
|
|
*/
|
|
public includeAttributes = (): string[] => {
|
|
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 ');
|
|
}
|
|
}
|