mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
fix: decrement uncategorized transactions count
This commit is contained in:
@@ -130,7 +130,7 @@ export interface ICommandCashflowDeletedPayload {
|
|||||||
|
|
||||||
export interface ICashflowTransactionCategorizedPayload {
|
export interface ICashflowTransactionCategorizedPayload {
|
||||||
tenantId: number;
|
tenantId: number;
|
||||||
uncategorizedTransactions: any;
|
uncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
||||||
cashflowTransaction: ICashflowTransaction;
|
cashflowTransaction: ICashflowTransaction;
|
||||||
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
oldUncategorizedTransactions: Array<IUncategorizedCashflowTransaction>;
|
||||||
categorizeDTO: any;
|
categorizeDTO: any;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default class UncategorizedCashflowTransaction extends mixin(
|
|||||||
/**
|
/**
|
||||||
* Timestamps columns.
|
* Timestamps columns.
|
||||||
*/
|
*/
|
||||||
static get timestamps() {
|
get timestamps() {
|
||||||
return ['createdAt', 'updatedAt'];
|
return ['createdAt', 'updatedAt'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,13 @@ export class DecrementUncategorizedTransactionOnMatching {
|
|||||||
const { UncategorizedCashflowTransaction, Account } =
|
const { UncategorizedCashflowTransaction, Account } =
|
||||||
this.tenancy.models(tenantId);
|
this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const transactions = await UncategorizedCashflowTransaction.query().whereIn(
|
const uncategorizedTransactions =
|
||||||
'id',
|
await UncategorizedCashflowTransaction.query().whereIn(
|
||||||
uncategorizedTransactionIds
|
'id',
|
||||||
);
|
uncategorizedTransactionIds
|
||||||
|
);
|
||||||
await PromisePool.withConcurrency(1)
|
await PromisePool.withConcurrency(1)
|
||||||
.for(transactions)
|
.for(uncategorizedTransactions)
|
||||||
.process(async (transaction) => {
|
.process(async (transaction) => {
|
||||||
await Account.query(trx)
|
await Account.query(trx)
|
||||||
.findById(transaction.accountId)
|
.findById(transaction.accountId)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export class UncategorizeCashflowTransaction {
|
|||||||
categorizeRefType: null,
|
categorizeRefType: null,
|
||||||
});
|
});
|
||||||
const uncategorizedTransactions =
|
const uncategorizedTransactions =
|
||||||
await UncategorizedCashflowTransaction.query().whereIn(
|
await UncategorizedCashflowTransaction.query(trx).whereIn(
|
||||||
'id',
|
'id',
|
||||||
oldUncategoirzedTransactionsIds
|
oldUncategoirzedTransactionsIds
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
ICashflowTransactionCategorizedPayload,
|
ICashflowTransactionCategorizedPayload,
|
||||||
ICashflowTransactionUncategorizedPayload,
|
ICashflowTransactionUncategorizedPayload,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
|
import PromisePool from '@supercharge/promise-pool';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class DecrementUncategorizedTransactionOnCategorize {
|
export class DecrementUncategorizedTransactionOnCategorize {
|
||||||
@@ -35,13 +36,17 @@ export class DecrementUncategorizedTransactionOnCategorize {
|
|||||||
public async decrementUnCategorizedTransactionsOnCategorized({
|
public async decrementUnCategorizedTransactionsOnCategorized({
|
||||||
tenantId,
|
tenantId,
|
||||||
uncategorizedTransactions,
|
uncategorizedTransactions,
|
||||||
|
trx
|
||||||
}: ICashflowTransactionCategorizedPayload) {
|
}: ICashflowTransactionCategorizedPayload) {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
const accountIds = uncategorizedTransactions.map((a) => a.id);
|
|
||||||
|
|
||||||
await Account.query()
|
await PromisePool.withConcurrency(1)
|
||||||
.whereIn('id', accountIds)
|
.for(uncategorizedTransactions)
|
||||||
.decrement('uncategorizedTransactions', 1);
|
.process(async (uncategorizedTransaction) => {
|
||||||
|
await Account.query(trx)
|
||||||
|
.findById(uncategorizedTransaction.accountId)
|
||||||
|
.decrement('uncategorizedTransactions', 1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,15 +56,17 @@ export class DecrementUncategorizedTransactionOnCategorize {
|
|||||||
public async incrementUnCategorizedTransactionsOnUncategorized({
|
public async incrementUnCategorizedTransactionsOnUncategorized({
|
||||||
tenantId,
|
tenantId,
|
||||||
uncategorizedTransactions,
|
uncategorizedTransactions,
|
||||||
|
trx
|
||||||
}: ICashflowTransactionUncategorizedPayload) {
|
}: ICashflowTransactionUncategorizedPayload) {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const uncategorizedTransactionIds = uncategorizedTransactions?.map(
|
await PromisePool.withConcurrency(1)
|
||||||
(t) => t.id
|
.for(uncategorizedTransactions)
|
||||||
);
|
.process(async (uncategorizedTransaction) => {
|
||||||
await Account.query()
|
await Account.query(trx)
|
||||||
.whereIn('id', uncategorizedTransactionIds)
|
.findById(uncategorizedTransaction.accountId)
|
||||||
.increment('uncategorizedTransactions', 1);
|
.increment('uncategorizedTransactions', 1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export class DeleteCashflowTransactionOnUncategorize {
|
|||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (result.errors) {
|
if (result.errors.length > 0) {
|
||||||
throw new ServiceError('SOMETHING_WRONG');
|
throw new ServiceError('SOMETHING_WRONG');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user