resolv.ex (2409B)
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.Proposal.Resolv do 19 @moduledoc false 20 21 alias Zenflows.GQL.Connection 22 alias Zenflows.VF.Proposal.Domain 23 24 def proposal(params, _) do 25 Domain.one(params) 26 end 27 28 def proposals(params, _) do 29 with {:ok, page} <- Connection.parse(params), 30 {:ok, schemas} <- Domain.all(page) do 31 {:ok, Connection.from_list(schemas, page)} 32 end 33 end 34 35 def offers(_params, _) do 36 {:ok, %{ 37 edges: [], 38 page_info: %{ 39 has_previous_page: false, 40 has_next_page: false, 41 }, 42 }} 43 end 44 45 def requests(_params, _) do 46 {:ok, %{ 47 edges: [], 48 page_info: %{ 49 has_previous_page: false, 50 has_next_page: false, 51 }, 52 }} 53 end 54 55 def create_proposal(%{proposal: params}, _) do 56 with {:ok, prop} <- Domain.create(params) do 57 {:ok, %{proposal: prop}} 58 end 59 end 60 61 def update_proposal(%{proposal: %{id: id} = params}, _) do 62 with {:ok, prop} <- Domain.update(id, params) do 63 {:ok, %{proposal: prop}} 64 end 65 end 66 67 def delete_proposal(%{id: id}, _) do 68 with {:ok, _} <- Domain.delete(id) do 69 {:ok, true} 70 end 71 end 72 73 def created(%{id: id}, _, _) do 74 Zenflows.DB.ID.ts(id) 75 end 76 77 def eligible_location(prop, _, _) do 78 prop = Domain.preload(prop, :eligible_location) 79 {:ok, prop.eligible_location} 80 end 81 82 def publishes(prop, _, _) do 83 prop = Domain.preload(prop, :publishes) 84 {:ok, prop.publishes} 85 end 86 87 def primary_intents(prop, _, _) do 88 prop = Domain.preload(prop, :primary_intents) 89 {:ok, prop.primary_intents} 90 end 91 92 def reciprocal_intents(prop, _, _) do 93 prop = Domain.preload(prop, :reciprocal_intents) 94 {:ok, prop.reciprocal_intents} 95 end 96 97 def status(prop, _, _) do 98 Domain.status(prop) 99 end 100 end