Skip to content

Commit

Permalink
fix: increment/decrement uncategorized transactions on excluding
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Jul 7, 2024
1 parent 9a5befb commit b80bc95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class UnexcludeBankTransaction {
public async unexcludeBankTransaction(
tenantId: number,
uncategorizedTransactionId: number
) {
): Promise<void> {
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);

const oldUncategorizedTransaction =
Expand All @@ -40,21 +40,27 @@ export class UnexcludeBankTransaction {
validateTransactionNotCategorized(oldUncategorizedTransaction);

return this.uow.withTransaction(tenantId, async (trx) => {
await this.eventPublisher.emitAsync(events.bankTransactions.onExcluding, {
tenantId,
uncategorizedTransactionId,
} as IBankTransactionExcludingEventPayload);
await this.eventPublisher.emitAsync(
events.bankTransactions.onUnexcluding,
{
tenantId,
uncategorizedTransactionId,
} as IBankTransactionExcludingEventPayload
);

await UncategorizedCashflowTransaction.query(trx)
.findById(uncategorizedTransactionId)
.patch({
excludedAt: null,
});

await this.eventPublisher.emitAsync(events.bankTransactions.onExcluded, {
tenantId,
uncategorizedTransactionId,
} as IBankTransactionExcludedEventPayload);
await this.eventPublisher.emitAsync(
events.bankTransactions.onUnexcluded,
{
tenantId,
uncategorizedTransactionId,
} as IBankTransactionExcludedEventPayload
);
});
}
}
4 changes: 2 additions & 2 deletions packages/server/src/subscribers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export default {
onExcluding: 'onBankTransactionExclude',
onExcluded: 'onBankTransactionExcluded',

onUnexcluding: 'onBankTransactionExcluding',
onUnexcluded: 'onBankTransactionExcluded',
onUnexcluding: 'onBankTransactionUnexcluding',
onUnexcluded: 'onBankTransactionUnexcluded',
},
};

0 comments on commit b80bc95

Please sign in to comment.