Add new GraphQL type for milestones

- added the milestone type to be displayed with investments
- the corresponding spec
This commit is contained in:
cyrillefr
2024-07-02 15:47:42 +02:00
committed by Javi Martín
parent 5ec6337d47
commit 18323a36c3
8 changed files with 38 additions and 0 deletions

View File

@@ -9,5 +9,6 @@ module Types
field :location, String, null: true field :location, String, null: true
field :comments, Types::CommentType.connection_type, null: true field :comments, Types::CommentType.connection_type, null: true
field :comments_count, Integer, null: true field :comments_count, Integer, null: true
field :milestones, Types::MilestoneType.connection_type, null: true
end end
end end

View File

@@ -0,0 +1,8 @@
module Types
class MilestoneType < Types::BaseObject
field :title, String, null: true
field :description, String, null: true
field :id, ID, null: false
field :publication_date, GraphQL::Types::ISO8601Date, null: true
end
end

View File

@@ -20,6 +20,7 @@ module Types
field :title, String, null: true field :title, String, null: true
field :video_url, String, null: true field :video_url, String, null: true
field :votes_for, Types::VoteType.connection_type, null: true field :votes_for, Types::VoteType.connection_type, null: true
field :milestones, Types::MilestoneType.connection_type, null: true
def tags def tags
object.tags.public_for_api object.tags.public_for_api

View File

@@ -20,6 +20,11 @@ module Types
argument :id, ID, required: true, default_value: false argument :id, ID, required: true, default_value: false
end end
field :milestones, Types::MilestoneType.connection_type, "Returns all milestones", null: false
field :milestone, Types::MilestoneType, "Returns milestone for ID", null: false do
argument :id, ID, required: true, default_value: false
end
field :proposals, Types::ProposalType.connection_type, "Returns all proposals", null: false field :proposals, Types::ProposalType.connection_type, "Returns all proposals", null: false
field :proposal, Types::ProposalType, "Returns proposal for ID", null: false do field :proposal, Types::ProposalType, "Returns proposal for ID", null: false do
argument :id, ID, required: true, default_value: false argument :id, ID, required: true, default_value: false
@@ -84,6 +89,14 @@ module Types
Geozone.find(id) Geozone.find(id)
end end
def milestones
Milestone.public_for_api
end
def milestone(id:)
Milestone.find(id)
end
def proposals def proposals
Proposal.public_for_api Proposal.public_for_api
end end

View File

@@ -16,6 +16,9 @@ class Milestone < ApplicationRecord
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) } scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
scope :published, -> { where(publication_date: ..Date.current.end_of_day) } scope :published, -> { where(publication_date: ..Date.current.end_of_day) }
scope :with_status, -> { where.not(status_id: nil) } scope :with_status, -> { where.not(status_id: nil) }
scope :public_for_api, -> do
where(milestoneable: [Proposal.public_for_api, Budget::Investment.public_for_api])
end
def self.title_max_length def self.title_max_length
80 80

View File

@@ -133,6 +133,7 @@ The models are the following:
| `Budget` | Participatory budgets | | `Budget` | Participatory budgets |
| `Budget::Investment` | Budget investments | | `Budget::Investment` | Budget investments |
| `Comment` | Comments on debates, proposals and other comments | | `Comment` | Comments on debates, proposals and other comments |
| `Milestone` | Proposals, investments and processes milestones |
| `Geozone` | Geozones (districts) | | `Geozone` | Geozones (districts) |
| `ProposalNotification` | Notifications related to proposals | | `ProposalNotification` | Notifications related to proposals |
| `Tag` | Tags on debates and proposals | | `Tag` | Tags on debates and proposals |

View File

@@ -133,6 +133,7 @@ La lista de modelos es la siguiente:
| `Budget` | Presupuestos participativos | | `Budget` | Presupuestos participativos |
| `Budget::Investment` | Proyectos de gasto | | `Budget::Investment` | Proyectos de gasto |
| `Comment` | Comentarios en debates, propuestas y otros comentarios | | `Comment` | Comentarios en debates, propuestas y otros comentarios |
| `Milestone` | Hitos en propuestas, proyectos de gasto y procesos |
| `Geozone` | Geozonas (distritos) | | `Geozone` | Geozonas (distritos) |
| `ProposalNotification` | Notificaciones asociadas a propuestas | | `ProposalNotification` | Notificaciones asociadas a propuestas |
| `Tag` | Tags en debates y propuestas | | `Tag` | Tags en debates y propuestas |

View File

@@ -678,6 +678,16 @@ describe "Consul Schema" do
end end
end end
describe "Milestone" do
it "formats publication date like in view" do
milestone = create(:milestone, publication_date: Time.zone.parse("2024-07-02 11:45:17"))
response = execute("{ milestone(id: #{milestone.id}) { id publication_date } }")
received_publication_date = dig(response, "data.milestone.publication_date")
expect(received_publication_date).to eq "2024-07-02"
end
end
describe "Budget investment" do describe "Budget investment" do
it "does not include hidden comments" do it "does not include hidden comments" do
budget = create(:budget) budget = create(:budget)