feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -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());
}
}

View File

@@ -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 [];
};
}

View File

@@ -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());
}
}

View File

@@ -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 ');
}
}