-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
560 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
import { Knex } from "knex"; | ||
|
||
export interface ExcludedBankTransactionsQuery { | ||
page?: number; | ||
pageSize?: number; | ||
accountId?: number; | ||
} | ||
} | ||
|
||
export interface IBankTransactionUnexcludingEventPayload { | ||
tenantId: number; | ||
uncategorizedTransactionId: number; | ||
trx?: Knex.Transaction | ||
} | ||
|
||
export interface IBankTransactionUnexcludedEventPayload { | ||
tenantId: number; | ||
uncategorizedTransactionId: number; | ||
trx?: Knex.Transaction | ||
} | ||
|
||
export interface IBankTransactionExcludingEventPayload { | ||
tenantId: number; | ||
uncategorizedTransactionId: number; | ||
trx?: Knex.Transaction | ||
} | ||
export interface IBankTransactionExcludedEventPayload { | ||
tenantId: number; | ||
uncategorizedTransactionId: number; | ||
trx?: Knex.Transaction | ||
} |
68 changes: 68 additions & 0 deletions
68
.../server/src/services/Banking/Exclude/events/DecrementUncategorizedTransactionOnExclude.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Inject, Service } from 'typedi'; | ||
import events from '@/subscribers/events'; | ||
import HasTenancyService from '@/services/Tenancy/TenancyService'; | ||
import { | ||
IBankTransactionExcludedEventPayload, | ||
IBankTransactionUnexcludedEventPayload, | ||
} from '../_types'; | ||
|
||
@Service() | ||
export class DecrementUncategorizedTransactionOnExclude { | ||
@Inject() | ||
private tenancy: HasTenancyService; | ||
/** | ||
* Constructor method. | ||
*/ | ||
public attach(bus) { | ||
bus.subscribe( | ||
events.bankTransactions.onExcluded, | ||
this.decrementUnCategorizedTransactionsOnExclude.bind(this) | ||
); | ||
bus.subscribe( | ||
events.bankTransactions.onUnexcluded, | ||
this.incrementUnCategorizedTransactionsOnUnexclude.bind(this) | ||
); | ||
} | ||
|
||
/** | ||
* Validates the cashflow transaction whether matched with bank transaction on deleting. | ||
* @param {IManualJournalDeletingPayload} | ||
*/ | ||
public async decrementUnCategorizedTransactionsOnExclude({ | ||
tenantId, | ||
uncategorizedTransactionId, | ||
trx, | ||
}: IBankTransactionExcludedEventPayload) { | ||
const { UncategorizedCashflowTransaction, Account } = | ||
this.tenancy.models(tenantId); | ||
|
||
const transaction = await UncategorizedCashflowTransaction.query( | ||
trx | ||
).findById(uncategorizedTransactionId); | ||
|
||
await Account.query(trx) | ||
.findById(transaction.accountId) | ||
.decrement('uncategorizedTransactions', 1); | ||
} | ||
|
||
/** | ||
* Validates the cashflow transaction whether matched with bank transaction on deleting. | ||
* @param {IManualJournalDeletingPayload} | ||
*/ | ||
public async incrementUnCategorizedTransactionsOnUnexclude({ | ||
tenantId, | ||
uncategorizedTransactionId, | ||
trx, | ||
}: IBankTransactionUnexcludedEventPayload) { | ||
const { UncategorizedCashflowTransaction, Account } = | ||
this.tenancy.models(tenantId); | ||
|
||
const transaction = await UncategorizedCashflowTransaction.query().findById( | ||
uncategorizedTransactionId | ||
); | ||
// | ||
await Account.query(trx) | ||
.findById(transaction.accountId) | ||
.increment('uncategorizedTransactions', 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.