# Collection

This class defines a Collection of [[Books]].

## Extends

- `Resource`\<`bkper.Collection`\>

### Constructor

```ts
new Collection(payload?, config?): Collection;
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `payload?` | `Collection` |
| `config?` | [`Config`](https://bkper.com/docs/api/bkper-js/interfaces/config.md) |

#### Returns

`Collection`

#### Overrides

```ts
Resource<bkper.Collection>.constructor
```

### payload

```ts
payload: Collection;
```

The underlying payload data for this resource

#### Inherited from

```ts
Resource.payload
```

### addBooks()

```ts
addBooks(books): Promise;
```

Adds Books to this Collection.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `books` | [`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)[] | The Books to add to this Collection |

#### Returns

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

The added Book objects

***

### create()

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

Performs create new Collection.

#### Returns

`Promise`\<`Collection`\>

The created Collection object

***

### getBooks()

```ts
getBooks(): Book[];
```

Gets all Books of this collection.

#### Returns

[`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)[]

All Books of this collection

***

### getId()

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

Gets the unique identifier of this Collection.

#### Returns

`string` \| `undefined`

The id of this Collection

***

### getName()

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

Gets the name of this Collection.

#### Returns

`string` \| `undefined`

The name of this Collection

***

### getOwnerUsername()

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

Gets the username of the owner of this Collection

#### Returns

`string` \| `undefined`

The Collection's owner username

***

### getPermission()

```ts
getPermission(): Permission | undefined;
```

Gets the user permission for this Collection

#### Returns

[`Permission`](https://bkper.com/docs/api/bkper-js/enumerations/permission.md) \| `undefined`

The permission for the current user

***

### getUpdatedAt()

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

Gets the last update date of this Collection

#### Returns

`string` \| `undefined`

The Collection's last update timestamp, in milliseconds

***

### json()

```ts
json(): Collection;
```

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

#### Returns

`Collection`

An immutable copy of the json payload

#### Inherited from

```ts
Resource.json
```

***

### remove()

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

Performs delete Collection.

#### Returns

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

The list of Books the user has access to that were affected by the deletion of this Collection

***

### removeBooks()

```ts
removeBooks(books): Promise;
```

Removes Books from this Collection.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `books` | [`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)[] | The Books to remove from this Collection |

#### Returns

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

The removed Book objects

***

### setName()

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

Sets the name of the Collection.

#### Parameters

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

#### Returns

`Collection`

This Collection, for chaining

***

### update()

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

Performs update Collection, applying pending changes.

#### Returns

`Promise`\<`Collection`\>

The updated Collection object
