fix: align gaiia graphql queries with actual api schema

field mappings from docs:
- accountStatus/accountType -> status/type
- accountBillingSubscriptions -> billingSubscriptions
- billingSubscriptionStatus -> status
- address city/state/zip -> locality/region/postalCode
- networkSiteIpBlocks -> ipBlocks
- inventoryItemStatus -> status, ipAddress -> ipAddressV4
- inventoryModel -> model, inventoryModelCategory -> model.category
- account/networkSite -> assignation.assignee (union type)
- product/recurringAmount/currency -> productVersion (price in cents)
- account on subscription -> entity (union type)
This commit is contained in:
Graham McIntire 2026-02-13 14:41:14 -06:00
parent 471c4f6893
commit 848efa8fc4
No known key found for this signature in database
5 changed files with 104 additions and 90 deletions

View file

@ -18,22 +18,22 @@ defmodule Towerops.Gaiia.Client do
id
readableId
name
accountStatus
accountType
status
type
physicalAddress {
line1
city
state
zip
locality
region
postalCode
country
latitude
longitude
}
accountBillingSubscriptions(first: 100) {
billingSubscriptions(first: 100) {
edges {
node {
id
billingSubscriptionStatus
status
}
}
}
@ -56,14 +56,14 @@ defmodule Towerops.Gaiia.Client do
name
address {
line1
city
state
zip
locality
region
postalCode
country
latitude
longitude
}
networkSiteIpBlocks(first: 100) {
ipBlocks(first: 100) {
edges {
node {
subnet
@ -86,25 +86,23 @@ defmodule Towerops.Gaiia.Client do
edges {
node {
id
name
inventoryItemStatus
serialNumber
macAddress
ipAddress
inventoryModel {
status
ipAddressV4
model {
name
manufacturer {
name
}
category {
name
}
}
inventoryModelCategory {
name
}
account {
id
}
networkSite {
id
assignation {
assigneeType
assignee {
... on Account { id }
... on NetworkSite { id }
}
}
}
}
@ -122,14 +120,16 @@ defmodule Towerops.Gaiia.Client do
edges {
node {
id
billingSubscriptionStatus
product {
name
status
productVersion {
product {
name
}
price
currency
}
recurringAmount
currency
account {
id
entity {
... on Account { id }
}
}
}
@ -173,8 +173,7 @@ defmodule Towerops.Gaiia.Client do
mutation UpdateInventoryItem($id: ID!, $input: UpdateInventoryItemInput!) {
updateInventoryItem(id: $id, input: $input) {
id
ipAddress
serialNumber
ipAddressV4
}
}
"""

View file

@ -78,15 +78,15 @@ defmodule Towerops.Gaiia.Sync do
end
defp map_account(node) do
subs = get_in(node, ["accountBillingSubscriptions", "edges"]) || []
active_count = Enum.count(subs, &(&1["node"]["billingSubscriptionStatus"] == "Active"))
subs = get_in(node, ["billingSubscriptions", "edges"]) || []
active_count = Enum.count(subs, &(&1["node"]["status"] == "Active"))
%{
gaiia_id: node["id"],
readable_id: node["readableId"],
name: node["name"],
status: node["accountStatus"],
account_type: node["accountType"],
status: node["status"],
account_type: node["type"],
address: map_address(node["physicalAddress"]),
subscription_count: active_count,
raw_data: node
@ -94,7 +94,7 @@ defmodule Towerops.Gaiia.Sync do
end
defp map_network_site(node) do
ip_block_edges = get_in(node, ["networkSiteIpBlocks", "edges"]) || []
ip_block_edges = get_in(node, ["ipBlocks", "edges"]) || []
ip_blocks = Enum.map(ip_block_edges, & &1["node"]["subnet"])
%{
@ -107,30 +107,45 @@ defmodule Towerops.Gaiia.Sync do
end
defp map_inventory_item(node) do
assignation = node["assignation"]
{account_id, site_id} =
case assignation do
%{"assigneeType" => "Account", "assignee" => %{"id" => id}} -> {id, nil}
%{"assigneeType" => "NetworkSite", "assignee" => %{"id" => id}} -> {nil, id}
_ -> {nil, nil}
end
%{
gaiia_id: node["id"],
name: node["name"],
status: node["inventoryItemStatus"],
serial_number: node["serialNumber"],
mac_address: node["macAddress"],
ip_address: node["ipAddress"],
model_name: get_in(node, ["inventoryModel", "name"]),
manufacturer_name: get_in(node, ["inventoryModel", "manufacturer", "name"]),
category: get_in(node, ["inventoryModelCategory", "name"]),
assigned_account_gaiia_id: get_in(node, ["account", "id"]),
assigned_network_site_gaiia_id: get_in(node, ["networkSite", "id"]),
name: get_in(node, ["model", "name"]),
status: node["status"],
serial_number: nil,
mac_address: nil,
ip_address: node["ipAddressV4"],
model_name: get_in(node, ["model", "name"]),
manufacturer_name: get_in(node, ["model", "manufacturer", "name"]),
category: get_in(node, ["model", "category", "name"]),
assigned_account_gaiia_id: account_id,
assigned_network_site_gaiia_id: site_id,
raw_data: node
}
end
defp map_billing_subscription(node) do
price_cents = get_in(node, ["productVersion", "price"])
mrr_amount =
if is_integer(price_cents),
do: Decimal.div(Decimal.new(price_cents), 100)
%{
gaiia_id: node["id"],
account_gaiia_id: get_in(node, ["account", "id"]),
status: node["billingSubscriptionStatus"],
product_name: get_in(node, ["product", "name"]),
mrr_amount: node["recurringAmount"],
currency: node["currency"],
account_gaiia_id: get_in(node, ["entity", "id"]),
status: node["status"],
product_name: get_in(node, ["productVersion", "product", "name"]),
mrr_amount: mrr_amount,
currency: get_in(node, ["productVersion", "currency"]),
raw_data: node
}
end
@ -140,9 +155,9 @@ defmodule Towerops.Gaiia.Sync do
defp map_address(addr) do
%{
"line1" => addr["line1"],
"city" => addr["city"],
"state" => addr["state"],
"zip" => addr["zip"],
"city" => addr["locality"],
"state" => addr["region"],
"zip" => addr["postalCode"],
"country" => addr["country"],
"latitude" => addr["latitude"],
"longitude" => addr["longitude"]

View file

@ -156,8 +156,8 @@ defmodule Towerops.Gaiia.ClientTest do
%{
"node" => %{
"id" => "sub-1",
"billingSubscriptionStatus" => "Active",
"product" => %{"name" => "100Mbps"}
"status" => "Active",
"productVersion" => %{"product" => %{"name" => "100Mbps"}}
}
}
],

View file

@ -64,12 +64,11 @@ defmodule Towerops.Gaiia.SyncTest do
[item] = Gaiia.list_inventory_items(org.id)
assert item.gaiia_id == "item-1"
assert item.name == "AF5XHD"
assert item.serial_number == "SN12345"
assert item.mac_address == "AA:BB:CC:DD:EE:FF"
assert item.name == "airFiber 5XHD"
assert item.model_name == "airFiber 5XHD"
assert item.manufacturer_name == "Ubiquiti"
assert item.category == "AP"
assert item.assigned_account_gaiia_id == "acct-1"
end
test "maps billing subscription fields correctly", %{org: org, integration: integration} do
@ -139,23 +138,23 @@ defmodule Towerops.Gaiia.SyncTest do
"id" => "acct-1",
"readableId" => "1001",
"name" => "Alice Smith",
"accountStatus" => "Active",
"accountType" => "Residential",
"status" => "Active",
"type" => "Residential",
"physicalAddress" => %{
"line1" => "123 Main St",
"city" => "Portland",
"state" => "OR",
"zip" => "97201",
"locality" => "Portland",
"region" => "OR",
"postalCode" => "97201",
"country" => "US",
"latitude" => 45.5,
"longitude" => -122.6
},
"accountBillingSubscriptions" => %{
"billingSubscriptions" => %{
"edges" => [
%{
"node" => %{
"id" => "sub-1",
"billingSubscriptionStatus" => "Active"
"status" => "Active"
}
}
]
@ -180,14 +179,14 @@ defmodule Towerops.Gaiia.SyncTest do
"name" => "Tower 3",
"address" => %{
"line1" => "456 Tower Rd",
"city" => "Portland",
"state" => "OR",
"zip" => "97201",
"locality" => "Portland",
"region" => "OR",
"postalCode" => "97201",
"country" => "US",
"latitude" => 45.5,
"longitude" => -122.6
},
"networkSiteIpBlocks" => %{
"ipBlocks" => %{
"edges" => [
%{"node" => %{"subnet" => "10.0.0.0/24"}}
]
@ -209,18 +208,17 @@ defmodule Towerops.Gaiia.SyncTest do
%{
"node" => %{
"id" => "item-1",
"name" => "AF5XHD",
"inventoryItemStatus" => "Active",
"serialNumber" => "SN12345",
"macAddress" => "AA:BB:CC:DD:EE:FF",
"ipAddress" => "10.0.0.1",
"inventoryModel" => %{
"status" => "Active",
"ipAddressV4" => "10.0.0.1",
"model" => %{
"name" => "airFiber 5XHD",
"manufacturer" => %{"name" => "Ubiquiti"}
"manufacturer" => %{"name" => "Ubiquiti"},
"category" => %{"name" => "AP"}
},
"inventoryModelCategory" => %{"name" => "AP"},
"account" => %{"id" => "acct-1"},
"networkSite" => %{"id" => "site-1"}
"assignation" => %{
"assigneeType" => "Account",
"assignee" => %{"id" => "acct-1"}
}
}
}
],
@ -238,11 +236,13 @@ defmodule Towerops.Gaiia.SyncTest do
%{
"node" => %{
"id" => "sub-1",
"billingSubscriptionStatus" => "Active",
"product" => %{"name" => "100Mbps Unlimited"},
"recurringAmount" => "79.99",
"currency" => "USD",
"account" => %{"id" => "acct-1"}
"status" => "Active",
"productVersion" => %{
"product" => %{"name" => "100Mbps Unlimited"},
"price" => 7999,
"currency" => "USD"
},
"entity" => %{"id" => "acct-1"}
}
}
],

View file

@ -62,8 +62,8 @@ defmodule Towerops.Workers.GaiiaSyncWorkerTest do
"node" => %{
"id" => "acct-1",
"name" => "Test Account",
"accountStatus" => "Active",
"accountBillingSubscriptions" => %{"edges" => []}
"status" => "Active",
"billingSubscriptions" => %{"edges" => []}
}
}
],