mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { GetBankRuleTransformer } from './GetBankRuleTransformer';
|
||||
import { TransformerInjectable } from '../../Transformer/TransformerInjectable.service';
|
||||
import { BankRule } from '../models/BankRule';
|
||||
import { GetBankRulesTransformer } from './GetBankRulesTransformer';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetBankRuleService {
|
||||
constructor(
|
||||
@Inject(BankRule.name)
|
||||
private bankRuleModel: TenantModelProxy<typeof BankRule>,
|
||||
private transformer: TransformerInjectable,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieves the bank rule.
|
||||
* @param {number} ruleId - Rule id.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
async getBankRule(ruleId: number): Promise<any> {
|
||||
const bankRule = await this.bankRuleModel()
|
||||
.query()
|
||||
.findById(ruleId)
|
||||
.withGraphFetched('conditions')
|
||||
.withGraphFetched('assignAccount');
|
||||
|
||||
return this.transformer.transform(bankRule, new GetBankRulesTransformer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Transformer } from "@/modules/Transformer/Transformer";
|
||||
|
||||
export class GetBankRuleTransformer extends Transformer {
|
||||
/**
|
||||
* Include these attributes to sale invoice object.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return [];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { GetBankRulesTransformer } from './GetBankRulesTransformer';
|
||||
import { BankRule } from '../models/BankRule';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetBankRulesService {
|
||||
constructor(
|
||||
private transformer: TransformerInjectable,
|
||||
|
||||
@Inject(BankRule.name)
|
||||
private bankRuleModel: TenantModelProxy<typeof BankRule>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieves the bank rules of the given account.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
public async getBankRules(): Promise<any> {
|
||||
const bankRule = await this.bankRuleModel()
|
||||
.query()
|
||||
.withGraphFetched('conditions')
|
||||
.withGraphFetched('assignAccount');
|
||||
|
||||
return this.transformer.transform(bankRule, new GetBankRulesTransformer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { Transformer } from '@/modules/Transformer/Transformer';
|
||||
import { getCashflowTransactionFormattedType } from '../../BankingTransactions/utils';
|
||||
|
||||
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) {
|
||||
return getCashflowTransactionFormattedType(bankRule.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