# Referință API pentru programele de gardă

Source: https://instatus.com/help/ro/api/on-call-schedules

## Valori posibile pentru câmpuri

**Tipul restricției**

| Valoare | Descriere |
| --------------- | -------------------------------------------- |
| `NONE` | Fără restricții |
| `TIMEOFDAY` | Restricție bazată pe o anumită oră din zi |
| `TIMEINTERVALS` | Restricție bazată pe anumite intervale orare |

**Tipul rotației**

| Valoare | Descriere |
| -------- | ---------------------------------- |
| `DAILY` | Rotația are loc zilnic |
| `WEEKLY` | Rotația are loc săptămânal |
| `CUSTOM` | Rotația urmează un program personalizat |

**Zilele săptămânii**

| Valoare | Descriere |
| ----------- | ----------- |
| `SATURDAY` | Sâmbătă |
| `SUNDAY` | Duminică |
| `MONDAY` | Luni |
| `TUESDAY` | Marți |
| `WEDNESDAY` | Miercuri |
| `THURSDAY` | Joi |
| `FRIDAY` | Vineri |

## Obține membrii unui program de gardă

**Endpoint:**

```bash
GET /on-call-schedules/:id/members
```

**Exemplu de cerere**

```bash
GET /on-call-schedules/clzmgn2ze40301poblv9e1pq5/members
```

**Exemplu de răspuns**

```json
{
  "currentMembers": [
    {
      "id": "clh8nmaan72592bfokqjqd95s1",
      "name": null,
      "email": "member1@email.com",
      "phone": null,
      "avatar": "https://example.com/avatar.jpg"
    }
  ],
  "nextMembers": [
    {
      "id": "clzajmm98115510h5olxn5i7ljr",
      "name": null,
      "email": "member2@email.com",
      "phone": null,
      "avatar": null
    }
  ],
  "allMembers": [
    {
      "id": "clh8nmaan72592bfokqjqd95s1",
      "name": null,
      "email": "member1@email.com",
      "phone": null,
      "avatar": "https://example.com/avatar.jpg"
    },
    {
      "id": "clzajmm98115510h5olxn5i7ljr",
      "name": null,
      "email": "member2@email.com",
      "phone": null,
      "avatar": null
    }
  ]
}
```

## Creează un program de gardă

**Endpoint:**

```bash
POST /on-call-schedules
```

**Exemplu de cerere**

```json
{
  "name": "Primary On-call Schedule",
  "description": "This schedule is for the primary on-call team.",
  "onCallShifts": [
    {
      "name": "Primary",
      "members": [
        {
          "workspaceMemberId": "member123",
          "color": "#FF5733"
        },
        {
          "workspaceMemberId": "member456",
          "color": "#33C4FF"
        }
      ],
      "rotationType": "WEEKLY",
      "customRotationTypeValue": null,
      "customRotationTypeUnit": null,
      "startDate": "2023-08-08T08:00:00Z",
      "endDate": "2024-08-21T08:42:00.000Z",
      "restrictionType": "TIMEINTERVALS",
      "timeOfDayRestrictionStartTime": null,
      "timeOfDayRestrictionEndTime": null,
      "timeIntervals": [
        {
          "startDay": "SATURDAY",
          "startDayTime": "1970-01-01T21:00:00.000Z",
          "endDay": "SUNDAY",
          "endDayTime": "1970-01-01T03:00:00.000Z"
        }
      ]
    }
  ]
}
```

**Exemplu de răspuns**

```json
{
  "id": "clzmgn2ze40301poblv9e1pq5",
  "name": "Primary On-call Schedule",
  "description": "This schedule is for the primary on-call team.",
  "status": "ACTIVE",
  "onCallShifts": [
    {
      "id": "clzmgn2zt40361pobj78giwf7",
      "name": "Primary",
      "order": 1,
      "members": [
        {
          "id": "clzmgn2zt40401pobjzq0pwjd",
          "order": 3,
          "color": "#0470a6",
          "workspaceMember": {
            "id": "member123",
            "user": {
              "id": "clh8nmaan72592bfokqjqd95s1",
              "name": null,
              "email": "member12@email.com",
              "avatar": null
            }
          }
        },
        {
          "id": "clzmgn2zt40381pob690bwaxx",
          "order": 1,
          "color": "#195397",
          "workspaceMember": {
            "id": "member456",
            "user": {
              "id": "clzajmm98115510h5olxn5i7ljr",
              "name": null,
              "email": "member45@email.com",
              "avatar": null
            }
          }
        }
      ],
      "rotationType": "WEEKLY",
      "customRotationTypeValue": null,
      "customRotationTypeUnit": null,
      "startDate": "2024-08-09T08:42:34.557Z",
      "endDate": "2024-08-21T08:42:00.000Z",
      "restrictionType": "TIMEINTERVALS",
      "timeOfDayRestrictionStartTime": null,
      "timeOfDayRestrictionEndTime": null,
      "timeIntervals": [
        {
          "id": "clzmjq8bn313521ioblyzg7hic",
          "startDay": "SATURDAY",
          "startDayTime": "1970-01-01T21:00:00.000Z",
          "endDay": "SUNDAY",
          "endDayTime": "1970-01-01T03:00:00.000Z"
        }
      ]
    }
  ]
}
```

