CustomerService
CustomerService
Contains methods relating to Customer entities.
class CustomerService {
constructor(connection: TransactionalConnection, configService: ConfigService, userService: UserService, countryService: CountryService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus, historyService: HistoryService, channelService: ChannelService, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService)
findAll(ctx: RequestContext, options: ListQueryOptions<Customer> | undefined, relations: RelationPaths<Customer> = []) => Promise<PaginatedList<Customer>>;
findOne(ctx: RequestContext, id: ID, relations: RelationPaths<Customer> = []) => Promise<Customer | undefined>;
findOneByUserId(ctx: RequestContext, userId: ID, filterOnChannel: = true) => Promise<Customer | undefined>;
findAddressesByCustomerId(ctx: RequestContext, customerId: ID) => Promise<Address[]>;
getCustomerGroups(ctx: RequestContext, customerId: ID) => Promise<CustomerGroup[]>;
create(ctx: RequestContext, input: CreateCustomerInput, password?: string) => Promise<ErrorResultUnion<CreateCustomerResult, Customer>>;
update(ctx: RequestContext, input: UpdateCustomerShopInput & { id: ID }) => Promise<Customer>;
update(ctx: RequestContext, input: UpdateCustomerInput) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>;
update(ctx: RequestContext, input: UpdateCustomerInput | (UpdateCustomerShopInput & { id: ID })) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>;
registerCustomerAccount(ctx: RequestContext, input: RegisterCustomerInput) => Promise<RegisterCustomerAccountResult | EmailAddressConflictError | PasswordValidationError>;
refreshVerificationToken(ctx: RequestContext, emailAddress: string) => Promise<void>;
verifyCustomerEmailAddress(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, Customer>>;
requestPasswordReset(ctx: RequestContext, emailAddress: string) => Promise<void>;
resetPassword(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
>;
requestUpdateEmailAddress(ctx: RequestContext, userId: ID, newEmailAddress: string) => Promise<boolean | EmailAddressConflictError>;
updateEmailAddress(ctx: RequestContext, token: string) => Promise<boolean | IdentifierChangeTokenInvalidError | IdentifierChangeTokenExpiredError>;
createOrUpdate(ctx: RequestContext, input: Partial<CreateCustomerInput> & { emailAddress: string }, errorOnExistingUser: boolean = false) => Promise<Customer | EmailAddressConflictError>;
createAddress(ctx: RequestContext, customerId: ID, input: CreateAddressInput) => Promise<Address>;
updateAddress(ctx: RequestContext, input: UpdateAddressInput) => Promise<Address>;
deleteAddress(ctx: RequestContext, id: ID) => Promise<boolean>;
softDelete(ctx: RequestContext, customerId: ID) => Promise<DeletionResponse>;
createAddressesForNewCustomer(ctx: RequestContext, order: Order) => ;
addNoteToCustomer(ctx: RequestContext, input: AddNoteToCustomerInput) => Promise<Customer>;
updateCustomerNote(ctx: RequestContext, input: UpdateCustomerNoteInput) => Promise<HistoryEntry>;
deleteCustomerNote(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
}
constructor
(connection: TransactionalConnection, configService: ConfigService, userService: UserService, countryService: CountryService, listQueryBuilder: ListQueryBuilder, eventBus: EventBus, historyService: HistoryService, channelService: ChannelService, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService) => CustomerService
findAll
(ctx: RequestContext, options: ListQueryOptions<Customer> | undefined, relations: RelationPaths<Customer> = []) => Promise<PaginatedList<Customer>>
findOne
(ctx: RequestContext, id: ID, relations: RelationPaths<Customer> = []) => Promise<Customer | undefined>
findOneByUserId
(ctx: RequestContext, userId: ID, filterOnChannel: = true) => Promise<Customer | undefined>
Returns the Customer entity associated with the given userId, if one exists.
Setting filterOnChannel
to true
will limit the results to Customers which are assigned
to the current active Channel only.
findAddressesByCustomerId
(ctx: RequestContext, customerId: ID) => Promise<Address[]>
Returns all Address entities associated with the specified Customer.
getCustomerGroups
(ctx: RequestContext, customerId: ID) => Promise<CustomerGroup[]>
Returns a list of all CustomerGroup entities.
create
(ctx: RequestContext, input: CreateCustomerInput, password?: string) => Promise<ErrorResultUnion<CreateCustomerResult, Customer>>
Creates a new Customer, including creation of a new User with the special customer
Role.
If the password
argument is specified, the Customer will be immediately verified. If not,
then an AccountRegistrationEvent is published, so that the customer can have their
email address verified and set their password in a later step using the verifyCustomerEmailAddress()
method.
This method is intended to be used in admin-created Customer flows.
update
(ctx: RequestContext, input: UpdateCustomerShopInput & { id: ID }) => Promise<Customer>
update
(ctx: RequestContext, input: UpdateCustomerInput) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>
update
(ctx: RequestContext, input: UpdateCustomerInput | (UpdateCustomerShopInput & { id: ID })) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>
registerCustomerAccount
(ctx: RequestContext, input: RegisterCustomerInput) => Promise<RegisterCustomerAccountResult | EmailAddressConflictError | PasswordValidationError>
Registers a new Customer account with the NativeAuthenticationStrategy and starts
the email verification flow (unless AuthOptions requireVerification
is set to false
)
by publishing an AccountRegistrationEvent.
This method is intended to be used in storefront Customer-creation flows.
refreshVerificationToken
(ctx: RequestContext, emailAddress: string) => Promise<void>
Refreshes a stale email address verification token by generating a new one and publishing a AccountRegistrationEvent.
verifyCustomerEmailAddress
(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, Customer>>
Given a valid verification token which has been published in an AccountRegistrationEvent, this
method is used to set the Customer as verified
as part of the account registration flow.
requestPasswordReset
(ctx: RequestContext, emailAddress: string) => Promise<void>
Publishes a new PasswordResetEvent for the given email address. This event creates
a token which can be used in the resetPassword()
method.
resetPassword
(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
>
Given a valid password reset token created by a call to the requestPasswordReset()
method,
this method will change the Customer's password to that given as the password
argument.
requestUpdateEmailAddress
(ctx: RequestContext, userId: ID, newEmailAddress: string) => Promise<boolean | EmailAddressConflictError>
Publishes a IdentifierChangeRequestEvent for the given User. This event contains a token
which is then used in the updateEmailAddress()
method to change the email address of the User &
Customer.
updateEmailAddress
(ctx: RequestContext, token: string) => Promise<boolean | IdentifierChangeTokenInvalidError | IdentifierChangeTokenExpiredError>
Given a valid email update token published in a IdentifierChangeRequestEvent, this method will update the Customer & User email address.
createOrUpdate
(ctx: RequestContext, input: Partial<CreateCustomerInput> & { emailAddress: string }, errorOnExistingUser: boolean = false) => Promise<Customer | EmailAddressConflictError>
For guest checkouts, we assume that a matching email address is the same customer.
createAddress
(ctx: RequestContext, customerId: ID, input: CreateAddressInput) => Promise<Address>
Creates a new Address for the given Customer.
updateAddress
(ctx: RequestContext, input: UpdateAddressInput) => Promise<Address>
deleteAddress
(ctx: RequestContext, id: ID) => Promise<boolean>
softDelete
(ctx: RequestContext, customerId: ID) => Promise<DeletionResponse>
createAddressesForNewCustomer
(ctx: RequestContext, order: Order) =>
If the Customer associated with the given Order does not yet have any Addresses, this method will create new Address(es) based on the Order's shipping & billing addresses.
addNoteToCustomer
(ctx: RequestContext, input: AddNoteToCustomerInput) => Promise<Customer>
updateCustomerNote
(ctx: RequestContext, input: UpdateCustomerNoteInput) => Promise<HistoryEntry>
deleteCustomerNote
(ctx: RequestContext, id: ID) => Promise<DeletionResponse>