feat: excluded bank transactions

This commit is contained in:
Ahmed Bouhuolia
2024-06-27 22:14:53 +02:00
parent fab22c9820
commit 978ce6c441
28 changed files with 1301 additions and 27 deletions

View File

@@ -1,6 +1,8 @@
import { Inject, Service } from 'typedi';
import { ExcludeBankTransaction } from './ExcludeBankTransaction';
import { UnexcludeBankTransaction } from './UnexcludeBankTransaction';
import { GetExcludedBankTransactionsService } from './GetExcludedBankTransactions';
import { ExcludedBankTransactionsQuery } from './_types';
@Service()
export class ExcludeBankTransactionsApplication {
@@ -10,6 +12,9 @@ export class ExcludeBankTransactionsApplication {
@Inject()
private unexcludeBankTransactionService: UnexcludeBankTransaction;
@Inject()
private getExcludedBankTransactionsService: GetExcludedBankTransactionsService;
/**
* Marks a bank transaction as excluded.
* @param {number} tenantId - The ID of the tenant.
@@ -35,4 +40,20 @@ export class ExcludeBankTransactionsApplication {
bankTransactionId
);
}
/**
* Retrieves the excluded bank transactions.
* @param {number} tenantId
* @param {ExcludedBankTransactionsQuery} filter
* @returns {}
*/
public getExcludedBankTransactions(
tenantId: number,
filter: ExcludedBankTransactionsQuery
) {
return this.getExcludedBankTransactionsService.getExcludedBankTransactions(
tenantId,
filter
);
}
}

View File

@@ -0,0 +1,52 @@
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
import { ExcludedBankTransactionsQuery } from './_types';
import { UncategorizedTransactionTransformer } from '@/services/Cashflow/UncategorizedTransactionTransformer';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
@Service()
export class GetExcludedBankTransactionsService {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private transformer: TransformerInjectable;
/**
* Retrieves the excluded uncategorized bank transactions.
* @param {number} tenantId
* @param {ExcludedBankTransactionsQuery} filter
* @returns
*/
public async getExcludedBankTransactions(
tenantId: number,
filter: ExcludedBankTransactionsQuery
) {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
// Parsed query with default values.
const _query = {
page: 1,
pageSize: 20,
...filter,
};
const { results, pagination } =
await UncategorizedCashflowTransaction.query()
.onBuild((q) => {
q.where('excluded', true);
q.orderBy('date', 'DESC');
if (_query.accountId) {
q.where('account_id', _query.accountId);
}
})
.pagination(_query.page - 1, _query.pageSize);
const data = await this.transformer.transform(
tenantId,
results,
new UncategorizedTransactionTransformer()
);
return { data, pagination };
}
}

View File

@@ -0,0 +1,6 @@
export interface ExcludedBankTransactionsQuery {
page?: number;
pageSize?: number;
accountId?: number;
}