# `Deputy.Departments`
[🔗](https://github.com/sgerrand/ex_deputy/blob/v0.4.0/lib/deputy/departments.ex#L1)

Functions for interacting with departments (operational units) in Deputy.

# `create`

```elixir
@spec create(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Create a department (operational unit).

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the new department details.

## Department parameters

- `intCompanyId`: ID of the company/location.
- `strOpunitName`: Name of the department.
- `strAddress`: Address of the department.
- `strExportName`: Optional. Name to use for exports.
- `intSortOrder`: Optional. Sort order.
- `intOpunitType`: Type of operational unit.
- `LocationId`: Optional. ID of the location.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   intCompanyId: 1,
    ...>   strOpunitName: "Sales",
    ...>   strAddress: "123 Main St",
    ...>   intOpunitType: 1
    ...> }
    iex> Deputy.Departments.create(client, attrs)
    {:ok, %{"Id" => 123}}

# `create!`

```elixir
@spec create!(Deputy.t(), map()) :: map()
```

Same as `create/2` but raises on error.

# `create_multiple`

```elixir
@spec create_multiple(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Create multiple departments.

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the array of departments to create.

## Parameters

- `arrArea`: Array of department objects.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   arrArea: [
    ...>     %{
    ...>       intCompanyId: 1,
    ...>       strOpunitName: "Sales",
    ...>       strAddress: "123 Main St",
    ...>       intOpunitType: 1
    ...>     },
    ...>     %{
    ...>       intCompanyId: 1,
    ...>       strOpunitName: "Marketing",
    ...>       strAddress: "123 Main St",
    ...>       intOpunitType: 1
    ...>     }
    ...>   ]
    ...> }
    iex> Deputy.Departments.create_multiple(client, attrs)
    {:ok, %{"success" => true}}

# `create_multiple!`

```elixir
@spec create_multiple!(Deputy.t(), map()) :: map()
```

Same as `create_multiple/2` but raises on error.

# `delete`

```elixir
@spec delete(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Delete an operational unit (department).

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the department to delete.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Departments.delete(client, 1)
    {:ok, %{"success" => true}}

# `delete!`

```elixir
@spec delete!(Deputy.t(), integer()) :: map()
```

Same as `delete/2` but raises on error.

# `list`

```elixir
@spec list(Deputy.t()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Get all operational units (departments).

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Departments.list(client)
    {:ok, [%{"Id" => 1, "OpunitName" => "Sales"}]}

# `list!`

```elixir
@spec list!(Deputy.t()) :: [map()]
```

Same as `list/1` but raises on error.

# `query`

```elixir
@spec query(Deputy.t(), map()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Retrieve preferred employees for a specific area/department.

## Parameters

- `client`: A Deputy client.
- `query`: A map containing the search query.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> query = %{
    ...>   join: [],
    ...>   assoc: ["RosterEmployeeOperationalUnit"],
    ...>   search: %{id: %{field: "Id", type: "eq", data: 1}}
    ...> }
    iex> Deputy.Departments.query(client, query)
    {:ok, [%{"Id" => 1, "Employees" => [%{"Id" => 123, "FirstName" => "John"}]}]}

# `query!`

```elixir
@spec query!(Deputy.t(), map()) :: [map()]
```

Same as `query/2` but raises on error.

# `update`

```elixir
@spec update(Deputy.t(), integer(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Update an operational unit (department).

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the department to update.
- `attrs`: A map containing the fields to update.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   intCompanyId: 12,
    ...>   strOpunitName: "Updated Department Name"
    ...> }
    iex> Deputy.Departments.update(client, 20, attrs)
    {:ok, %{"success" => true}}

# `update!`

```elixir
@spec update!(Deputy.t(), integer(), map()) :: map()
```

Same as `update/3` but raises on error.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
