mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import UnitOfWork from '@/services/UnitOfWork';
|
|
import { Inject, Service } from 'typedi';
|
|
import { validateTransactionNotCategorized } from './utils';
|
|
|
|
@Service()
|
|
export class UnexcludeBankTransaction {
|
|
@Inject()
|
|
private tenancy: HasTenancyService;
|
|
|
|
@Inject()
|
|
private uow: UnitOfWork;
|
|
|
|
/**
|
|
* Marks the given bank transaction as excluded.
|
|
* @param {number} tenantId
|
|
* @param {number} bankTransactionId
|
|
* @returns {Promise<void>}
|
|
*/
|
|
public async unexcludeBankTransaction(
|
|
tenantId: number,
|
|
uncategorizedTransactionId: number
|
|
) {
|
|
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
|
|
|
const oldUncategorizedTransaction =
|
|
await UncategorizedCashflowTransaction.query()
|
|
.findById(uncategorizedTransactionId)
|
|
.throwIfNotFound();
|
|
|
|
validateTransactionNotCategorized(oldUncategorizedTransaction);
|
|
|
|
return this.uow.withTransaction(tenantId, async (trx) => {
|
|
await UncategorizedCashflowTransaction.query(trx)
|
|
.findById(uncategorizedTransactionId)
|
|
.patch({
|
|
excludedAt: null,
|
|
});
|
|
});
|
|
}
|
|
}
|