HistoryService
Contains methods relating to HistoryEntry entities. Histories are timelines of actions related to a particular Customer or Order, recording significant events such as creation, state changes, notes, etc.
Custom History Entry Types
Since Vendure v1.9.0, it is possible to define custom HistoryEntry types.
Let's take an example where we have some Customers who are businesses. We want to verify their tax ID in order to allow them wholesale rates. As part of this verification, we'd like to add an entry into the Customer's history with data about the tax ID verification.
First of all we'd extend the GraphQL HistoryEntryType enum for our new type as part of a plugin
Example
Next we need to create a TypeScript type definition file where we extend the CustomerHistoryEntryData interface. This is done
via TypeScript's declaration merging
and ambient modules features.
Example
Note: it works exactly the same way if we wanted to add a custom type for Order history, except in that case we'd extend the
OrderHistoryEntryData interface instead.
Now that we have our types set up, we can use the HistoryService to add a new HistoryEntry in a type-safe manner:
Example
It is also possible to define a UI component to display custom history entry types. See the Custom History Timeline Components guide.
constructor
(connection: TransactionalConnection, administratorService: AdministratorService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus) => HistoryServicegetHistoryForOrder
(ctx: RequestContext, orderId: ID, publicOnly: boolean, options?: HistoryEntryListOptions) => Promise<PaginatedList<OrderHistoryEntry>>createHistoryEntryForOrder
(args: CreateOrderHistoryEntryArgs<T>, isPublic: = true) => Promise<OrderHistoryEntry>getHistoryForCustomer
(ctx: RequestContext, customerId: ID, publicOnly: boolean, options?: HistoryEntryListOptions) => Promise<PaginatedList<CustomerHistoryEntry>>createHistoryEntryForCustomer
(args: CreateCustomerHistoryEntryArgs<T>, isPublic: = false) => Promise<CustomerHistoryEntry>updateOrderHistoryEntry
(ctx: RequestContext, args: UpdateOrderHistoryEntryArgs<T>) => deleteOrderHistoryEntry
(ctx: RequestContext, id: ID) => Promise<void>updateCustomerHistoryEntry
(ctx: RequestContext, args: UpdateCustomerHistoryEntryArgs<T>) => deleteCustomerHistoryEntry
(ctx: RequestContext, id: ID) => Promise<void>