I have a resource Task
I need to calculate overdue tasks based on their status: in_progres and due_date: less than current date.
defmodule Ash.Task do
use Ash.Resource,
otp_app: :ash,
domain: Ash.Assignments,
data_layer: AshPostgres.DataLayer
postgres do
table "tasks"
repo Ash.Repo
end
actions do
default_accept [:title, :description, :due_date, :status, :story_point]
defaults [:create, :read, :update, :destroy]
end
attributes do
uuid_primary_key :id
attribute :title, :string
attribute :description, :string
attribute :status, :atom, public?: true, constraints: [one_of: [:todo, :in_progress, :done]]
attribute :due_date, :utc_datetime, public?: true
attribute :story_point, :integer
timestamps()
end
end
Ash.Task
|> Ash.Query.calculate(:overdue_tasks, :integer, filter: [status: :in_progress, due_date: [less_than: DateTime.utc_now])
|> Ash.read!()
How to write correct filter exp for query calculate?