CustomerService
internal.internal.CustomerService
Provides layer to manipulate customers.
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredretrieve_
anyRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredEvents.PASSWORD_RESET
stringRequiredEvents.UPDATED
stringRequiredAccessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addAddress
addAddress(customerId
, address
): Promise
<Customer
| Address
>
Parameters
customerId
stringRequiredReturns
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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
<TResult
>
Promise
Promise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
count
count(): Promise
<number
>
Return the total number of documents in database
Returns
Promise
<number
>
Promise
Promise<number>Requiredthe result of the count operation
Promise
Promise<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
customerId
stringRequiredReturns
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
customerId
stringRequiredReturns
Promise
<string
>
Promise
Promise<string>Requiredthe generated JSON web token
Promise
Promise<string>RequiredhashPassword_
hashPassword_(password
): Promise
<string
>
Hashes a password
Parameters
password
stringRequiredReturns
Promise
<string
>
Promise
Promise<string>Requiredhashed password
Promise
Promise<string>Requiredlist
list(selector?
, config?
): Promise
<Customer
[]>
Parameters
config
FindConfig<Customer>Returns
Promise
<Customer
[]>
the result of the find operation
listAndCount
listAndCount(selector
, config?
): Promise
<[Customer
[], number
]>
Parameters
config
FindConfig<Customer>Returns
Promise
<[Customer
[], number
]>
the result of the find operation
listByEmail
listByEmail(email
, config?
): Promise
<Customer
[]>
Parameters
email
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
[]>
removeAddress
removeAddress(customerId
, addressId
): Promise
<void
>
Parameters
customerId
stringRequiredaddressId
stringRequiredReturns
Promise
<void
>
Promise
Promise<void>Requiredretrieve
retrieve(customerId
, config?
): Promise
<Customer
>
Gets a customer by id.
Parameters
customerId
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
>
the customer document.
retrieveByEmail
retrieveByEmail(email
, config?
): Promise
<Customer
>
Gets a registered customer by email.
Parameters
email
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
>
the customer document.
Deprecated
retrieveByPhone
retrieveByPhone(phone
, config?
): Promise
<Customer
>
Gets a customer by phone.
Parameters
phone
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
>
the customer document.
retrieveRegisteredByEmail
retrieveRegisteredByEmail(email
, config?
): Promise
<Customer
>
Parameters
email
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
>
retrieveUnregisteredByEmail
retrieveUnregisteredByEmail(email
, config?
): Promise
<Customer
>
Parameters
email
stringRequiredconfig
FindConfig<Customer>Returns
Promise
<Customer
>
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(customerId
, update
): Promise
<Customer
>
Updates a customer.
Parameters
customerId
stringRequiredReturns
Promise
<Customer
>
resolves to the update result.
updateAddress
updateAddress(customerId
, addressId
, address
): Promise
<Address
>
Parameters
customerId
stringRequiredaddressId
stringRequiredReturns
Promise
<Address
>
updateBillingAddress_
updateBillingAddress_(customer
, addressOrId
): Promise
<void
>
Updates the customers' billing address.
Parameters
Returns
Promise
<void
>
Promise
Promise<void>RequiredwithTransaction
withTransaction(transactionManager?
): CustomerService
Parameters
transactionManager
EntityManager