Skip to main content
Skip to main content

CustomerService

Provides layer to manipulate customers.

constructor

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
addressRepository_Repository<Address>Required
customerRepository_Repository<Customer> & objectRequired
eventBusService_EventBusServiceRequired
manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "customer.created"

Events.PASSWORD_RESETstringRequired

Default: "customer.password_reset"

Events.UPDATEDstringRequired

Default: "customer.updated"


Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

addAddress

Parameters

customerIdstringRequired
addressAddressCreatePayloadRequired

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.

Type Parameters

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

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> & objectRequired
the query object for find

Default: {}

configFindConfig<Customer>Required
the config object containing query settings

Returns

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

listAndCount

Parameters

selectorSelector<Customer> & objectRequired
the query object for find
configFindConfig<Customer>Required
the config object containing query settings

Returns

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

listByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

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.
configFindConfig<Customer>Required
the config object containing query settings

Default: {}

Returns

PromisePromise<Customer>Required
the customer document.

retrieveByEmail

Gets a registered customer by email.

Parameters

emailstringRequired
the email of the customer to get.
configFindConfig<Customer>Required
the config object containing query settings

Default: {}

Returns

PromisePromise<Customer>Required
the customer document.

Deprecated


retrieveByPhone

Gets a customer by phone.

Parameters

phonestringRequired
the phone of the customer to get.
configFindConfig<Customer>Required
the config object containing query settings

Default: {}

Returns

PromisePromise<Customer>Required
the customer document.

retrieveRegisteredByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

retrieveUnregisteredByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

retrieve_

Parameters

selectorSelector<Customer>Required
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

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

CustomerServiceobjectRequired
Provides layer to manipulate customers.
Was this section helpful?