Skip to main content
Skip to main content

CustomerService

internal.internal.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_

Protected get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

Methods

addAddress

addAddress(customerId, address): Promise<Customer | Address>

Parameters

customerIdstringRequired
addressAddressCreatePayloadRequired

Returns

Promise<Customer | Address>

PromisePromise<Customer | Address>Required

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.

TResultobjectRequired
TErrorobjectRequired

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_


count

count(): Promise<number>

Return the total number of documents in database

Returns

Promise<number>

PromisePromise<number>Required
the result of the count operation

create

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

customerCreateCustomerInputRequired
the customer to create

Returns

Promise<Customer>

PromisePromise<Customer>Required
the result of create

delete

delete(customerId): Promise<void | Customer>

Deletes a customer from a given customer id.

Parameters

customerIdstringRequired
the id of the customer to delete. Must be castable as an ObjectId

Returns

Promise<void | Customer>

PromisePromise<void | Customer>Required
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

customerIdstringRequired
the customer to reset the password for

Returns

Promise<string>

PromisePromise<string>Required
the generated JSON web token

hashPassword_

hashPassword_(password): Promise<string>

Hashes a password

Parameters

passwordstringRequired
the value to hash

Returns

Promise<string>

PromisePromise<string>Required
hashed password

list

list(selector?, config?): Promise<Customer[]>

Parameters

selectorSelector<Customer> & { groups?: string[] ; q?: string }
the query object for find
the config object containing query settings

Returns

Promise<Customer[]>

PromisePromise<Customer[]>Required
the result of the find operation

listAndCount

listAndCount(selector, config?): Promise<[Customer[], number]>

Parameters

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

Returns

Promise<[Customer[], number]>

PromisePromise<[Customer[], number]>Required
the result of the find operation

listByEmail

listByEmail(email, config?): Promise<Customer[]>

Parameters

emailstringRequired

Returns

Promise<Customer[]>

PromisePromise<Customer[]>Required

removeAddress

removeAddress(customerId, addressId): Promise<void>

Parameters

customerIdstringRequired
addressIdstringRequired

Returns

Promise<void>

PromisePromise<void>Required

retrieve

retrieve(customerId, config?): Promise<Customer>

Gets a customer by id.

Parameters

customerIdstringRequired
the id of the customer to get.
the config object containing query settings

Returns

Promise<Customer>

PromisePromise<Customer>Required
the customer document.

retrieveByEmail

retrieveByEmail(email, config?): Promise<Customer>

Gets a registered customer by email.

Parameters

emailstringRequired
the email of the customer to get.
the config object containing query settings

Returns

Promise<Customer>

PromisePromise<Customer>Required
the customer document.

Deprecated


retrieveByPhone

retrieveByPhone(phone, config?): Promise<Customer>

Gets a customer by phone.

Parameters

phonestringRequired
the phone of the customer to get.
the config object containing query settings

Returns

Promise<Customer>

PromisePromise<Customer>Required
the customer document.

retrieveRegisteredByEmail

retrieveRegisteredByEmail(email, config?): Promise<Customer>

Parameters

emailstringRequired

Returns

Promise<Customer>

PromisePromise<Customer>Required

retrieveUnregisteredByEmail

retrieveUnregisteredByEmail(email, config?): Promise<Customer>

Parameters

emailstringRequired

Returns

Promise<Customer>

PromisePromise<Customer>Required

shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

booleanboolean

Inherited from

TransactionBaseService.shouldRetryTransaction_


update

update(customerId, update): Promise<Customer>

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

Promise<Customer>

PromisePromise<Customer>Required
resolves to the update result.

updateAddress

updateAddress(customerId, addressId, address): Promise<Address>

Parameters

customerIdstringRequired
addressIdstringRequired

Returns

Promise<Address>

PromisePromise<Address>Required

updateBillingAddress_

updateBillingAddress_(customer, addressOrId): Promise<void>

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

Promise<void>

PromisePromise<void>Required
the result of the update operation

withTransaction

withTransaction(transactionManager?): CustomerService

Parameters

transactionManagerEntityManager

Returns

CustomerService

CustomerServiceCustomerServiceRequired

Inherited from

TransactionBaseService.withTransaction

Was this section helpful?