mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d24474162 | ||
|
|
5962b990c4 |
@@ -146,6 +146,7 @@ export interface ICashflowTransactionUncategorizedPayload {
|
|||||||
tenantId: number;
|
tenantId: number;
|
||||||
uncategorizedTransactionId: number;
|
uncategorizedTransactionId: number;
|
||||||
uncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
uncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
||||||
|
oldMainUncategorizedTransaction: IUncategorizedCashflowTransaction;
|
||||||
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,22 +33,25 @@ export class UncategorizeCashflowTransaction {
|
|||||||
): Promise<Array<number>> {
|
): Promise<Array<number>> {
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const oldUncategorizedTransaction =
|
const oldMainUncategorizedTransaction =
|
||||||
await UncategorizedCashflowTransaction.query()
|
await UncategorizedCashflowTransaction.query()
|
||||||
.findById(uncategorizedTransactionId)
|
.findById(uncategorizedTransactionId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
validateTransactionShouldBeCategorized(oldUncategorizedTransaction);
|
validateTransactionShouldBeCategorized(oldMainUncategorizedTransaction);
|
||||||
|
|
||||||
const associatedUncategorizedTransactions =
|
const associatedUncategorizedTransactions =
|
||||||
await UncategorizedCashflowTransaction.query()
|
await UncategorizedCashflowTransaction.query()
|
||||||
.where('categorizeRefId', oldUncategorizedTransaction.categorizeRefId)
|
.where('categorizeRefId', oldMainUncategorizedTransaction.categorizeRefId)
|
||||||
.where(
|
.where(
|
||||||
'categorizeRefType',
|
'categorizeRefType',
|
||||||
oldUncategorizedTransaction.categorizeRefType
|
oldMainUncategorizedTransaction.categorizeRefType
|
||||||
);
|
)
|
||||||
|
// Exclude the main transaction.
|
||||||
|
.whereNot('id', uncategorizedTransactionId);
|
||||||
|
|
||||||
const oldUncategorizedTransactions = [
|
const oldUncategorizedTransactions = [
|
||||||
oldUncategorizedTransaction,
|
oldMainUncategorizedTransaction,
|
||||||
...associatedUncategorizedTransactions,
|
...associatedUncategorizedTransactions,
|
||||||
];
|
];
|
||||||
const oldUncategoirzedTransactionsIds = oldUncategorizedTransactions.map(
|
const oldUncategoirzedTransactionsIds = oldUncategorizedTransactions.map(
|
||||||
@@ -85,6 +88,7 @@ export class UncategorizeCashflowTransaction {
|
|||||||
{
|
{
|
||||||
tenantId,
|
tenantId,
|
||||||
uncategorizedTransactionId,
|
uncategorizedTransactionId,
|
||||||
|
oldMainUncategorizedTransaction,
|
||||||
uncategorizedTransactions,
|
uncategorizedTransactions,
|
||||||
oldUncategorizedTransactions,
|
oldUncategorizedTransactions,
|
||||||
trx,
|
trx,
|
||||||
|
|||||||
@@ -22,32 +22,25 @@ export class DeleteCashflowTransactionOnUncategorize {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the cashflow transaction on uncategorize transaction.
|
* Deletes the cashflow transaction once uncategorize the bank transaction.
|
||||||
* @param {ICashflowTransactionUncategorizedPayload} payload
|
* @param {ICashflowTransactionUncategorizedPayload} payload
|
||||||
*/
|
*/
|
||||||
public async deleteCashflowTransactionOnUncategorize({
|
public async deleteCashflowTransactionOnUncategorize({
|
||||||
tenantId,
|
tenantId,
|
||||||
oldUncategorizedTransactions,
|
oldMainUncategorizedTransaction,
|
||||||
trx,
|
trx,
|
||||||
}: ICashflowTransactionUncategorizedPayload) {
|
}: ICashflowTransactionUncategorizedPayload) {
|
||||||
const _oldUncategorizedTransactions = oldUncategorizedTransactions.filter(
|
// Cannot continue if the main transaction does not reference to cashflow type.
|
||||||
(transaction) => transaction.categorizeRefType === 'CashflowTransaction'
|
if (
|
||||||
);
|
oldMainUncategorizedTransaction.categorizeRefType !==
|
||||||
|
'CashflowTransaction'
|
||||||
// Deletes the cashflow transaction.
|
) {
|
||||||
if (_oldUncategorizedTransactions.length > 0) {
|
return;
|
||||||
const result = await PromisePool.withConcurrency(1)
|
|
||||||
.for(_oldUncategorizedTransactions)
|
|
||||||
.process(async (oldUncategorizedTransaction) => {
|
|
||||||
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
|
||||||
tenantId,
|
|
||||||
oldUncategorizedTransaction.categorizeRefId,
|
|
||||||
trx
|
|
||||||
);
|
|
||||||
});
|
|
||||||
if (result.errors.length > 0) {
|
|
||||||
throw new ServiceError('SOMETHING_WRONG');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
||||||
|
tenantId,
|
||||||
|
oldMainUncategorizedTransaction.categorizeRefId,
|
||||||
|
trx
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user