Skip to main content
Skip to main content

CustomerService

Provides layer to manipulate customers.

constructor

Parameters

__namedParametersInjectedDependenciesRequired

Properties

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
customerRepository_Repository<Customer> & objectRequired
addressRepository_Repository<Address>Required
eventBusService_EventBusServiceRequired
EventsobjectRequired
Events.PASSWORD_RESETstringRequired

Default: "customer.password_reset"

Events.CREATEDstringRequired

Default: "customer.created"

Events.UPDATEDstringRequired

Default: "customer.updated"

__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

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

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

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

count

Return the total number of documents in database

Returns

PromisePromise<number>Required
the result of the count operation

retrieve_

Parameters

selectorSelector<Customer>Required
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

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

retrieveUnregisteredByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

retrieveRegisteredByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

Default: {}

Returns

PromisePromise<Customer>Required

listByEmail

Parameters

emailstringRequired
configFindConfig<Customer>Required

Returns

PromisePromise<Customer[]>Required

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.

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.

hashPassword_

Hashes a password

Parameters

passwordstringRequired
the value to hash

Returns

PromisePromise<string>Required
hashed password

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

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.

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

updateAddress

Parameters

customerIdstringRequired
addressIdstringRequired

Returns

PromisePromise<Address>Required

removeAddress

Parameters

customerIdstringRequired
addressIdstringRequired

Returns

PromisePromise<void>Required

addAddress

Parameters

customerIdstringRequired
addressAddressCreatePayloadRequired

Returns

PromisePromise<Customer | Address>Required

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.
Was this section helpful?