fix: Handle additional parser fields causing insertion failures

The parser is sending fields with different names than our schema:
- aprs_messaging? (with question mark) -> convert to aprs_messaging
- raw_data -> remove (not in schema)

This should fix the remaining packet insertion failures in production.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-08-04 10:30:52 -05:00
parent a7c4993a0b
commit 49e647e609
No known key found for this signature in database

View file

@ -312,6 +312,7 @@ defmodule Aprsme.PacketConsumer do
# Apply the same processing as the original store_packet function
attrs
|> convert_coordinate_field_names()
|> convert_field_names()
|> normalize_packet_attrs()
|> set_received_at()
|> patch_lat_lon_from_data_extended()
@ -392,6 +393,11 @@ defmodule Aprsme.PacketConsumer do
|> Map.delete("longitude")
|> Map.delete(:latitude)
|> Map.delete("latitude")
# Fields with naming mismatches
|> Map.delete(:aprs_messaging?)
|> Map.delete("aprs_messaging?")
|> Map.delete(:raw_data)
|> Map.delete("raw_data")
end
# Helper functions for coordinate validation and point creation
@ -474,6 +480,23 @@ defmodule Aprsme.PacketConsumer do
end
end
# Convert field names that don't match our schema
defp convert_field_names(attrs) do
then(attrs, fn a ->
# Convert aprs_messaging? to aprs_messaging
case Map.get(a, :aprs_messaging?) || Map.get(a, "aprs_messaging?") do
nil ->
a
value ->
a
|> Map.put(:aprs_messaging, value)
|> Map.delete(:aprs_messaging?)
|> Map.delete("aprs_messaging?")
end
end)
end
# Convert latitude/longitude to lat/lon if present at top level
defp convert_coordinate_field_names(attrs) do
attrs