--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # CustomerService Provides layer to manipulate customers. ## Constructors ### constructor `**new CustomerService**(«destructured»)` #### Parameters ## Properties `", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__container__", "type": "`any`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__moduleDeclaration__", "type": "`Record`", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "addressRepository_", "type": "Repository<[Address](Address.mdx)>", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customerRepository_", "type": "Repository<[Customer](Customer.mdx)> & ``{ 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 ## Methods ### addAddress `**addAddress**(customerId, address): Promise<[Customer](Customer.mdx) \| [Address](Address.mdx)>` #### Parameters #### Returns Promise<[Customer](Customer.mdx) \| [Address](Address.mdx)> ___ ### atomicPhase\_ `Protected **atomicPhase_**(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. #### Parameters Promise<TResult>", "description": "the transactional work to be done", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "isolationOrErrorHandler", "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise<void \\| TResult>", "description": "the isolation level to be used for the work.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "maybeErrorHandlerOrDontFail", "type": "(`error`: `TError`) => Promise<void \\| TResult>", "description": "Potential error handler", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns Promise<TResult> ___ ### count `**count**(): Promise<number>` Return the total number of documents in database #### Returns Promise<number> ___ ### create `**create**(customer): Promise<[Customer](Customer.mdx)>` 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 #### Returns Promise<[Customer](Customer.mdx)> ___ ### delete `**delete**(customerId): Promise<void \| [Customer](Customer.mdx)>` Deletes a customer from a given customer id. #### Parameters #### Returns Promise<void \| [Customer](Customer.mdx)> ___ ### 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 #### Returns Promise<string> ___ ### hashPassword\_ `**hashPassword_**(password): Promise<string>` Hashes a password #### Parameters #### Returns Promise<string> ___ ### list `**list**(selector?, config?): Promise<[Customer](Customer.mdx)[]>` #### Parameters #### Returns Promise<[Customer](Customer.mdx)[]> ___ ### listAndCount `**listAndCount**(selector, config?): Promise<[[Customer](Customer.mdx)[], number]>` #### Parameters #### Returns Promise<[[Customer](Customer.mdx)[], number]> ___ ### listByEmail `**listByEmail**(email, config?): Promise<[Customer](Customer.mdx)[]>` #### Parameters #### Returns Promise<[Customer](Customer.mdx)[]> ___ ### removeAddress `**removeAddress**(customerId, addressId): Promise<void>` #### Parameters #### Returns Promise<void> ___ ### retrieve `**retrieve**(customerId, config?): Promise<[Customer](Customer.mdx)>` Gets a customer by id. #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### retrieveByEmail `**retrieveByEmail**(email, config?): Promise<[Customer](Customer.mdx)>` Gets a registered customer by email. #### Parameters #### Returns Promise<[Customer](Customer.mdx)> #### Deprecated ___ ### retrieveByPhone `**retrieveByPhone**(phone, config?): Promise<[Customer](Customer.mdx)>` Gets a customer by phone. #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### retrieveRegisteredByEmail `**retrieveRegisteredByEmail**(email, config?): Promise<[Customer](Customer.mdx)>` #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### retrieveUnregisteredByEmail `**retrieveUnregisteredByEmail**(email, config?): Promise<[Customer](Customer.mdx)>` #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### retrieve\_ `Private **retrieve_**(selector, config?): Promise<[Customer](Customer.mdx)>` #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### shouldRetryTransaction\_ `Protected **shouldRetryTransaction_**(err): boolean` #### Parameters ` \\| ``{ code: string }``", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `boolean` ___ ### update `**update**(customerId, update): Promise<[Customer](Customer.mdx)>` Updates a customer. #### Parameters #### Returns Promise<[Customer](Customer.mdx)> ___ ### updateAddress `**updateAddress**(customerId, addressId, address): Promise<[Address](Address.mdx)>` #### Parameters #### Returns Promise<[Address](Address.mdx)> ___ ### updateBillingAddress\_ `**updateBillingAddress_**(customer, addressOrId): Promise<void>` Updates the customers' billing address. #### Parameters #### Returns Promise<void> ___ ### withTransaction `**withTransaction**(transactionManager?): [CustomerService](CustomerService.mdx)` #### Parameters #### Returns [CustomerService](CustomerService.mdx)