fix: auto-update asset lat/lng on check-in so map shows pins
Previously assets never had coordinates populated - only checkins did. Now when a checkin is created with GPS data, the asset's latitude/longitude fields are auto-updated. Also backfilled existing assets from their latest checkin history. This fixes empty maps — loadAssetPins() filters by a.latitude != null.
This commit is contained in:
@@ -1106,6 +1106,14 @@ def create_checkin(body: CheckinCreate):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
checkin_id = cursor.lastrowid
|
checkin_id = cursor.lastrowid
|
||||||
|
|
||||||
|
# Auto-update asset's last known location
|
||||||
|
if body.latitude is not None and body.longitude is not None:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE assets SET latitude = ?, longitude = ? WHERE id = ?",
|
||||||
|
(body.latitude, body.longitude, body.asset_id),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
# Auto-log visit
|
# Auto-log visit
|
||||||
row = conn.execute("SELECT created_at FROM checkins WHERE id = ?", (checkin_id,)).fetchone()
|
row = conn.execute("SELECT created_at FROM checkins WHERE id = ?", (checkin_id,)).fetchone()
|
||||||
_auto_log_visit(conn, body.user_id, body.asset_id, row["created_at"])
|
_auto_log_visit(conn, body.user_id, body.asset_id, row["created_at"])
|
||||||
|
|||||||
Reference in New Issue
Block a user