ash_postgres/test/support/complex_calculations/resources/certification.ex
Zach Daniel 37cc01957d
improvement!: 3.0 (#227)
* WIP

* chore: fix mix.lock merge issues

* improvement: upgrade to 3.0

* chore: remove `repo.to_tenant`

* chore: continue removal of unnecessary helper

* chore: use `Ash.ToTenant`
2024-03-27 16:52:28 -04:00

53 lines
1.3 KiB
Elixir

defmodule AshPostgres.Test.ComplexCalculations.Certification do
@moduledoc false
use Ash.Resource,
domain: AshPostgres.Test.ComplexCalculations.Domain,
data_layer: AshPostgres.DataLayer
actions do
default_accept(:*)
defaults([:create, :read, :update, :destroy])
end
aggregates do
count :count_of_documented_skills, :skills do
filter(expr(removed == false and status != :pending))
end
count :count_of_approved_skills, :skills do
filter(expr(removed == false and status == :approved))
end
count :count_of_skills, :skills do
filter(expr(removed == false))
end
end
attributes do
uuid_primary_key(:id)
end
calculations do
calculate :all_documentation_approved, :boolean do
calculation(expr(count_of_skills == count_of_approved_skills))
load([:count_of_skills, :count_of_approved_skills])
end
calculate :some_documentation_created, :boolean do
calculation(expr(count_of_documented_skills > 0 && all_documentation_approved == false))
load([:count_of_documented_skills, :all_documentation_approved])
end
end
postgres do
table "complex_calculations_certifications"
repo(AshPostgres.TestRepo)
end
relationships do
has_many(:skills, AshPostgres.Test.ComplexCalculations.Skill) do
public?(true)
end
end
end