mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
39 lines
1022 B
TypeScript
39 lines
1022 B
TypeScript
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
|
|
);
|
|
};
|
|
}
|