# Group

This class defines a Group of [[Accounts]].

Accounts can be grouped by different meaning, like Expenses, Revenue, Assets, Liabilities and so on

Its useful to keep organized and for high level analysis.

## Extends

- `ResourceProperty`\<`bkper.Group`\>

### Constructor

```ts
new Group(book, payload?): Group;
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `book` | [`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md) |
| `payload?` | `Group` |

#### Returns

`Group`

#### Overrides

```ts
ResourceProperty<bkper.Group>.constructor
```

### payload

```ts
payload: Group;
```

The underlying payload data for this resource

#### Inherited from

```ts
ResourceProperty.payload
```

### create()

```ts
create(): Promise;
```

Performs create new group.

#### Returns

`Promise`\<`Group`\>

A promise that resolves to this Group

***

### deleteProperty()

```ts
deleteProperty(key): this;
```

Deletes a custom property.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.deleteProperty
```

***

### getAccounts()

```ts
getAccounts(): Promise;
```

Gets all Accounts of this group.

#### Returns

`Promise`\<[`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md)[]\>

All Accounts of this group

***

### getChildren()

```ts
getChildren(): Group[];
```

Gets the children of the Group.

#### Returns

`Group`[]

An array of child Groups

***

### getDepth()

```ts
getDepth(): number;
```

Gets the depth of the Group in the hierarchy.

#### Returns

`number`

The depth of the Group

***

### getDescendants()

```ts
getDescendants(): Set;
```

Gets all descendant Groups of the current Group.

#### Returns

`Set`\<`Group`\>

A set of descendant Groups

***

### getDescendantTreeIds()

```ts
getDescendantTreeIds(): Set<string>;
```

Gets the IDs of all descendant Groups in a tree structure.

#### Returns

`Set`\<`string`\>

A set of descendant Group IDs

***

### getId()

```ts
getId(): string | undefined;
```

Gets the id of this Group.

#### Returns

`string` \| `undefined`

The id of this Group

***

### getName()

```ts
getName(): string | undefined;
```

Gets the name of this Group.

#### Returns

`string` \| `undefined`

The name of this Group

***

### getNormalizedName()

```ts
getNormalizedName(): string;
```

Gets the normalized name of this group without spaces and special characters.

#### Returns

`string`

The name of this group without spaces and special characters

***

### getParent()

```ts
getParent(): Group | undefined;
```

Gets the parent Group.

#### Returns

`Group` \| `undefined`

The parent Group

***

### getProperties()

```ts
getProperties(): object;
```

Gets the custom properties stored in this resource.

#### Returns

`object`

Object with key/value pair properties

#### Inherited from

```ts
ResourceProperty.getProperties
```

***

### getProperty()

```ts
getProperty(...keys): string | undefined;
```

Gets the property value for given keys. First property found will be retrieved.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| ...`keys` | `string`[] | The property keys to search for |

#### Returns

`string` \| `undefined`

The property value or undefined if not found

#### Inherited from

```ts
ResourceProperty.getProperty
```

***

### getPropertyKeys()

```ts
getPropertyKeys(): string[];
```

Gets the custom properties keys stored in this resource.

#### Returns

`string`[]

Array of property keys sorted alphabetically

#### Inherited from

```ts
ResourceProperty.getPropertyKeys
```

***

### getRoot()

```ts
getRoot(): Group;
```

Gets the root Group of the current Group.

#### Returns

`Group`

The root Group

***

### getRootName()

```ts
getRootName(): string;
```

Gets the name of the root Group.

#### Returns

`string`

The name of the root Group

***

### getType()

```ts
getType(): AccountType;
```

Gets the type of the accounts of this group.

#### Returns

