feat: wip matching bank transactions

This commit is contained in:
Ahmed Bouhuolia
2024-07-01 12:02:59 +02:00
parent da0fab9a58
commit c27458ebcc
12 changed files with 107 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
import { Inject, Service } from 'typedi';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { GetMatchedTransactionBillsTransformer } from './GetMatchedTransactionBillsTransformer';
import { GetMatchedTransactionsFilter } from './types';
import { GetMatchedTransactionsFilter, MatchedTransactionPOJO } from './types';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { GetMatchedTransactionsByType } from './GetMatchedTransactionsByType';
@@ -24,7 +24,9 @@ export class GetMatchedTransactionsByBills extends GetMatchedTransactionsByType
) {
const { Bill } = this.tenancy.models(tenantId);
const bills = await Bill.query();
const bills = await Bill.query().onBuild((q) => {
q.whereNotExists(Bill.relatedQuery('matchedBankTransaction'));
});
return this.transformer.transform(
tenantId,
@@ -32,4 +34,25 @@ export class GetMatchedTransactionsByBills extends GetMatchedTransactionsByType
new GetMatchedTransactionBillsTransformer()
);
}
/**
* Retrieves the given bill matched transaction.
* @param {number} tenantId
* @param {number} transactionId
* @returns {Promise<MatchedTransactionPOJO>}
*/
public async getMatchedTransaction(
tenantId: number,
transactionId: number
): Promise<MatchedTransactionPOJO> {
const { Bill } = this.tenancy.models(tenantId);
const bill = await Bill.query().findById(transactionId).throwIfNotFound();
return this.transformer.transform(
tenantId,
bill,
new GetMatchedTransactionBillsTransformer()
);
}
}