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
@spec change_company(PhoenixKitCRM.Schemas.Company.t(), map()) :: Ecto.Changeset.t()
@spec count_companies(keyword()) :: non_neg_integer()
@spec create_company(map()) :: {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}
@spec delete_company(PhoenixKitCRM.Schemas.Company.t()) :: {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}
Permanently deletes a company (cascades its memberships).
@spec get_company(UUIDv7.t() | String.t() | nil) :: PhoenixKitCRM.Schemas.Company.t() | nil
@spec list_by_uuids([binary()]) :: [PhoenixKitCRM.Schemas.Company.t()]
Companies for the given uuids (any status) — for comment back-link resolution.
@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_trashed—trueto include trashed alongside the rest
@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.
@spec restore_company(PhoenixKitCRM.Schemas.Company.t()) :: {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, atom() | Ecto.Changeset.t()}
@spec search_companies(String.t(), pos_integer()) :: [ PhoenixKitCRM.Schemas.Company.t() ]
Searches companies by name (case-insensitive) for the picker. Excludes trashed.
@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).
@spec update_company(PhoenixKitCRM.Schemas.Company.t(), map()) :: {:ok, PhoenixKitCRM.Schemas.Company.t()} | {:error, Ecto.Changeset.t()}