CustomerService
CustomerService
Contains methods relating to Customer entities.
Signature
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[]>;
async getCustomerGroups(ctx: RequestContext, customerId: ID) => Promise<CustomerGroup[]>;
async create(ctx: RequestContext, input: CreateCustomerInput, password?: string) => Promise<ErrorResultUnion<CreateCustomerResult, Customer>>;
async update(ctx: RequestContext, input: UpdateCustomerShopInput & { id: ID }) => Promise<Customer>;
async update(ctx: RequestContext, input: UpdateCustomerInput) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>;
async update(ctx: RequestContext, input: UpdateCustomerInput | (UpdateCustomerShopInput & { id: ID })) => Promise<ErrorResultUnion<UpdateCustomerResult, Customer>>;
async registerCustomerAccount(ctx: RequestContext, input: RegisterCustomerInput) => Promise<RegisterCustomerAccountResult | EmailAddressConflictError | PasswordValidationError>;
async refreshVerificationToken(ctx: RequestContext, emailAddress: string) => Promise<void>;
async verifyCustomerEmailAddress(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, Customer>>;
async requestPasswordReset(ctx: RequestContext, emailAddress: string) => Promise<void>;
async resetPassword(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
>;
async requestUpdateEmailAddress(ctx: RequestContext, userId: ID, newEmailAddress: string) => Promise<boolean | EmailAddressConflictError>;
async updateEmailAddress(ctx: RequestContext, token: string) => Promise<boolean | IdentifierChangeTokenInvalidError | IdentifierChangeTokenExpiredError>;
async createOrUpdate(ctx: RequestContext, input: Partial<CreateCustomerInput> & { emailAddress: string }, errorOnExistingUser: boolean = false) => Promise<Customer | EmailAddressConflictError>;
async createAddress(ctx: RequestContext, customerId: ID, input: CreateAddressInput) => Promise<Address>;
async updateAddress(ctx: RequestContext, input: UpdateAddressInput) => Promise<Address>;
async deleteAddress(ctx: RequestContext, id: ID) => Promise<boolean>;
async softDelete(ctx: RequestContext, customerId: ID) => Promise<DeletionResponse>;
async createAddressesForNewCustomer(ctx: RequestContext, order: Order) => ;
async addNoteToCustomer(ctx: RequestContext, input: AddNoteToCustomerInput) => Promise<Customer>;
async updateCustomerNote(ctx: RequestContext, input: UpdateCustomerNoteInput) => Promise<HistoryEntry>;
async deleteCustomerNote(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
}
Members
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>
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[]>
getCustomerGroups
(ctx: RequestContext, customerId: ID) => Promise<CustomerGroup[]>
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>
verifyCustomerEmailAddress
(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, Customer>>
verified
as part of the account registration flow.
requestPasswordReset
(ctx: RequestContext, emailAddress: string) => Promise<void>
resetPassword()
method.
resetPassword
(ctx: RequestContext, passwordResetToken: string, password: string) => Promise< User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError >
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>
updateEmailAddress()
method to change the email address of the User &
Customer.
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>