[`AccountType`](https://bkper.com/docs/api/bkper-js/enumerations/accounttype.md)

The type for of the accounts of this group. Null if mixed

***

### getVisibleProperties()

```ts
getVisibleProperties(): object;
```

Gets the visible custom properties stored in this resource.
Hidden properties (those ending with "_") are excluded from the result.

#### Returns

`object`

Object with key/value pair properties, excluding hidden properties

#### Inherited from

```ts
ResourceProperty.getVisibleProperties
```

***

### hasAccounts()

```ts
hasAccounts(): boolean | undefined;
```

Tells if this group has any account in it.

#### Returns

`boolean` \| `undefined`

True if this group has any account in it

***

### hasChildren()

```ts
hasChildren(): boolean;
```

Checks if the Group has any children.

#### Returns

`boolean`

True if the Group has children, otherwise false

***

### hasParent()

```ts
hasParent(): boolean;
```

Checks if the Group has a parent.

#### Returns

`boolean`

True if the Group has a parent, otherwise false

***

### isBalanceVerified()

```ts
isBalanceVerified(): Promise<boolean | undefined>;
```

Tells if the balance of this Group has been verified/audited.

#### Returns

`Promise`\<`boolean` \| `undefined`\>

True if the balance of this Group has been verified/audited

***

### isCredit()

```ts
isCredit(): boolean | undefined;
```

Tells if this is a credit (Incoming and Liabilities) group.

#### Returns

`boolean` \| `undefined`

True if this is a credit group

***

### isHidden()

```ts
isHidden(): boolean | undefined;
```

Tells if the Group is hidden on main transactions menu.

#### Returns

`boolean` \| `undefined`

True if the Group is hidden, false otherwise

***

### isLeaf()

```ts
isLeaf(): boolean;
```

Checks if the Group is a leaf node (i.e., has no children).

#### Returns

`boolean`

True if the Group is a leaf, otherwise false

***

### isLocked()

```ts
isLocked(): boolean;
```

Tells if the Group is locked by the Book owner.

#### Returns

`boolean`

True if the Group is locked

***

### isMixed()

```ts
isMixed(): boolean | undefined;
```

Tells if this is a mixed (Assets/Liabilities or Incoming/Outgoing) group.

#### Returns

`boolean` \| `undefined`

True if this is a mixed group

***

### isPermanent()

```ts
isPermanent(): boolean | undefined;
```

Tells if the Group is permanent.

#### Returns

`boolean` \| `undefined`

True if the Group is permanent

***

### isRoot()

```ts
isRoot(): boolean;
```

Checks if the Group is a root node (i.e., has no parent).

#### Returns

`boolean`

True if the Group is a root, otherwise false

***

### json()

```ts
json(): Group;
```

Gets an immutable copy of the JSON payload for this resource.

#### Returns

`Group`

An immutable copy of the json payload

#### Inherited from

```ts
ResourceProperty.json
```

***

### remove()

```ts
remove(): Promise;
```

Performs delete group.

#### Returns

`Promise`\<`Group`\>

A promise that resolves to this Group

***

### setHidden()

```ts
setHidden(hidden): Group;
```

Hide/Show group on main menu.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `hidden` | `boolean` | Whether to hide the group |

#### Returns

`Group`

This Group, for chaining

***

### setLocked()

```ts
setLocked(locked): Group;
```

Sets the locked state of the Group.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `locked` | `boolean` | The locked state of the Group. |

#### Returns

`Group`

This Group, for chaining

***

### setName()

```ts
setName(name): Group;
```

Sets the name of the Group.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name to set |

#### Returns

`Group`

This Group, for chaining

***

### setParent()

```ts
setParent(group): Group;
```

Sets the parent Group.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `group` | `Group` \| `null` \| `undefined` | The parent Group to set |

#### Returns

`Group`

This Group, for chaining

***

### setProperties()

```ts
setProperties(properties): this;
```

Sets the custom properties of this resource.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperties
```

***

### setProperty()

```ts
setProperty(key, value): this;
```

Sets a custom property in this resource.

Property keys are normalized and validated by the API when saved. Keep keys
to 30 characters or fewer after normalization. Use a trailing underscore
(`_`) for hidden/internal properties.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperty
```

***

### setVisibleProperties()

```ts
setVisibleProperties(properties): this;
```

Sets the custom properties of this resource, filtering out hidden properties.
Hidden properties are those whose keys end with an underscore "_".

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperties
```

***

### setVisibleProperty()

```ts
setVisibleProperty(key, value): this;
```

Sets a custom property in this resource, filtering out hidden properties.
Hidden properties are those whose keys end with an underscore "_".

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperty
```

***

### update()

```ts
update(): Promise;
```

Performs update group, applying pending changes.

#### Returns

`Promise`\<`Group`\>

A promise that resolves to this Group
