CustomerService
internal.internal.CustomerService
Provides layer to manipulate customers.
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>manager_EntityManagerRequiredretrieve_anyRequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredEvents.PASSWORD_RESETstringRequiredEvents.UPDATEDstringRequiredAccessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addAddress
addAddress(customerId, address): Promise<Customer | Address>
Parameters
customerIdstringRequiredReturns
atomicPhase_
Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>
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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
count
count(): Promise<number>
Return the total number of documents in database
Returns
Promise<number>
PromisePromise<number>Requiredthe result of the count operation
PromisePromise<number>Requiredcreate
create(customer): Promise<Customer>
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
Returns
Promise<Customer>
the result of create
delete
delete(customerId): Promise<void | Customer>
Deletes a customer from a given customer id.
Parameters
customerIdstringRequiredReturns
Promise<void | Customer>
the result of the delete operation.
generateResetPasswordToken
generateResetPasswordToken(customerId): Promise<string>
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
customerIdstringRequiredReturns
Promise<string>
PromisePromise<string>Requiredthe generated JSON web token
PromisePromise<string>RequiredhashPassword_
hashPassword_(password): Promise<string>
Hashes a password
Parameters
passwordstringRequiredReturns
Promise<string>
PromisePromise<string>Requiredhashed password
PromisePromise<string>Requiredlist
list(selector?, config?): Promise<Customer[]>
Parameters
configFindConfig<Customer>Returns
Promise<Customer[]>
the result of the find operation
listAndCount
listAndCount(selector, config?): Promise<[Customer[], number]>
Parameters
configFindConfig<Customer>Returns
Promise<[Customer[], number]>
the result of the find operation
listByEmail
listByEmail(email, config?): Promise<Customer[]>
Parameters
emailstringRequiredconfigFindConfig<Customer>Returns
Promise<Customer[]>
removeAddress
removeAddress(customerId, addressId): Promise<void>
Parameters
customerIdstringRequiredaddressIdstringRequiredReturns
Promise<void>
PromisePromise<void>Requiredretrieve
retrieve(customerId, config?): Promise<Customer>
Gets a customer by id.
Parameters
customerIdstringRequiredconfigFindConfig<Customer>Returns
Promise<Customer>
the customer document.
retrieveByEmail
retrieveByEmail(email, config?): Promise<Customer>
Gets a registered customer by email.
Parameters
emailstringRequiredconfigFindConfig<Customer>Returns
Promise<Customer>
the customer document.
Deprecated
retrieveByPhone
retrieveByPhone(phone, config?): Promise<Customer>
Gets a customer by phone.
Parameters
phonestringRequiredconfigFindConfig<Customer>Returns
Promise<Customer>
the customer document.
retrieveRegisteredByEmail
retrieveRegisteredByEmail(email, config?): Promise<Customer>
Parameters
emailstringRequiredconfigFindConfig<Customer>Returns
Promise<Customer>
retrieveUnregisteredByEmail
retrieveUnregisteredByEmail(email, config?): Promise<Customer>
Parameters
emailstringRequiredconfigFindConfig<Customer>Returns
Promise<Customer>
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(customerId, update): Promise<Customer>
Updates a customer.
Parameters
customerIdstringRequiredReturns
Promise<Customer>
resolves to the update result.
updateAddress
updateAddress(customerId, addressId, address): Promise<Address>
Parameters
customerIdstringRequiredaddressIdstringRequiredReturns
Promise<Address>
updateBillingAddress_
updateBillingAddress_(customer, addressOrId): Promise<void>
Updates the customers' billing address.
Parameters
Returns
Promise<void>
PromisePromise<void>RequiredwithTransaction
withTransaction(transactionManager?): CustomerService
Parameters
transactionManagerEntityManager