## Actualizează un program de gardă

**Endpoint:**

```bash
PUT /on-call-schedules/:id
```

**Exemplu de cerere**

```bash
PUT /on-call-schedules/clzmgn2ze40301poblv9e1pq5
```

```json
{
  "id": "clzmgn2ze40301poblv9e1pq5",
  "name": "Name Update",
  "description": "This schedule is for the primary on-call team.",
  "status": "ACTIVE",
  "onCallShifts": [
      {
          "id": "clzmgn2zt40361pobj78giwf7",
          "name": "Primary",
          "order": 1,
          "members": [
              {
                  "id": "clzmgn2zt40401pobjzq0pwjd",
                  "order": 3,
                  "color": "#0470a6",
                  "workspaceMember": {
                      "id": "member123",
                      "user": {
                          "id": "clh8nmaan72592bfokqjqd95s1",
                          "name": null,
                          "email": "member12@email.com",
                          "avatar": null
                      }
                  }
              },
              {
                  "id": "clzmgn2zt40381pob690bwaxx",
                  "order": 1,
                  "color": "#195397",
                  "workspaceMember": {
                      "id": "member456",
                      "user": {
                          "id": "clzajmm98115510h5olxn5i7ljr",
                          "name": null,
                          "email": "member45@email.com",
                          "avatar": null
                      }
                  }
              }
          ],
          "rotationType": "WEEKLY",
          "customRotationTypeValue": null,
          "customRotationTypeUnit": null,
          "startDate": "2024-08-09T08:42:34.557Z",
          "endDate": "2024-08-21T08:42:00.000Z",
          "restrictionType": "TIMEINTERVALS",
          "timeOfDayRestrictionStartTime": null,
          "timeOfDayRestrictionEndTime": null,
          "timeIntervals": [
              {
                  "id": "clzmjq8bn313521ioblyzg7hic",
                  "startDay": "SATURDAY",
                  "startDayTime": "1970-01-01T21:00:00.000Z",
                  "endDay": "SUNDAY",
                  "endDayTime": "1970-01-01T03:00:00.000Z"
              }
          ]
      }
  ]
}
```

**Exemplu de răspuns**

```json
{
  "id": "clzmgn2ze40301poblv9e1pq5",
  "name": "Name Update",
  "description": "This schedule is for the primary on-call team.",
  "status": "ACTIVE",
  "onCallShifts": [
      {
          "id": "clzmgn2zt40361pobj78giwf7",
          "name": "Primary",
          "order": 1,
          "members": [
              {
                  "id": "clzmgn2zt40401pobjzq0pwjd",
                  "order": 3,
                  "color": "#0470a6",
                  "workspaceMember": {
                      "id": "member123",
                      "user": {
                          "id": "clh8nmaan72592bfokqjqd95s1",
                          "name": null,
                          "email": "member12@email.com",
                          "avatar": null
                      }
                  }
              },
              {
                  "id": "clzmgn2zt40381pob690bwaxx",
                  "order": 1,
                  "color": "#195397",
                  "workspaceMember": {
                      "id": "member456",
                      "user": {
                          "id": "clzajmm98115510h5olxn5i7ljr",
                          "name": null,
                          "email": "member45@email.com",
                          "avatar": null
                      }
                  }
              }
          ],
          "rotationType": "WEEKLY",
          "customRotationTypeValue": null,
          "customRotationTypeUnit": null,
          "startDate": "2024-08-09T08:42:34.557Z",
          "endDate": "2024-08-21T08:42:00.000Z",
          "restrictionType": "TIMEINTERVALS",
          "timeOfDayRestrictionStartTime": null,
          "timeOfDayRestrictionEndTime": null,
          "timeIntervals": [
              {
                  "id": "clzmjq8bn313521ioblyzg7hic",
                  "startDay": "SATURDAY",
                  "startDayTime": "1970-01-01T21:00:00.000Z",
                  "endDay": "SUNDAY",
                  "endDayTime": "1970-01-01T03:00:00.000Z"
              }
          ]
      }
  ]
}
```

## Șterge un program de gardă

**Endpoint:**

```bash
DELETE /on-call-schedules/:id
```

**Exemplu de cerere**

```bash
DELETE /on-call-schedules/schedule-id-1
```

**Exemplu de răspuns**

```
204 No Content
```
