CustomerService
Provides layer to manipulate customers.
Hierarchy
- TransactionBaseService- ↳ - CustomerService
Constructors
constructor
new CustomerService(«destructured»)
Parameters
| Name | 
|---|
| «destructured» | 
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/customer.ts:46
Properties
__configModule__
 Protected Optional Readonly __configModule__: Record<string, unknown>
Inherited from
TransactionBaseService.__configModule__
Defined in
medusa/src/interfaces/transaction-base-service.ts:14
__container__
 Protected Readonly __container__: any
Inherited from
TransactionBaseService.__container__
Defined in
medusa/src/interfaces/transaction-base-service.ts:13
__moduleDeclaration__
 Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
medusa/src/interfaces/transaction-base-service.ts:15
addressRepository_
 Protected Readonly addressRepository_: Repository<Address>
Defined in
medusa/src/services/customer.ts:37
customerRepository_
 Protected Readonly customerRepository_: Repository<Customer> & { listAndCount: Method listAndCount  }
Defined in
medusa/src/services/customer.ts:36
eventBusService_
 Protected Readonly eventBusService_: EventBusService
Defined in
medusa/src/services/customer.ts:38
manager_
 Protected manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:5
transactionManager_
 Protected transactionManager_: undefined | EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:6
Events
 Static Events: Object
