Fix todo due date also counting completed items

This commit is contained in:
2026-03-04 14:43:01 +01:00
parent 8ff955415c
commit 4ee1d01e38
4 changed files with 21 additions and 7 deletions
@@ -19,14 +19,16 @@ public function index()
$query->where('notable_type', 'App\Models\PipelineItem');
}])
->withCount(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem');
$query
->where('todoable_type', 'App\Models\PipelineItem')
->whereNotIn('status', ['completed', 'COMPLETED']);
}])
->orderBy('position')
->get();
$pipelineItemsArray = $pipelineItems->map(function ($item) {
$itemArray = $item->toArray();
$itemArray['next_todo_due_date'] = $item->todos->first()?->due_date?->toISOString() ?? null;
$itemArray['next_todo_due_date'] = $item->todos()->where('status', '!=', 'COMPLETED')->first()?->due_date?->toISOString() ?? null;
unset($itemArray['todos']); // Remove the todos array
return $itemArray;
});
@@ -43,7 +45,8 @@ public function single(int $id)
::with(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem')->orderBy('created_at', 'desc');
}])->with(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem')->orderBy('due_date', 'asc');
$query
->where('todoable_type', 'App\Models\PipelineItem')->orderBy('due_date', 'asc');
}])->orderBy('position')->findOrFail($id);
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());