# Team

The "Team" section includes endpoints for team management and all associated information. It serves as the central hub for handling teams, offering functions like team creation, modification, and access to all team-related data.

The user must set the current command to pass validation when performing actions. It is important to note that if a user is a member of a command, but it is not marked as current for that user, the user will not be able to perform any actions in it. Typically this item is used to switch between the user's commands.

## Set current team

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/teams/current`

Assign the user to their active team, allowing them to collaborate within that specific team's context

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| teamId<mark style="color:red;">\*</mark> | String | Team ID     |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "userToken": "eyJ0eXAiOiJqd3QiLCJhbGciOiJFUzI1NiIsImtpZCI6IlBWdjZpMjBBNEZmdXJXVWtKRkYzMUV5WW5sdnJTVjFQRTNOUTI4TTUxLUUifQ.eyJhdWQiOiJlbmNsYWl2ZS1rZXlzdG9yZSIsImlzcyI6ImVuY2xhaXZlLWNvbnNvbGUiLCJzdWIiOiJlbmNsYWl2ZS1jdXN0b21lciIsImN1c3RvbWVyIjoiNjU0OGE0MTEzODQwNmMxNGRiMzNiNjA2IiwiZXhwIjoxNjk5NDM0NzczLCJpYXQiOjE2OTkzNDgzNzMsIm5iZiI6MTY5OTM0ODM3M30.chONgqM6AJeX5DvBUOGyq0PutoiEn5F7p3PiiP3JW5ugTQ9hk8zMlJKAdgVML-Y-qzaIhhRWFdb6pQaGmapdIQ",
    "vaultToken": "eyJ0eXAiOiJqd3QiLCJhbGciOiJFUzI1NiIsImtpZCI6IlBWdjZpMjBBNEZmdXJXVWtKRkYzMUV5WW5sdnJTVjFQRTNOUTI4TTUxLUUifQ.eyJhdWQiOiJlbmNsYWl2ZS1rZXlzdG9yZSIsImlzcyI6ImVuY2xhaXZlLWNvbnNvbGUiLCJzdWIiOiJlbmNsYWl2ZS1jdXN0b21lciIsImN1c3RvbWVyIjoiNjU0OGE0MWYzODQwNmMxNGRiMzNiNjFlIiwiZXhwIjoxNjk5NDM0NzczLCJpYXQiOjE2OTkzNDgzNzMsIm5iZiI6MTY5OTM0ODM3M30.CdVESfmO46Aczw0jufmDs9eKx1c1t06zn_pRC3m6_l69aQpe_mrE-ZnMkNfsklKvbHanrauujE2trmaVW9AAYw"
}
```

{% endtab %}
{% endtabs %}

## Get current team

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/teams/current`

Retrieve information about the user's currently active team, enabling them to access and interact with their team's resources.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "_id": "6548a41f38406c14db33b61e",
    "name": "My Team",
    "email": "john.doe@mail.com",
    "members": [
        {
            "user": {
                "_id": "6548a41138406c14db33b606",
                "status": 0,
                "name": "John Doe",
                "email": "john.doe@mail.com"
            },
            "role": 0
        }
    ],
    "createdAt": "2023-11-06T08:30:23.529Z",
    "updatedAt": "2023-11-06T12:56:06.337Z",
    "billingSettings": "6548e2660919dc0442dc2ec7",
    "quotas": [
        {
            "_id": "6548a41f38406c14db33b624",
            "cloudProvider": "6548a383e2442d14b6bf9681",
            "apps": {
                "nextCloud": 0,
                "gitlab": 0
            },
            "databases": {
                "mongo": 0,
                "postgres": 0,
                "maria": 0,
                "redis": 0
            },
            "vm": 4,
            "k8s": {
                "masterNode": 2,
                "workerNode": 2
            },
            "createdAt": "2023-11-06T08:27:47.146Z",
            "updatedAt": "2023-11-06T08:27:47.146Z",
            "team": "6548a41f38406c14db33b61e"
        },
        {
            "_id": "6548a41f38406c14db33b625",
            "cloudProvider": "6548a383e2442d14b6bf9682",
            "apps": {
                "nextCloud": 0,
                "gitlab": 0
            },
            "databases": {
                "mongo": 0,
                "postgres": 0,
                "maria": 0,
                "redis": 0
            },
            "vm": 4,
            "k8s": {
                "masterNode": 2,
                "workerNode": 2
            },
            "createdAt": "2023-11-06T08:27:47.146Z",
            "updatedAt": "2023-11-06T08:27:47.146Z",
            "team": "6548a41f38406c14db33b61e"
        },
        {
            "_id": "6548a41f38406c14db33b626",
            "cloudProvider": "6548a383e2442d14b6bf9683",
            "apps": {
                "nextCloud": 0,
                "gitlab": 0
            },
            "databases": {
                "mongo": 0,
                "postgres": 0,
                "maria": 0,
                "redis": 0
            },
            "vm": 4,
            "k8s": {
                "masterNode": 2,
                "workerNode": 2
            },
            "createdAt": "2023-11-06T08:27:47.146Z",
            "updatedAt": "2023-11-06T08:27:47.146Z",
            "team": "6548a41f38406c14db33b61e"
        },
        {
            "_id": "6548a41f38406c14db33b627",
            "cloudProvider": "6548a383e2442d14b6bf9684",
            "apps": {
                "nextCloud": 0,
                "gitlab": 0
            },
            "databases": {
                "mongo": 0,
                "postgres": 0,
                "maria": 0,
                "redis": 0
            },
            "vm": 4,
            "k8s": {
                "masterNode": 2,
                "workerNode": 2
            },
            "createdAt": "2023-11-06T08:27:47.146Z",
            "updatedAt": "2023-11-06T08:27:47.146Z",
            "team": "6548a41f38406c14db33b61e"
        },
        {
            "_id": "6548a41f38406c14db33b628",
            "cloudProvider": "6548a383e2442d14b6bf9685",
            "apps": {
                "nextCloud": 4,
                "gitlab": 4
            },
            "databases": {
                "mongo": 4,
                "postgres": 4,
                "maria": 4,
                "redis": 4
            },
            "vm": 4,
            "k8s": {
                "masterNode": 2,
                "workerNode": 2
            },
            "createdAt": "2023-11-06T08:27:47.146Z",
            "updatedAt": "2023-11-06T08:27:47.146Z",
            "team": "6548a41f38406c14db33b61e"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Get resources by team&#x20;

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/teams/{id}/resources`

