mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-24 08:39:49 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
import { UpdateInventoryTransactionsWithWarehouse } from './UpdateInventoryTransactionsWithWarehouse';
|
||||
import { CreateInitialWarehousesItemsQuantity } from './CreateInitialWarehousesitemsQuantity';
|
||||
|
||||
@Service()
|
||||
export class ActivateWarehousesSubscriber {
|
||||
@Inject()
|
||||
private updateInventoryTransactionsWithWarehouse: UpdateInventoryTransactionsWithWarehouse;
|
||||
|
||||
@Inject()
|
||||
private createInitialWarehousesItemsQuantity: CreateInitialWarehousesItemsQuantity;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
attach(bus) {
|
||||
bus.subscribe(
|
||||
events.warehouse.onActivated,
|
||||
this.updateInventoryTransactionsWithWarehouseOnActivating
|
||||
);
|
||||
bus.subscribe(
|
||||
events.warehouse.onActivated,
|
||||
this.createInitialWarehousesItemsQuantityOnActivating
|
||||
);
|
||||
return bus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates inventory transactiont to primary warehouse once
|
||||
* multi-warehouses activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
private updateInventoryTransactionsWithWarehouseOnActivating = async ({
|
||||
tenantId,
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) => {
|
||||
await this.updateInventoryTransactionsWithWarehouse.run(
|
||||
tenantId,
|
||||
primaryWarehouse.id
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates initial warehouses items quantity once the multi-warehouses activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
private createInitialWarehousesItemsQuantityOnActivating = async ({
|
||||
tenantId,
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) => {
|
||||
await this.createInitialWarehousesItemsQuantity.run(
|
||||
tenantId,
|
||||
primaryWarehouse.id
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user