mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { GetRecognizedTransactionTransformer } from './GetRecognizedTransactionTransformer';
|
|
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
|
import { UncategorizedBankTransaction } from '../models/UncategorizedBankTransaction';
|
|
|
|
@Injectable()
|
|
export class GetRecognizedTransactionService {
|
|
constructor(
|
|
private readonly transformer: TransformerInjectable,
|
|
|
|
@Inject(UncategorizedBankTransaction.name)
|
|
private readonly uncategorizedBankTransactionModel: typeof UncategorizedBankTransaction
|
|
) {}
|
|
|
|
/**
|
|
* Retrieves the recognized transaction of the given uncategorized transaction.
|
|
* @param {number} tenantId
|
|
* @param {number} uncategorizedTransactionId
|
|
*/
|
|
public async getRecognizedTransaction(
|
|
uncategorizedTransactionId: number
|
|
) {
|
|
const uncategorizedTransaction =
|
|
await this.uncategorizedBankTransactionModel.query()
|
|
.findById(uncategorizedTransactionId)
|
|
.withGraphFetched('matchedBankTransactions')
|
|
.withGraphFetched('recognizedTransaction.assignAccount')
|
|
.withGraphFetched('recognizedTransaction.bankRule')
|
|
.withGraphFetched('account')
|
|
.throwIfNotFound();
|
|
|
|
return this.transformer.transform(
|
|
uncategorizedTransaction,
|
|
new GetRecognizedTransactionTransformer()
|
|
);
|
|
}
|
|
}
|