Get all active resources on a specific team.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Team ID     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "vms": [
        {
            "_id": "654a002170c99a149c791cb6",
            "name": "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01",
            "type": "vm"
        }
    ],
    "dbs": [],
    "apps": []
}
```

{% endtab %}
{% endtabs %}

When creating a new project, the user has the option of transferring previously created resources to the new project.

## Move resources

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/teams/{id}/move-resources`

Transfer active resources (VMs, databases, applications, Kubernetes resources) from one project to another, providing flexibility in resource allocation.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| data<mark style="color:red;">\*</mark> | Object |             |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"ok"}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Request payload</summary>

```json
{
    "project": "654a052370c99a149c791ce7",
    "resources": [
        {
            "_id": "654a002170c99a149c791cb6",
            "name": "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01",
            "type": "vm"
        }
    ]
}
```

</details>

***

## Get Team

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/teams/{id}`

Get information about a specific team.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Team ID     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "_id": "6549ff7ce58641429600ac91",
    "name": "DEV Team",
    "email": "john.doe@mail.com",
    "members": [
        {
            "user": {
                "_id": "6548a41138406c14db33b606",
                "status": 0,
                "name": "John Doe",
                "email": "john.doe@mail.com"
            },
            "role": 0
        }
    ],
    "createdAt": "2023-11-06T08:30:23.529Z",
    "updatedAt": "2023-11-06T12:56:06.337Z",
    "billingSettings": "6548e2660919dc0442dc2ec7"
}
```

{% endtab %}
{% endtabs %}

## Updated Team

<mark style="color:orange;">`PUT`</mark> `{{BASE_URL}}/api/teams/{id}`

Update details and information about a specific team, ensuring accurate and up-to-date team information.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Team ID     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "_id": "6549ff7ce58641429600ac91",
    "name": "DEV Team1",
    "email": "john.doe@mail.com",
    "members": [
        {
            "user": {
                "_id": "6548a41138406c14db33b606",
                "name": "John Doe",
                "email": "john.doe@mail.com"
            },
            "role": 0
        }
    ],
    "createdAt": "2023-11-06T08:30:23.529Z",
    "updatedAt": "2023-11-07T09:41:38.504Z",
    "billingSettings": "6548e2660919dc0442dc2ec7"
}
```

{% endtab %}
{% endtabs %}

## Delete Team

<mark style="color:red;">`DELETE`</mark> `{{BASE_URL}}/api/teams/{id}`

Delete a team. You can only delete a team if there are no active resources in the team.

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Team ID     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"Sorry, functionality in development..."}
```

{% endtab %}
{% endtabs %}

## Delete member

<mark style="color:red;">`DELETE`</mark> `{{BASE_URL}}/api/teams/{id}/members/{memberId}`

Deleting a team member. This can only be done by the team administrator

#### Path Parameters

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark>       | String | Team ID     |
| memberId<mark style="color:red;">\*</mark> | String | User id     |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "name": "DEV Team1",
    "_id": "6549ff7ce58641429600ac91",
    "email": "john.doe@mail.com",
    "members": [
        {
            "user": "6548a41138406c14db33b606",
            "role": 0
        }
    ],
    "createdAt": "2023-11-06T08:30:23.529Z",
    "updatedAt": "2023-11-07T09:55:26.348Z",
    "billingSettings": "6548e2660919dc0442dc2ec7"
}
```

{% endtab %}
{% endtabs %}
