Deputy.Departments (Deputy v0.2.1)

View Source

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

Summary

Functions

Create a department (operational unit).

Create multiple departments.

Delete an operational unit (department).

Get all operational units (departments).

Retrieve preferred employees for a specific area/department.

Update an operational unit (department).

Functions

create(client, attrs)

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

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_multiple(client, attrs)

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

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}}

delete(client, id)

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

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}}

list(client)

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

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"}]}

query(client, query)

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

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"}]}]}

update(client, id, attrs)

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

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}}