|
|
@@ -17,6 +17,8 @@ import { UserInputError } from '../../common/error/errors';
|
|
|
import { assertFound, idsAreEqual } from '../../common/utils';
|
|
|
import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
|
|
|
import { Customer } from '../../entity/customer/customer.entity';
|
|
|
+import { EventBus } from '../../event-bus/event-bus';
|
|
|
+import { CustomerGroupEvent } from '../../event-bus/events/customer-group-event';
|
|
|
import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
|
|
|
import { patchEntity } from '../helpers/utils/patch-entity';
|
|
|
import { TransactionalConnection } from '../transaction/transactional-connection';
|
|
|
@@ -29,6 +31,7 @@ export class CustomerGroupService {
|
|
|
private connection: TransactionalConnection,
|
|
|
private listQueryBuilder: ListQueryBuilder,
|
|
|
private historyService: HistoryService,
|
|
|
+ private eventBus: EventBus,
|
|
|
) {}
|
|
|
|
|
|
findAll(ctx: RequestContext, options?: CustomerGroupListOptions): Promise<PaginatedList<CustomerGroup>> {
|
|
|
@@ -122,6 +125,7 @@ export class CustomerGroupService {
|
|
|
}
|
|
|
|
|
|
await this.connection.getRepository(ctx, Customer).save(customers, { reload: false });
|
|
|
+ this.eventBus.publish(new CustomerGroupEvent(ctx, customers, group, 'assigned'));
|
|
|
return assertFound(this.findOne(ctx, group.id));
|
|
|
}
|
|
|
|
|
|
@@ -146,6 +150,7 @@ export class CustomerGroupService {
|
|
|
});
|
|
|
}
|
|
|
await this.connection.getRepository(ctx, Customer).save(customers, { reload: false });
|
|
|
+ this.eventBus.publish(new CustomerGroupEvent(ctx, customers, group, 'removed'));
|
|
|
return assertFound(this.findOne(ctx, group.id));
|
|
|
}
|
|
|
|