CustomerService
Provides layer to manipulate customers.
Constructors
constructor
new CustomerService(«destructured»
)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "customer.created"
Events.PASSWORD_RESET
stringRequiredDefault: "customer.password_reset"
Events.UPDATED
stringRequiredDefault: "customer.updated"
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
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>Requiredcount
count(): Promise
<number
>
Return the total number of documents in database
Returns
Promise
<number
>
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
>
delete
delete(customerId
): Promise
<void
| Customer
>
Deletes a customer from a given customer id.
Parameters
customerId
stringRequiredReturns
Promise
<void
| Customer
>
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>RequiredhashPassword_
hashPassword_(password
): Promise
<string
>
Hashes a password
Parameters
password
stringRequiredReturns
Promise
<string
>
Promise
Promise<string>Requiredlist
list(selector?
, config?
): Promise
<Customer
[]>
Parameters
Default: {}
Returns
Promise
<Customer
[]>
listAndCount
listAndCount(selector
, config?
): Promise
<[Customer
[], number
]>
Parameters
Returns
Promise
<[Customer
[], number
]>
listByEmail
listByEmail(email
, config?
): Promise
<Customer
[]>
Parameters
email
stringRequiredReturns
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
stringRequiredDefault: {}
Returns
Promise
<Customer
>
retrieveByEmail
retrieveByEmail(email
, config?
): Promise
<Customer
>
Gets a registered customer by email.
Parameters
email
stringRequiredDefault: {}
Returns
Promise
<Customer
>
Deprecated
retrieveByPhone
retrieveByPhone(phone
, config?
): Promise
<Customer
>
Gets a customer by phone.
Parameters
phone
stringRequiredDefault: {}
Returns
Promise
<Customer
>
retrieveRegisteredByEmail
retrieveRegisteredByEmail(email
, config?
): Promise
<Customer
>
Parameters
email
stringRequiredDefault: {}
Returns
Promise
<Customer
>
retrieveUnregisteredByEmail
retrieveUnregisteredByEmail(email
, config?
): Promise
<Customer
>
Parameters
email
stringRequiredDefault: {}
Returns
Promise
<Customer
>
retrieve_
Private
retrieve_(selector
, config?
): Promise
<Customer
>
Parameters
Default: {}
Returns
Promise
<Customer
>
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
update(customerId
, update
): Promise
<Customer
>
Updates a customer.
Parameters
customerId
stringRequiredReturns
Promise
<Customer
>
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