fix: last completed date

This commit is contained in:
Moritz Böhme 2025-04-07 10:13:00 +02:00
parent a5504e6e6e
commit 3c4f868f12
2 changed files with 14 additions and 6 deletions

View file

@ -9,13 +9,23 @@ defmodule Putzplan.Tasks.Task do
end
calculations do
calculate :last_completed,
:date,
expr(
fragment(
"SELECT c.completion FROM \"completed_tasks\" AS c WHERE c.task_id = ? ORDER BY c.completion DESC LIMIT 1",
id
) || today()
)
calculate :due,
:date,
expr(
fragment(
"SELECT strftime('%F', ?)", # HACK: to cast to date
# HACK: to cast to date
"SELECT strftime('%F', ?)",
date_add(
completed_tasks.completion || today(),
last_completed,
repetition_days,
:day
)
@ -29,9 +39,7 @@ defmodule Putzplan.Tasks.Task do
end
relationships do
has_many :completed_tasks, Putzplan.Tasks.CompletedTask do
sort [:completion]
end
has_many :completed_tasks, Putzplan.Tasks.CompletedTask
end
# Attributes are the simple pieces of data that exist on your resource

View file

@ -65,7 +65,7 @@ defmodule PutzplanWeb.TaskLive.Index do
def mount(_params, _session, socket) do
{:ok,
socket
|> stream(:tasks, Ash.read!(Putzplan.Tasks.Task, actor: socket.assigns[:current_user]) |> Ash.load!(:due))
|> stream(:tasks, Ash.read!(Putzplan.Tasks.Task, load: [:due], actor: socket.assigns[:current_user]))
|> assign_new(:current_user, fn -> nil end)}
end