Skip to content

Commit

Permalink
fix: fix tasks screen showing completed tasks (monicahq/chandler#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Dec 3, 2022
1 parent 4326c98 commit b382117
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
use App\Models\User;
use App\Models\Vault;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class VaultTasksIndexViewHelper
{
public static function data(Vault $vault, User $user): Collection
{
$contacts = $vault->contacts()
->with('tasks')
->whereHas('tasks', fn (Builder $query) => $query->where('completed', false)
)
->orderBy('last_name', 'asc')
->get();

$contactsCollection = collect();
foreach ($contacts as $contact) {
$tasksCollection = $contact->tasks
->sortBy('due_at')
->map(fn ($task) => [
$tasks = DB::table('contact_tasks')
->where('completed', false)
->where('contact_id', $contact->id)
->orderBy('due_at', 'asc')
->get();

$tasksCollection = collect();
foreach ($tasks as $task) {
$tasksCollection->push([
'id' => $task->id,
'label' => $task->label,
'due_at' => $task->due_at ? DateHelper::format(Carbon::parse($task->due_at), $user) : null,
Expand All @@ -37,6 +40,7 @@ public static function data(Vault $vault, User $user): Collection
]),
],
]);
}

if ($tasksCollection->count() <= 0) {
continue;
Expand Down

0 comments on commit b382117

Please sign in to comment.