|
|
@@ -22,6 +22,7 @@ import { TransactionalConnection } from '../../connection/transactional-connecti
|
|
|
import { OrderLine } from '../../entity/order-line/order-line.entity';
|
|
|
import { StockLevel } from '../../entity/stock-level/stock-level.entity';
|
|
|
import { StockLocation } from '../../entity/stock-location/stock-location.entity';
|
|
|
+import { EventBus, StockLocationEvent } from '../../event-bus/index';
|
|
|
import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
|
|
|
import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
|
|
|
import { RequestContextService } from '../helpers/request-context/request-context.service';
|
|
|
@@ -41,6 +42,7 @@ export class StockLocationService {
|
|
|
private configService: ConfigService,
|
|
|
private requestContextCache: RequestContextCacheService,
|
|
|
private customFieldRelationService: CustomFieldRelationService,
|
|
|
+ private eventBus: EventBus,
|
|
|
) {}
|
|
|
|
|
|
async initStockLocations() {
|
|
|
@@ -81,6 +83,7 @@ export class StockLocationService {
|
|
|
);
|
|
|
await this.channelService.assignToCurrentChannel(stockLocation, ctx);
|
|
|
await this.connection.getRepository(ctx, StockLocation).save(stockLocation);
|
|
|
+ await this.eventBus.publish(new StockLocationEvent(ctx, stockLocation, 'created', input));
|
|
|
return stockLocation;
|
|
|
}
|
|
|
|
|
|
@@ -94,6 +97,7 @@ export class StockLocationService {
|
|
|
input,
|
|
|
updatedStockLocation,
|
|
|
);
|
|
|
+ await this.eventBus.publish(new StockLocationEvent(ctx, updatedStockLocation, 'updated', input));
|
|
|
return assertFound(this.findOne(ctx, updatedStockLocation.id));
|
|
|
}
|
|
|
|
|
|
@@ -147,7 +151,11 @@ export class StockLocationService {
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
+ const deletedStockLocation = new StockLocation(stockLocation);
|
|
|
await this.connection.getRepository(ctx, StockLocation).remove(stockLocation);
|
|
|
+ await this.eventBus.publish(
|
|
|
+ new StockLocationEvent(ctx, deletedStockLocation, 'deleted', input.id),
|
|
|
+ );
|
|
|
} catch (e: any) {
|
|
|
return {
|
|
|
result: DeletionResult.NOT_DELETED,
|