Skip to content

Commit

Permalink
feat(core): Added multiple events (vendure-ecommerce#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin committed Nov 15, 2021
1 parent ce096c9 commit 573a32f
Show file tree
Hide file tree
Showing 53 changed files with 902 additions and 67 deletions.
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/administrator-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateAdministratorInput, UpdateAdministratorInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Administrator } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type AdministratorInputTypes = CreateAdministratorInput | UpdateAdministratorInput | ID;

/**
* @description
* This event is fired whenever a {@link Administrator} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class AdministratorEvent extends VendureEntityEvent<Administrator, AdministratorInputTypes> {
constructor(
ctx: RequestContext,
entity: Administrator,
type: 'created' | 'updated' | 'deleted',
input: AdministratorInputTypes,
) {
super(entity, type, ctx, input);
}
}
13 changes: 7 additions & 6 deletions packages/core/src/event-bus/events/asset-event.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { CreateAssetInput, DeleteAssetInput, UpdateAssetInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Asset } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type AssetInputTypes = CreateAssetInput | UpdateAssetInput | DeleteAssetInput;
type AssetInputTypes = CreateAssetInput | UpdateAssetInput | DeleteAssetInput | ID;

/**
* @description
* This event is fired whenever aa {@link Asset} is added, updated
* This event is fired whenever a {@link Asset} is added, updated
* or deleted. The `input` property is only defined for `'created'` & `'updated'` event types.
*
* @docsCategory events
Expand All @@ -17,10 +18,10 @@ type AssetInputTypes = CreateAssetInput | UpdateAssetInput | DeleteAssetInput;
*/
export class AssetEvent extends VendureEntityEvent<Asset, AssetInputTypes> {
constructor(
public ctx: RequestContext,
public entity: Asset,
public type: 'created' | 'updated' | 'deleted',
public input?: AssetInputTypes,
ctx: RequestContext,
entity: Asset,
type: 'created' | 'updated' | 'deleted',
input: AssetInputTypes,
) {
super(entity, type, ctx, input);
}
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/change-channel-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ID, Type } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { ChannelAware } from '../../common';
import { VendureEntity } from '../../entity';
import { VendureEvent } from '../vendure-event';

/**
* @description
* This event is fired whenever an {@link ChannelAware} entity is assigned or removed
* from a channel. The entity property contains the value before updating the channels.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class ChangeChannelEvent<T extends ChannelAware & VendureEntity> extends VendureEvent {
constructor(
public ctx: RequestContext,
public entity: T,
public channelIds: ID[],
public type: 'assigned' | 'removed',
public entityType?: Type<T>,
) {
super();
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/channel-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateChannelInput, UpdateChannelInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Channel } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type ChannelInputTypes = CreateChannelInput | UpdateChannelInput | ID;

/**
* @description
* This event is fired whenever a {@link Channel} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class ChannelEvent extends VendureEntityEvent<Channel, ChannelInputTypes> {
constructor(
ctx: RequestContext,
entity: Channel,
type: 'created' | 'updated' | 'deleted',
input: ChannelInputTypes,
) {
super(entity, type, ctx, input);
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/collection-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateCollectionInput, UpdateCollectionInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Collection } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CollectionInputTypes = CreateCollectionInput | UpdateCollectionInput | ID;

/**
* @description
* This event is fired whenever a {@link Collection} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CollectionEvent extends VendureEntityEvent<Collection, CollectionInputTypes> {
constructor(
ctx: RequestContext,
entity: Collection,
type: 'created' | 'updated' | 'deleted',
input: CollectionInputTypes,
) {
super(entity, type, ctx, input);
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/country-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateCountryInput, UpdateCountryInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Country } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CountryInputTypes = CreateCountryInput | UpdateCountryInput | ID;

/**
* @description
* This event is fired whenever a {@link Country} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CountryEvent extends VendureEntityEvent<Country, CountryInputTypes> {
constructor(
ctx: RequestContext,
entity: Country,
type: 'created' | 'updated' | 'deleted',
input: CountryInputTypes,
) {
super(entity, type, ctx, input);
}
}
24 changes: 24 additions & 0 deletions packages/core/src/event-bus/events/coupon-code-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api/common/request-context';
import { VendureEvent } from '../vendure-event';

/**
* @description
* This event is fired whenever an {@link Asset} is assigned or removed
* From a channel.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CouponCodeEvent extends VendureEvent {
constructor(
public ctx: RequestContext,
public couponCode: string,
public orderId: ID,
public type: 'assigned' | 'removed',
) {
super();
}
}
9 changes: 5 additions & 4 deletions packages/core/src/event-bus/events/customer-address-event.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CreateAddressInput, UpdateAddressInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Address } from '../../entity';
import { Address } from '../../entity/address/address.entity';
import { VendureEntityEvent } from '../vendure-entity-event';

/**
* Possible input types for Address mutations
*/
type CustomerAddressInputTypes = CreateAddressInput | UpdateAddressInput | string | number;
type CustomerAddressInputTypes = CreateAddressInput | UpdateAddressInput | ID;

