Skip to content

Commit

Permalink
[TM-1407] Filter approved sites and polygons in query dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
LimberHope committed Nov 11, 2024
1 parent 5522f6e commit 2fc02a6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Helpers/TerrafundDashboardQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function buildQueryFromRequest(Request $request)
public static function retrievePolygonUuidsForProject($projectUuId)
{
$project = Project::where('uuid', $projectUuId)->first();
$sitePolygons = $project->sitePolygons;
$sitePolygons = $project->sitePolygons->where('status', 'approved');

$polygonsIds = $sitePolygons->pluck('poly_id');

Expand Down
2 changes: 1 addition & 1 deletion app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ private function approvedSiteReportIds(): HasManyThrough

public function getTotalSitePolygonsAttribute()
{
return $this->sitePolygons()->count();
return $this->sitePolygons()->where('status', 'approved')->count();
}

public function getTotalHectaresRestoredSumAttribute(): float
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Dashboard/RunHectaresRestoredService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Helpers\TerrafundDashboardQueryHelper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\V2\Sites\Site;

class RunHectaresRestoredService
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getProjectsPolygons($projects)
return DB::table('site_polygon as sp')
->join('v2_sites as s', 'sp.site_id', '=', 's.uuid')
->join('v2_projects as p', 's.project_id', '=', 'p.id')
->where('s.status', 'approved')
->whereIn('s.status', Site::$approvedStatuses)
->where('sp.status', 'approved')
->whereIn('p.uuid', $projects)
->select('sp.id')
Expand Down

0 comments on commit 2fc02a6

Please sign in to comment.