Skip to main content
Skip to main content

CustomerService

Provides layer to manipulate customers.

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
addressRepository_Repository<Address>Required
customerRepository_Repository<Customer> & { listAndCount: Method listAndCount }Required
eventBusService_EventBusServiceRequired
manager_EntityManagerRequired
retrieve_anyRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired
Events.PASSWORD_RESETstringRequired
Events.UPDATEDstringRequired

Accessors

activeManager_

Inherited from

TransactionBaseService.activeManager_

Methods

addAddress

Parameters
customerIdstringRequired
addressAddressCreatePayloadRequired
Address fields used when creating an address.
Returns
PromisePromise<Customer | Address>Required

atomicPhase_

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Parameters
work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler
Returns
PromisePromise<TResult>Required
the result of the transactional work

count

Return the total number of documents in database

Returns
PromisePromise<number>Required
the result of the count operation

create

Creates a customer from an email - customers can have accounts associated, e.g. to login and view order history, etc. If a password is provided the customer will automatically get an account, otherwise the customer is just used to hold details of customers.

Parameters
customerCreateCustomerInputRequired
the customer to create
Returns
PromisePromise<Customer>Required
the result of create

delete

Deletes a customer from a given customer id.

Parameters
customerIdstringRequired
the id of the customer to delete. Must be castable as an ObjectId
Returns
PromisePromise<void | Customer>Required
the result of the delete operation.

generateResetPasswordToken

Generate a JSON Web token, that will be sent to a customer, that wishes to reset password. The token will be signed with the customer's current password hash as a secret a long side a payload with userId and the expiry time for the token, which is always 15 minutes.

Parameters
customerIdstringRequired
the customer to reset the password for
Returns
PromisePromise<string>Required
the generated JSON web token

hashPassword_

Hashes a password

Parameters
passwordstringRequired
the value to hash
Returns
PromisePromise<string>Required
hashed password

list

Parameters
selectorSelector<Customer> & { groups?: string[] ; q?: string }
the query object for find
the config object containing query settings
Returns
PromisePromise<Customer[]>Required
the result of the find operation

listAndCount

Parameters
selectorSelector<Customer> & { groups?: string[] ; q?: string }Required
the query object for find
the config object containing query settings
Returns
PromisePromise<[Customer[], number]>Required
the result of the find operation

listByEmail

Parameters
emailstringRequired
Returns
PromisePromise<Customer[]>Required

removeAddress

Parameters
customerIdstringRequired
addressIdstringRequired
Returns
PromisePromise<void>Required

retrieve

Gets a customer by id.

Parameters
customerIdstringRequired
the id of the customer to get.
the config object containing query settings
Returns
PromisePromise<Customer>Required
the customer document.

retrieveByEmail

Gets a registered customer by email.

Parameters
emailstringRequired
the email of the customer to get.
the config object containing query settings
Returns
PromisePromise<Customer>Required
the customer document.

Deprecated


retrieveByPhone

Gets a customer by phone.

Parameters
phonestringRequired
the phone of the customer to get.
the config object containing query settings
Returns
PromisePromise<Customer>Required
the customer document.

retrieveRegisteredByEmail

Parameters
emailstringRequired
Returns
PromisePromise<Customer>Required

retrieveUnregisteredByEmail

Parameters
emailstringRequired
Returns
PromisePromise<Customer>Required

shouldRetryTransaction_

Parameters
errRecord<string, unknown> | { code: string }Required
Returns
booleanboolean

update

Updates a customer.

Parameters
customerIdstringRequired
the id of the variant. Must be a string that can be casted to an ObjectId
updateUpdateCustomerInputRequired
an object with the update values.
Returns
PromisePromise<Customer>Required
resolves to the update result.

updateAddress

Parameters
customerIdstringRequired
addressIdstringRequired
Returns
PromisePromise<Address>Required

updateBillingAddress_

Updates the customers' billing address.

Parameters
customerCustomerRequired
the Customer to update
addressOrIdundefined | string | DeepPartial<Address>Required
the value to set the billing address to
Returns
PromisePromise<void>Required
the result of the update operation

withTransaction

Parameters
transactionManagerEntityManager
Returns
CustomerServiceCustomerServiceRequired
Was this section helpful?