mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import { InventoryTransactionsWarehouses } from './AcountsTransactionsWarehouses';
|
||||
import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class AccountsTransactionsWarehousesSubscribe {
|
||||
@Inject()
|
||||
accountsTransactionsWarehouses: InventoryTransactionsWarehouses;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
public attach = (bus) => {
|
||||
bus.subscribe(
|
||||
events.branch.onActivated,
|
||||
this.updateGLTransactionsToPrimaryBranchOnActivated
|
||||
);
|
||||
return bus;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates all GL transactions to primary branch once
|
||||
* the multi-branches activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
private updateGLTransactionsToPrimaryBranchOnActivated = async ({
|
||||
tenantId,
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) => {
|
||||
await this.accountsTransactionsWarehouses.updateTransactionsWithWarehouse(
|
||||
tenantId,
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user