Skip to content

Commit

Permalink
[TM-1439] remove try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
LimberHope committed Nov 4, 2024
1 parent 2e47a3b commit 18d05fe
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions app/Services/Dashboard/RunHectaresRestoredService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,28 @@ class RunHectaresRestoredService
{
public function runHectaresRestoredJob(Request $request)
{
try {
$projectsToQuery = TerrafundDashboardQueryHelper::buildQueryFromRequest($request)->pluck('uuid')->toArray();
$HECTAREAS_BY_RESTORATION = 'restorationByStrategy';
$HECTAREAS_BY_TARGET_LAND_USE_TYPES = 'restorationByLandUse';
$projectsToQuery = TerrafundDashboardQueryHelper::buildQueryFromRequest($request)->pluck('uuid')->toArray();
$HECTAREAS_BY_RESTORATION = 'restorationByStrategy';
$HECTAREAS_BY_TARGET_LAND_USE_TYPES = 'restorationByLandUse';

$projectsPolygons = $this->getProjectsPolygons($projectsToQuery);
$polygonsUuids = array_column($projectsPolygons, 'uuid');
$projectsPolygons = $this->getProjectsPolygons($projectsToQuery);
$polygonsUuids = array_column($projectsPolygons, 'uuid');

$restorationStrategiesRepresented = $this->polygonToOutputHectares($HECTAREAS_BY_RESTORATION, $polygonsUuids);
$targetLandUseTypesRepresented = $this->polygonToOutputHectares($HECTAREAS_BY_TARGET_LAND_USE_TYPES, $polygonsUuids);

if (empty($restorationStrategiesRepresented) && empty($targetLandUseTypesRepresented)) {
return (object) [
'restoration_strategies_represented' => [],
'target_land_use_types_represented' => [],
'message' => 'No data available for restoration strategies and target land use types.',
];
}
$restorationStrategiesRepresented = $this->polygonToOutputHectares($HECTAREAS_BY_RESTORATION, $polygonsUuids);
$targetLandUseTypesRepresented = $this->polygonToOutputHectares($HECTAREAS_BY_TARGET_LAND_USE_TYPES, $polygonsUuids);

if (empty($restorationStrategiesRepresented) && empty($targetLandUseTypesRepresented)) {
return (object) [
'restoration_strategies_represented' => $this->calculateGroupedHectares($restorationStrategiesRepresented),
'target_land_use_types_represented' => $this->calculateGroupedHectares($targetLandUseTypesRepresented),
'restoration_strategies_represented' => [],
'target_land_use_types_represented' => [],
'message' => 'No data available for restoration strategies and target land use types.',
];
} catch (Exception $e) {
return response()->json([
'error' => 'An error occurred: ' . $e->getMessage(),
], 500);
}

return (object) [
'restoration_strategies_represented' => $this->calculateGroupedHectares($restorationStrategiesRepresented),
'target_land_use_types_represented' => $this->calculateGroupedHectares($targetLandUseTypesRepresented),
];
}

public function getProjectsPolygons($projects)
Expand Down

0 comments on commit 18d05fe

Please sign in to comment.