resolv.ex (3548B)
1 # Zenflows is designed to implement the Valueflows vocabulary, 2 # written and maintained by srfsh <info@dyne.org>. 3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>. 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Affero General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Affero General Public License for more details. 14 # 15 # You should have received a copy of the GNU Affero General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 defmodule Zenflows.VF.EconomicEvent.Resolv do 19 @moduledoc false 20 21 use Absinthe.Schema.Notation 22 23 alias Zenflows.GQL.Connection 24 alias Zenflows.VF.EconomicEvent.Domain 25 26 def economic_event(params, _) do 27 Domain.one(params) 28 end 29 30 def economic_events(params, _) do 31 with {:ok, page} <- Connection.parse(params), 32 {:ok, schemas} <- Domain.all(page) do 33 {:ok, Connection.from_list(schemas, page)} 34 end 35 end 36 37 def create_economic_event(%{event: evt_params} = params, _) do 38 res_params = params[:new_inventoried_resource] 39 with {:ok, evt} <- Domain.create(evt_params, res_params) do 40 {:ok, %{economic_event: evt}} 41 end 42 end 43 44 def update_economic_event(%{economic_event: %{id: id} = params}, _) do 45 with {:ok, eco_evt} <- Domain.update(id, params) do 46 {:ok, %{economic_event: eco_evt}} 47 end 48 end 49 50 def action(eco_evt, _, _) do 51 eco_evt = Domain.preload(eco_evt, :action) 52 {:ok, eco_evt.action} 53 end 54 55 def input_of(eco_evt, _, _) do 56 eco_evt = Domain.preload(eco_evt, :input_of) 57 {:ok, eco_evt.input_of} 58 end 59 60 def output_of(eco_evt, _, _) do 61 eco_evt = Domain.preload(eco_evt, :output_of) 62 {:ok, eco_evt.output_of} 63 end 64 65 def provider(eco_evt, _, _) do 66 eco_evt = Domain.preload(eco_evt, :provider) 67 {:ok, eco_evt.provider} 68 end 69 70 def receiver(eco_evt, _, _) do 71 eco_evt = Domain.preload(eco_evt, :receiver) 72 {:ok, eco_evt.receiver} 73 end 74 75 def resource_inventoried_as(eco_evt, _, _) do 76 eco_evt = Domain.preload(eco_evt, :resource_inventoried_as) 77 {:ok, eco_evt.resource_inventoried_as} 78 end 79 80 def to_resource_inventoried_as(eco_evt, _, _) do 81 eco_evt = Domain.preload(eco_evt, :to_resource_inventoried_as) 82 {:ok, eco_evt.to_resource_inventoried_as} 83 end 84 85 def resource_quantity(eco_evt, _, _) do 86 eco_evt = Domain.preload(eco_evt, :resource_quantity) 87 {:ok, eco_evt.resource_quantity} 88 end 89 90 def effort_quantity(eco_evt, _, _) do 91 eco_evt = Domain.preload(eco_evt, :effort_quantity) 92 {:ok, eco_evt.effort_quantity} 93 end 94 95 def resource_conforms_to(eco_evt, _, _) do 96 eco_evt = Domain.preload(eco_evt, :resource_conforms_to) 97 {:ok, eco_evt.resource_conforms_to} 98 end 99 100 def to_location(eco_evt, _, _) do 101 eco_evt = Domain.preload(eco_evt, :to_location) 102 {:ok, eco_evt.to_location} 103 end 104 105 def at_location(eco_evt, _, _) do 106 eco_evt = Domain.preload(eco_evt, :at_location) 107 {:ok, eco_evt.at_location} 108 end 109 110 def realization_of(eco_evt, _, _) do 111 eco_evt = Domain.preload(eco_evt, :realization_of) 112 {:ok, eco_evt.realization_of} 113 end 114 115 def triggered_by(eco_evt, _, _) do 116 eco_evt = Domain.preload(eco_evt, :triggered_by) 117 {:ok, eco_evt.triggered_by} 118 end 119 120 def previous_event(eco_evt, _, _) do 121 eco_evt = Domain.preload(eco_evt, :previous_event) 122 {:ok, eco_evt.previous_event} 123 end 124 125 def previous(eco_evt, _, _) do 126 {:ok, Domain.previous(eco_evt)} 127 end 128 end