fix empty get

This commit is contained in:
2025-12-10 02:49:07 +00:00
parent 5e7d2f9a77
commit dfb2a3ba6e

View File

@@ -5,12 +5,12 @@ header('Content-Type: application/json');
$dbconn = getDBConnection(); $dbconn = getDBConnection();
// Default endpoint: Get current point outages // Default endpoint: Get current point outages
if (empty($_GET)) { if (empty(array_diff_key($_GET, array('service' => '')))) {
try { try {
$query = " $query = "
SELECT json_build_object( SELECT json_build_object(
'type', 'FeatureCollection', 'type', 'FeatureCollection',
'features', json_agg( 'features', COALESCE(json_agg(
json_build_object( json_build_object(
'type', 'Feature', 'type', 'Feature',
'geometry', ST_AsGeoJSON(geom)::json, 'geometry', ST_AsGeoJSON(geom)::json,
@@ -19,16 +19,16 @@ if (empty($_GET)) {
'county', county, 'county', county,
'state', state, 'state', state,
'outage', outagen, 'outage', outagen,
'lastchange', last_change, 'lastchange', last_change,
'cause', cause, 'cause', COALESCE(cause, ''),
'area_geometry', ST_AsGeoJSON(COALESCE(realareageom, geom))::json 'area_geometry', ST_AsGeoJSON(COALESCE(realareageom, geom))::json
) )
) )
ORDER BY start_time ASC ORDER BY start_time ASC
) ), '[]'::json)
) as geojson ) as geojson
FROM newpower FROM newpower
WHERE cwa = $1 AND active = true WHERE cwa = $1 AND active = true AND geom IS NOT NULL
"; ";
$result = pg_query_params($dbconn, $query, array('RLX')); $result = pg_query_params($dbconn, $query, array('RLX'));
@@ -47,7 +47,7 @@ if (empty($_GET)) {
pg_free_result($result); pg_free_result($result);
} catch (Exception $e) { } catch (Exception $e) {
http_response_code(500); http_response_code(500);
die(json_encode(['error' => 'Query execution failed: ' . $e->getMessage()])); echo json_encode(['error' => 'Query execution failed: ' . $e->getMessage()]);
} }
} }