/**
* @description
Expand All @@ -23,9 +24,9 @@ export class CustomerAddressEvent extends VendureEntityEvent<Address, CustomerAd
public ctx: RequestContext,
public entity: Address,
public type: 'created' | 'updated' | 'deleted',
public input?: CustomerAddressInputTypes,
public input: CustomerAddressInputTypes,
) {
super(entity, type, ctx);
super(entity, type, ctx, input);
}

/**
Expand Down
32 changes: 26 additions & 6 deletions packages/core/src/event-bus/events/customer-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { CreateCustomerInput, UpdateCustomerInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api/common/request-context';
import { Customer } from '../../entity/customer/customer.entity';
import { VendureEvent } from '../vendure-event';
import { VendureEntityEvent } from '../vendure-entity-event';

type CustomerInputTypes =
| CreateCustomerInput
| UpdateCustomerInput
| (Partial<CreateCustomerInput> & { emailAddress: string })
| ID;

/**
* @description
Expand All @@ -10,12 +19,23 @@ import { VendureEvent } from '../vendure-event';
* @docsCategory events
* @docsPage Event Types
*/
export class CustomerEvent extends VendureEvent {
export class CustomerEvent extends VendureEntityEvent<Customer, CustomerInputTypes> {
constructor(
public ctx: RequestContext,
public customer: Customer,
public type: 'created' | 'updated' | 'deleted',
ctx: RequestContext,
entity: Customer,
type: 'created' | 'updated' | 'deleted',
input: CustomerInputTypes,
) {
super();
super(entity, type, ctx, input);
}

/**
* Return an customer field to become compatible with the
* deprecated old version of CustomerEvent
* @deprecated Use `entity` instead
* @since 1.4
*/
get customer(): Customer {
return this.entity;
}
}
28 changes: 28 additions & 0 deletions packages/core/src/event-bus/events/customer-group-entity-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CreateCustomerGroupInput, UpdateCustomerGroupInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { CustomerGroup } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CustomerGroupInputTypes = CreateCustomerGroupInput | UpdateCustomerGroupInput | ID;

/**
* @description
* This event is fired whenever a {@link CustomerGroup} is added, updated or deleted.
* This Entity shall replace the {@link CustomerGroupEvent} later!
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CustomerGroupEntityEvent extends VendureEntityEvent<CustomerGroup, CustomerGroupInputTypes> {
constructor(
ctx: RequestContext,
entity: CustomerGroup,
type: 'created' | 'updated' | 'deleted',
input: CustomerGroupInputTypes,
) {
super(entity, type, ctx, input);
}
}
21 changes: 21 additions & 0 deletions packages/core/src/event-bus/events/customer-group-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VendureEvent } from '../vendure-event';
*
* @docsCategory events
* @docsPage Event Types
* @deprecated Use {@link CustomerGroupChangeEvent} instead
*/
export class CustomerGroupEvent extends VendureEvent {
constructor(
Expand All @@ -21,3 +22,23 @@ export class CustomerGroupEvent extends VendureEvent {
super();
}
}

/**
* @description
* This event is fired whenever one or more {@link Customer} is assigned to or removed from a
* {@link CustomerGroup}.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CustomerGroupChangeEvent extends VendureEvent {
constructor(
public ctx: RequestContext,
public customers: Customer[],
public customGroup: CustomerGroup,
public type: 'assigned' | 'removed',
) {
super();
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/facet-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateFacetInput, UpdateFacetInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Facet } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type FacetInputTypes = CreateFacetInput | UpdateFacetInput | ID;

/**
* @description
* This event is fired whenever a {@link Facet} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class FacetEvent extends VendureEntityEvent<Facet, FacetInputTypes> {
constructor(
ctx: RequestContext,
entity: Facet,
type: 'created' | 'updated' | 'deleted',
input: FacetInputTypes,
) {
super(entity, type, ctx, input);
}
}
35 changes: 35 additions & 0 deletions packages/core/src/event-bus/events/facet-value-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
CreateFacetValueInput,
CreateFacetValueWithFacetInput,
UpdateFacetValueInput,
} from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { FacetValue } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type FacetValueInputTypes =
| CreateFacetValueInput
| CreateFacetValueWithFacetInput
| UpdateFacetValueInput
| ID;

/**
* @description
* This event is fired whenever a {@link FacetValue} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class FacetValueEvent extends VendureEntityEvent<FacetValue, FacetValueInputTypes> {
constructor(
ctx: RequestContext,
entity: FacetValue,
type: 'created' | 'updated' | 'deleted',
input: FacetValueInputTypes,
) {
super(entity, type, ctx, input);
}
}
Loading

0 comments on commit 573a32f

Please sign in to comment.