forked from vendure-ecommerce/vendure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Implemented CustomerAddressEvent with new entity event ba…
…se class (vendure-ecommerce#1219)
- Loading branch information
Kevin
committed
Nov 15, 2021
1 parent
b09b966
commit 469c6ac
Showing
2 changed files
with
30 additions
and
14 deletions.
There are no files selected for viewing
30 changes: 23 additions & 7 deletions
30
packages/core/src/event-bus/events/customer-address-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
import { RequestContext } from '../../api/common/request-context'; | ||
import { Address } from '../../entity/address/address.entity'; | ||
import { VendureEvent } from '../vendure-event'; | ||
import { CreateAddressInput, UpdateAddressInput } from '@vendure/common/lib/generated-types'; | ||
import { ID } from '@vendure/common/src/shared-types'; | ||
|
||
import { RequestContext } from '../../api'; | ||
import { Address } from '../../entity'; | ||
import { VendureEntityEvent } from '../vendure-entity-event'; | ||
|
||
type CustomerAddressInputTypes = CreateAddressInput | UpdateAddressInput | ID; | ||
|
||
/** | ||
* @description | ||
* This event is fired whenever a {@link Customer} is added, updated | ||
* This event is fired whenever a {@link Address} is added, updated | ||
* or deleted. | ||
* | ||
* @docsCategory events | ||
* @docsPage Event Types | ||
* @since 1.4 | ||
*/ | ||
export class CustomerAddressEvent extends VendureEvent { | ||
export class CustomerAddressEvent extends VendureEntityEvent<Address, CustomerAddressInputTypes> { | ||
constructor( | ||
public ctx: RequestContext, | ||
public address: Address, | ||
public entity: Address, | ||
public type: 'created' | 'updated' | 'deleted', | ||
public input?: CustomerAddressInputTypes, | ||
) { | ||
super(); | ||
super(entity, type, ctx); | ||
} | ||
|
||
/** | ||
* Return an address field to become compatible with the | ||
* deprecated old version of CustomerAddressEvent | ||
* @deprecated Use `entity` instead | ||
*/ | ||
get address(): Address { | ||
return this.entity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters