---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# CustomerGroupService

## Constructors

### constructor

`**new CustomerGroupService**(«destructured»)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "[CustomerGroupConstructorProps](../types/CustomerGroupConstructorProps.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": "customerGroupRepository_",
    "type": "Repository&#60;[CustomerGroup](CustomerGroup.mdx)&#62; & ``{ addCustomers: Method addCustomers ; findWithRelationsAndCount: Method findWithRelationsAndCount ; removeCustomers: Method removeCustomers  }``",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customerService_",
    "type": "[CustomerService](CustomerService.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": []
  }
]} />

## Accessors

### activeManager\_

`Protected get**activeManager_**(): EntityManager`

#### Returns

EntityManager

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "EntityManager",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

## Methods

### addCustomers

`**addCustomers**(id, customerIds): Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;`

Add a batch of customers to a customer group at once

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "id of the customer group to add customers to",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customerIds",
    "type": "`string` \\| `string`[]",
    "description": "customer id's to add to the group",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the customer group after insertion",
    "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": []
  }
]} />

___

### create

`**create**(group): Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;`

Creates a customer group with the provided data.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "group",
    "type": "DeepPartial&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "description": "the customer group to create",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the create operation",
    "expandable": false,
    "children": []
  }
]} />

___

### delete

`**delete**(groupId): Promise&#60;void&#62;`

Remove customer group

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "groupId",
    "type": "`string`",
    "description": "id of the customer group to delete",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;void&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "a promise",
    "expandable": false,
    "children": []
  }
]} />

___

### handleCreationFail

`Private **handleCreationFail**(id, ids, error): Promise&#60;never&#62;`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "ids",
    "type": "`string`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "error",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;never&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;never&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### list

`**list**(selector?, config): Promise&#60;[CustomerGroup](CustomerGroup.mdx)[]&#62;`

List customer groups.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[Selector](../types/Selector.mdx)&#60;[CustomerGroup](CustomerGroup.mdx)&#62; & ``{ discount_condition_id?: string ; q?: string  }``",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "description": "the config to be used for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)[]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

`**listAndCount**(selector?, config): Promise&#60;[[CustomerGroup](CustomerGroup.mdx)[], number]&#62;`

Retrieve a list of customer groups and total count of records that match the query.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[Selector](../types/Selector.mdx)&#60;[CustomerGroup](CustomerGroup.mdx)&#62; & ``{ discount_condition_id?: string ; q?: string  }``",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "description": "the config to be used for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[[CustomerGroup](CustomerGroup.mdx)[], number]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[CustomerGroup](CustomerGroup.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### removeCustomer

`**removeCustomer**(id, customerIds): Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;`

Remove list of customers from a customergroup

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "id of the customer group from which the customers are removed",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customerIds",
    "type": "`string` \\| `string`[]",
    "description": "id's of the customer to remove from group",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the customergroup with the provided id",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

`**retrieve**(customerGroupId, config?): Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "customerGroupId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.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**(customerGroupId, update): Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;`

Update a customer group.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "customerGroupId",
    "type": "`string`",
    "description": "id of the customer group",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "update",
    "type": "[CustomerGroupUpdate](CustomerGroupUpdate.mdx)",
    "description": "customer group partial data",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[CustomerGroup](CustomerGroup.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "resulting customer group",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

`**withTransaction**(transactionManager?): [CustomerGroupService](CustomerGroupService.mdx)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "EntityManager",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[CustomerGroupService](CustomerGroupService.mdx)

<ParameterTypes parameters={[
  {
    "name": "CustomerGroupService",
    "type": "[CustomerGroupService](CustomerGroupService.mdx)",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />
