Adds 7 new composable Query modules following the existing DeviceQuery/AlertQuery pattern. Each exposes base/0 and for_organization/1,2 plus filters used by 2+ callers. New modules: - Towerops.OnCall.ScheduleQuery - Towerops.OnCall.EscalationPolicyQuery - Towerops.Maintenance.MaintenanceWindowQuery - Towerops.Organizations.MembershipQuery - Towerops.Organizations.InvitationQuery - Towerops.Agents.AgentTokenQuery - Towerops.Gaiia.DeviceSubscriberLinkQuery Refactors callsites in alerts, agents, devices, gaiia, maintenance, on_call, organizations, search, and subscription_limits to use existing or new Query modules instead of inline 'where: x.organization_id == ^...' clauses.
36 lines
1 KiB
Elixir
36 lines
1 KiB
Elixir
defmodule Towerops.Agents.AgentTokenQuery do
|
|
@moduledoc """
|
|
Composable query fragments for `Towerops.Agents.AgentToken`.
|
|
|
|
Lets context modules build queries by piping filters together instead of
|
|
repeating `where: t.organization_id == ^...` clauses inline.
|
|
|
|
## Example
|
|
|
|
AgentTokenQuery.base()
|
|
|> AgentTokenQuery.for_organization(org_id)
|
|
|> AgentTokenQuery.enabled()
|
|
|> Repo.all()
|
|
"""
|
|
import Ecto.Query
|
|
|
|
alias Towerops.Agents.AgentToken
|
|
|
|
@doc "Starting point for an AgentToken query."
|
|
def base, do: AgentToken
|
|
|
|
@doc "Filter to a single organization."
|
|
def for_organization(query \\ base(), organization_id) do
|
|
where(query, [t], t.organization_id == ^organization_id)
|
|
end
|
|
|
|
@doc "Filter to organization-scoped tokens (excludes cloud pollers)."
|
|
def excluding_cloud_pollers(query \\ base()) do
|
|
where(query, [t], t.is_cloud_poller == false)
|
|
end
|
|
|
|
@doc "Filter to enabled tokens only."
|
|
def enabled(query \\ base()) do
|
|
where(query, [t], t.enabled == true)
|
|
end
|
|
end
|