mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: excluded bank transactions
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
6
packages/server/src/services/Banking/Exclude/_types.ts
Normal file
6
packages/server/src/services/Banking/Exclude/_types.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
export interface ExcludedBankTransactionsQuery {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
accountId?: number;
|
||||
}
|
||||
Reference in New Issue
Block a user