11defmodule CodeCorps.ProjectView do
2+ alias CodeCorps.StripeService.Validators.ProjectCanEnableDonations
3+
24 use CodeCorps.PreloadHelpers ,
35 default_preloads: [
4- :donation_goals , : organization, :project_categories ,
5- :stripe_connect_plan , :project_skills , :task_lists , :tasks
6+ :donation_goals , [ organization: :stripe_connect_account ] ,
7+ :project_categories , :project_skills , :stripe_connect_plan , :task_lists , :tasks
68 ]
79 use CodeCorps.Web , :view
810 use JaSerializer.PhoenixView
911
1012 attributes [
11- :slug , :title , :description , :donations_active , :icon_thumb_url ,
13+ :slug , :title , :can_activate_donations , :description ,
14+ :donations_active , :icon_thumb_url ,
1215 :icon_large_url , :long_description_body , :long_description_markdown ,
1316 :inserted_at , :total_monthly_donated , :updated_at ]
1417
@@ -21,6 +24,13 @@ defmodule CodeCorps.ProjectView do
2124 has_many :task_lists , serializer: CodeCorps.TaskListView , identifiers: :always
2225 has_many :tasks , serializer: CodeCorps.TaskView , identifiers: :always
2326
27+ def can_activate_donations ( project , _conn ) do
28+ case ProjectCanEnableDonations . validate ( project ) do
29+ { :ok , _ } -> true
30+ { :error , _ } -> false
31+ end
32+ end
33+
2434 def donations_active ( project , _conn ) do
2535 Enum . any? ( project . donation_goals ) && project . stripe_connect_plan != nil
2636 end
0 commit comments