Fix route ordering: /search before /{asset_id}
- /api/assets/search must be registered before /api/assets/{asset_id}
to prevent FastAPI path param from catching 'search' as an asset_id.
Returning a 422 with array detail caused frontend to show [object Object].
- Improve error message extraction in clearAssetGps catch block.
This commit is contained in:
+10
-11
@@ -1586,17 +1586,6 @@ def export_checkins_csv(asset_id: Optional[int] = Query(None)):
|
||||
# ─── Asset GPS Management ──────────────────────────────────────────────────
|
||||
|
||||
|
||||
@app.get("/api/assets/{asset_id}")
|
||||
def get_asset_admin(asset_id: int):
|
||||
"""Get a single asset by ID (admin)."""
|
||||
conn = get_db()
|
||||
row = conn.execute("SELECT * FROM assets WHERE id = ?", (asset_id,)).fetchone()
|
||||
conn.close()
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Asset not found")
|
||||
return row_to_dict(row)
|
||||
|
||||
|
||||
@app.get("/api/assets/search")
|
||||
def search_assets_admin(machine_id: str = Query(...)):
|
||||
"""Search for an asset by machine_id (admin)."""
|
||||
@@ -1610,6 +1599,16 @@ def search_assets_admin(machine_id: str = Query(...)):
|
||||
return row_to_dict(row)
|
||||
|
||||
|
||||
@app.get("/api/assets/{asset_id}")
|
||||
def get_asset_admin(asset_id: int):
|
||||
"""Get a single asset by ID (admin)."""
|
||||
conn = get_db()
|
||||
row = conn.execute("SELECT * FROM assets WHERE id = ?", (asset_id,)).fetchone()
|
||||
conn.close()
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Asset not found")
|
||||
return row_to_dict(row)
|
||||
|
||||
@app.delete("/api/assets/{asset_id}/gps", status_code=204)
|
||||
def clear_asset_gps(asset_id: int):
|
||||
"""Clear GPS coordinates from an asset (sets latitude/longitude to NULL)."""
|
||||
|
||||
+5
-1
@@ -2169,7 +2169,11 @@ async function clearAssetGps() {
|
||||
showToast('GPS data cleared');
|
||||
} catch (e) {
|
||||
resultEl.style.display = '';
|
||||
resultEl.innerHTML = '<span style="color:var(--red);">' + esc(e.message) + '</span>';
|
||||
const errMsg = (e && typeof e.message === 'string') ? e.message
|
||||
: (typeof e === 'string') ? e
|
||||
: (e && e.detail && typeof e.detail === 'string') ? e.detail
|
||||
: 'Unknown error';
|
||||
resultEl.innerHTML = '<span style="color:var(--red);">' + esc(errMsg) + '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user