Type declaration
| Name | Type | 
|---|---|
| CREATED | string | 
| PASSWORD_RESET | string | 
| UPDATED | string | 
Defined in
medusa/src/services/customer.ts:40
Accessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
-EntityManager: 
Inherited from
TransactionBaseService.activeManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:8
Methods
addAddress
addAddress(customerId, address): Promise<Customer | Address>
Parameters
| Name | 
|---|
| customerId | 
| address | 
Returns
Promise<Customer | Address>
-Promise:
-Customer \| Address: (optional) 
Defined in
medusa/src/services/customer.ts:519
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.
| Name | 
|---|
| TResult | 
| TError | 
Parameters
| Name | Description | 
|---|---|
| work | ( transactionManager:EntityManager) =>Promise<TResult> | 
| isolationOrErrorHandler? | IsolationLevel| (error:TError) =>Promise<void|TResult> | 
| maybeErrorHandlerOrDontFail? | ( error:TError) =>Promise<void|TResult> | 
Returns
Promise<TResult>
-Promise: the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
medusa/src/interfaces/transaction-base-service.ts:56
count
count(): Promise<number>
Return the total number of documents in database
Returns
Promise<number>
-Promise: the result of the count operation
-number: (optional) 
Defined in
medusa/src/services/customer.ts:178
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
| Name | Description | 
|---|---|
| customer | CreateCustomerInput | 
Returns
Promise<Customer>
-Promise: the result of create
-Customer: 
Defined in
medusa/src/services/customer.ts:306
delete
delete(customerId): Promise<void | Customer>
Deletes a customer from a given customer id.
Parameters
| Name | Description | 
|---|---|
| customerId | string | 
Returns
Promise<void | Customer>
-Promise: the result of the delete operation.
-void \| Customer: (optional) 
Defined in
medusa/src/services/customer.ts:565
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
| Name | Description | 
|---|---|
| customerId | string | 
Returns
Promise<string>
-Promise: the generated JSON web token
-string: (optional) 
Defined in
medusa/src/services/customer.ts:68
hashPassword_
hashPassword_(password): Promise<string>
Hashes a password
Parameters
| Name | Description | 
|---|---|
| password | string | 
Returns
Promise<string>
-Promise: hashed password
-string: (optional) 
Defined in
medusa/src/services/customer.ts:293
list
list(selector?, config?): Promise<Customer[]>
Parameters
| Name | Description | 
|---|---|
| selector | Selector<Customer> & {groups?:string[] ;q?:string} | 
| config | FindConfig<Customer> | 
Returns
Promise<Customer[]>
-Promise: the result of the find operation
-Customer[]:
-Customer: 
Defined in
medusa/src/services/customer.ts:111
listAndCount
listAndCount(selector, config?): Promise<[Customer[], number]>
Parameters
| Name | Description | 
|---|---|
| selector | Selector<Customer> & {groups?:string[] ;q?:string} | 
| config | FindConfig<Customer> | 
Returns
Promise<[Customer[], number]>
-Promise: the result of the find operation
-Customer[]:
-number: (optional) 
Defined in
medusa/src/services/customer.ts:143
listByEmail
listByEmail(email, config?): Promise<Customer[]>
Parameters
| Name | 
|---|
| email | 
| config | 
Returns
Promise<Customer[]>
-Promise:
-Customer[]:
-Customer: 
Defined in
medusa/src/services/customer.ts:249
removeAddress
removeAddress(customerId, addressId): Promise<void>
Parameters
| Name | 
|---|
| customerId | 
| addressId | 
Returns
Promise<void>
-Promise: 
Defined in
medusa/src/services/customer.ts:502
retrieve
retrieve(customerId, config?): Promise<Customer>
Gets a customer by id.
Parameters
| Name | Description | 
|---|---|
| customerId | string | 
| config | FindConfig<Customer> | 
Returns
Promise<Customer>
-Promise: the customer document.
-Customer: 
Defined in
medusa/src/services/customer.ts:274
retrieveByEmail
retrieveByEmail(email, config?): Promise<Customer>
Gets a registered customer by email.
Parameters
| Name | Description | 
|---|---|
| email | string | 
| config | FindConfig<Customer> | 
Returns
Promise<Customer>
-Promise: the customer document.
-Customer: 
Deprecated
Defined in
medusa/src/services/customer.ts:216
retrieveByPhone
retrieveByPhone(phone, config?): Promise<Customer>
Gets a customer by phone.
Parameters
| Name | Description | 
|---|---|
| phone | string | 
| config | FindConfig<Customer> | 
Returns
Promise<Customer>
-Promise: the customer document.
-Customer: 
Defined in
medusa/src/services/customer.ts:261
retrieveRegisteredByEmail
retrieveRegisteredByEmail(email, config?): Promise<Customer>
Parameters
| Name | 
|---|
| email | 
| config | 
Returns
Promise<Customer>
-Promise:
-Customer: 
Defined in
medusa/src/services/customer.ts:239
retrieveUnregisteredByEmail
retrieveUnregisteredByEmail(email, config?): Promise<Customer>
Parameters
| Name | 
|---|
| email | 
| config | 
Returns
Promise<Customer>
-Promise:
-Customer: 
Defined in
medusa/src/services/customer.ts:230
retrieve_
Private retrieve_(selector, config?): Promise<Customer>
Parameters
| Name | 
|---|
| selector | 
| config | 
Returns
Promise<Customer>
-Promise:
-Customer: 
Defined in
medusa/src/services/customer.ts:185
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
| Name | 
|---|
| err | 
Returns
boolean
-boolean: (optional) 
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
update
update(customerId, update): Promise<Customer>
Updates a customer.
Parameters
| Name | Description | 
|---|---|
| customerId | string | 
| update | UpdateCustomerInput | 
Returns
Promise<Customer>
-Promise: resolves to the update result.
-Customer: 
Defined in
medusa/src/services/customer.ts:362
updateAddress
updateAddress(customerId, addressId, address): Promise<Address>
Parameters
| Name | 
|---|
| customerId | 
| addressId | 
| address | 
Returns
Promise<Address>
-Promise:
-Address: 
Defined in
medusa/src/services/customer.ts:474
updateBillingAddress_
updateBillingAddress_(customer, addressOrId): Promise<void>
Updates the customers' billing address.
Parameters
| Name | Description | 
|---|---|
| customer | Customer | 
| addressOrId | undefined|string|DeepPartial<Address> | 
Returns
Promise<void>
-Promise: the result of the update operation
Defined in
medusa/src/services/customer.ts:422
withTransaction
withTransaction(transactionManager?): CustomerService
Parameters
| Name | 
|---|
| transactionManager? | 
Returns
-CustomerService: 
Inherited from
TransactionBaseService.withTransaction