PhoenixKitCRM.Companies (PhoenixKitCRM v0.2.4)

Copy Markdown View Source

Context for CRM companies — CRUD, soft-delete, and search (for the contact form's company picker).

Summary

Functions

Permanently deletes a company (cascades its memberships).

Companies for the given uuids (any status) — for comment back-link resolution.

Lists companies. Excludes trashed by default.

Memberships at a company (primary first), each with its contact preloaded. Excludes memberships whose contact is trashed so soft-deleted people don't linger in the roster or the company's interactions rollup.

Searches companies by name (case-insensitive) for the picker. Excludes trashed.

Soft-deletes a company (status → trashed, stashing the prior status).

Functions

change_company(company, attrs \\ %{})

@spec change_company(PhoenixKitCRM.Schemas.Company.t(), map()) :: Ecto.Changeset.t()

count_companies(opts \\ [])

@spec count_companies(keyword()) :: non_neg_integer()

create_company(attrs)

@spec create_company(map()) ::
  {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}

delete_company(company)

@spec delete_company(PhoenixKitCRM.Schemas.Company.t()) ::
  {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}

Permanently deletes a company (cascades its memberships).

get_company(uuid)

@spec get_company(UUIDv7.t() | String.t() | nil) ::
  PhoenixKitCRM.Schemas.Company.t() | nil

list_by_uuids(uuids)

@spec list_by_uuids([binary()]) :: [PhoenixKitCRM.Schemas.Company.t()]

Companies for the given uuids (any status) — for comment back-link resolution.

list_companies(opts \\ [])

@spec list_companies(keyword()) :: [PhoenixKitCRM.Schemas.Company.t()]

Lists companies. Excludes trashed by default.

Options

  • :status"trashed" for the Trash view, or any specific status
  • :include_trashedtrue to include trashed alongside the rest

list_memberships(company_uuid)

@spec list_memberships(UUIDv7.t() | String.t() | nil) :: [
  PhoenixKitCRM.Schemas.CompanyMembership.t()
]

Memberships at a company (primary first), each with its contact preloaded. Excludes memberships whose contact is trashed so soft-deleted people don't linger in the roster or the company's interactions rollup.

restore_company(company)

@spec restore_company(PhoenixKitCRM.Schemas.Company.t()) ::
  {:ok, PhoenixKitCRM.Schemas.Company.t()}
  | {:error, atom() | Ecto.Changeset.t()}

search_companies(query, limit \\ 8)

@spec search_companies(String.t(), pos_integer()) :: [
  PhoenixKitCRM.Schemas.Company.t()
]

Searches companies by name (case-insensitive) for the picker. Excludes trashed.

trash_company(company)

@spec trash_company(PhoenixKitCRM.Schemas.Company.t()) ::
  {:ok, PhoenixKitCRM.Schemas.Company.t()}
  | {:error, atom() | Ecto.Changeset.t()}

Soft-deletes a company (status → trashed, stashing the prior status).

update_company(company, attrs)

@spec update_company(PhoenixKitCRM.Schemas.Company.t(), map()) ::
  {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}