Deputy.Departments (Deputy v0.5.0)

Copy Markdown View Source

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

Summary

Functions

Create a department (operational unit).

Same as create/2 but raises on error.

Create multiple departments.

Same as create_multiple/2 but raises on error.

Delete an operational unit (department).

Same as delete/2 but raises on error.

Get all operational units (departments).

Same as list/1 but raises on error.

Retrieve preferred employees for a specific area/department.

Same as query/2 but raises on error.

Update an operational unit (department).

Same as update/3 but raises on error.

Functions

create(client, attrs)

@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

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

create!(client, attrs)

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

Same as create/2 but raises on error.

create_multiple(client, attrs)

@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

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

create_multiple!(client, attrs)

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

Same as create_multiple/2 but raises on error.

delete(client, id)

@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

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

delete!(client, id)

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

Same as delete/2 but raises on error.

list(client)

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

Get all operational units (departments).

Examples

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

list!(client)

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

Same as list/1 but raises on error.

query(client, query)

@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

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

query!(client, query)

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

Same as query/2 but raises on error.

update(client, id, attrs)

@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

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

update!(client, id, attrs)

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

Same as update/3 but raises on error.