Files
medusa-store/www/apps/docs/content/references/services/classes/CustomerService.mdx
Shahed Nasser c51dce164d docs: general fixes to references (#5653)
* fixed typedoc plugin's escape strategy

* move props comments to the associated property

* regenerate references
2023-11-17 19:36:58 +02:00

1150 lines
23 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# CustomerService
Provides layer to manipulate customers.
## Constructors
### constructor
`**new CustomerService**(«destructured»)`
#### Parameters
<ParameterTypes parameters={[
{
"name": "__namedParameters",
"type": "[InjectedDependencies](../types/InjectedDependencies-7.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Properties
<ParameterTypes parameters={[
{
"name": "__configModule__",
"type": "`Record<string, unknown>`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__container__",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__moduleDeclaration__",
"type": "`Record<string, unknown>`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "addressRepository_",
"type": "Repository&#60;[Address](Address.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "customerRepository_",
"type": "Repository&#60;[Customer](Customer.mdx)&#62; & ``{ listAndCount: Method listAndCount }``",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "eventBusService_",
"type": "[EventBusService](EventBusService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "manager_",
"type": "EntityManager",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "transactionManager_",
"type": "`undefined` \\| EntityManager",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "Events",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "Events.CREATED",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "\"customer.created\"",
"expandable": false,
"children": []
},
{
"name": "Events.PASSWORD_RESET",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "\"customer.password_reset\"",
"expandable": false,
"children": []
},
{
"name": "Events.UPDATED",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "\"customer.updated\"",
"expandable": false,
"children": []
}
]} />
## Accessors
### activeManager\_
`Protected get**activeManager_**(): EntityManager`
#### Returns
EntityManager
<ParameterTypes parameters={[
{
"name": "EntityManager",
"type": "EntityManager",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
## Methods
### addAddress
`**addAddress**(customerId, address): Promise&#60;[Customer](Customer.mdx) \| [Address](Address.mdx)&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "address",
"type": "[AddressCreatePayload](AddressCreatePayload.mdx)",
"description": "Address fields used when creating an address.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx) \| [Address](Address.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx) \\| [Address](Address.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### atomicPhase\_
`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;`
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.
<ParameterTypes parameters={[
{
"name": "TResult",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TError",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Parameters
<ParameterTypes parameters={[
{
"name": "work",
"type": "(`transactionManager`: EntityManager) => Promise&#60;TResult&#62;",
"description": "the transactional work to be done",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "isolationOrErrorHandler",
"type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
"description": "the isolation level to be used for the work.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "maybeErrorHandlerOrDontFail",
"type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
"description": "Potential error handler",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;TResult&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;TResult&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the transactional work",
"expandable": false,
"children": []
}
]} />
___
### count
`**count**(): Promise&#60;number&#62;`
Return the total number of documents in database
#### Returns
Promise&#60;number&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;number&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the count operation",
"expandable": false,
"children": []
}
]} />
___
### create
`**create**(customer): Promise&#60;[Customer](Customer.mdx)&#62;`
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
<ParameterTypes parameters={[
{
"name": "customer",
"type": "[CreateCustomerInput](../types/CreateCustomerInput.mdx)",
"description": "the customer to create",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of create",
"expandable": false,
"children": []
}
]} />
___
### delete
`**delete**(customerId): Promise&#60;void \| [Customer](Customer.mdx)&#62;`
Deletes a customer from a given customer id.
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "the id of the customer to delete. Must be castable as an ObjectId",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;void \| [Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;void \\| [Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the delete operation.",
"expandable": false,
"children": []
}
]} />
___
### generateResetPasswordToken
`**generateResetPasswordToken**(customerId): Promise&#60;string&#62;`
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
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "the customer to reset the password for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;string&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;string&#62;",
"optional": false,
"defaultValue": "",
"description": "the generated JSON web token",
"expandable": false,
"children": []
}
]} />
___
### hashPassword\_
`**hashPassword_**(password): Promise&#60;string&#62;`
Hashes a password
#### Parameters
<ParameterTypes parameters={[
{
"name": "password",
"type": "`string`",
"description": "the value to hash",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;string&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;string&#62;",
"optional": false,
"defaultValue": "",
"description": "hashed password",
"expandable": false,
"children": []
}
]} />
___
### list
`**list**(selector?, config?): Promise&#60;[Customer](Customer.mdx)[]&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[Selector](../types/Selector.mdx)&#60;[Customer](Customer.mdx)&#62; & ``{ groups?: string[] ; q?: string }``",
"description": "the query object for find",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "the config object containing query settings",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
### listAndCount
`**listAndCount**(selector, config?): Promise&#60;[[Customer](Customer.mdx)[], number]&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[Selector](../types/Selector.mdx)&#60;[Customer](Customer.mdx)&#62; & ``{ groups?: string[] ; q?: string }``",
"description": "the query object for find",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "the config object containing query settings",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[[Customer](Customer.mdx)[], number]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[[Customer](Customer.mdx)[], number]&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
### listByEmail
`**listByEmail**(email, config?): Promise&#60;[Customer](Customer.mdx)[]&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "email",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### removeAddress
`**removeAddress**(customerId, addressId): Promise&#60;void&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "addressId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;void&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;void&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### retrieve
`**retrieve**(customerId, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
Gets a customer by id.
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "the id of the customer to get.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "the config object containing query settings",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the customer document.",
"expandable": false,
"children": []
}
]} />
___
### retrieveByEmail
`**retrieveByEmail**(email, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
Gets a registered customer by email.
#### Parameters
<ParameterTypes parameters={[
{
"name": "email",
"type": "`string`",
"description": "the email of the customer to get.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "the config object containing query settings",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the customer document.",
"expandable": false,
"children": []
}
]} />
#### Deprecated
___
### retrieveByPhone
`**retrieveByPhone**(phone, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
Gets a customer by phone.
#### Parameters
<ParameterTypes parameters={[
{
"name": "phone",
"type": "`string`",
"description": "the phone of the customer to get.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "the config object containing query settings",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "the customer document.",
"expandable": false,
"children": []
}
]} />
___
### retrieveRegisteredByEmail
`**retrieveRegisteredByEmail**(email, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "email",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### retrieveUnregisteredByEmail
`**retrieveUnregisteredByEmail**(email, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "email",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### retrieve\_
`Private **retrieve_**(selector, config?): Promise&#60;[Customer](Customer.mdx)&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[Selector](../types/Selector.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Customer](Customer.mdx)&#62;",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### shouldRetryTransaction\_
`Protected **shouldRetryTransaction_**(err): boolean`
#### Parameters
<ParameterTypes parameters={[
{
"name": "err",
"type": "`Record<string, unknown>` \\| ``{ code: string }``",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`boolean`
<ParameterTypes parameters={[
{
"name": "boolean",
"type": "`boolean`",
"optional": true,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### update
`**update**(customerId, update): Promise&#60;[Customer](Customer.mdx)&#62;`
Updates a customer.
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "the id of the variant. Must be a string that can be casted to an ObjectId",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "update",
"type": "[UpdateCustomerInput](../types/UpdateCustomerInput.mdx)",
"description": "an object with the update values.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Customer](Customer.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Customer](Customer.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "resolves to the update result.",
"expandable": false,
"children": []
}
]} />
___
### updateAddress
`**updateAddress**(customerId, addressId, address): Promise&#60;[Address](Address.mdx)&#62;`
#### Parameters
<ParameterTypes parameters={[
{
"name": "customerId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "addressId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "address",
"type": "[StorePostCustomersCustomerAddressesAddressReq](StorePostCustomersCustomerAddressesAddressReq.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;[Address](Address.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[Address](Address.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### updateBillingAddress\_
`**updateBillingAddress_**(customer, addressOrId): Promise&#60;void&#62;`
Updates the customers' billing address.
#### Parameters
<ParameterTypes parameters={[
{
"name": "customer",
"type": "[Customer](Customer.mdx)",
"description": "the Customer to update",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "addressOrId",
"type": "`undefined` \\| `string` \\| DeepPartial&#60;[Address](Address.mdx)&#62;",
"description": "the value to set the billing address to",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
Promise&#60;void&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;void&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the update operation",
"expandable": false,
"children": []
}
]} />
___
### withTransaction
`**withTransaction**(transactionManager?): [CustomerService](CustomerService.mdx)`
#### Parameters
<ParameterTypes parameters={[
{
"name": "transactionManager",
"type": "EntityManager",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
[CustomerService](CustomerService.mdx)
<ParameterTypes parameters={[
{
"name": "CustomerService",
"type": "[CustomerService](CustomerService.mdx)",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />