diff --git a/app/graphql/types/budget_investment_type.rb b/app/graphql/types/budget_investment_type.rb index 00b6f32a0..15b1bd0d1 100644 --- a/app/graphql/types/budget_investment_type.rb +++ b/app/graphql/types/budget_investment_type.rb @@ -9,5 +9,6 @@ module Types field :location, String, null: true field :comments, Types::CommentType.connection_type, null: true field :comments_count, Integer, null: true + field :milestones, Types::MilestoneType.connection_type, null: true end end diff --git a/app/graphql/types/milestone_type.rb b/app/graphql/types/milestone_type.rb new file mode 100644 index 000000000..c7b9dd30f --- /dev/null +++ b/app/graphql/types/milestone_type.rb @@ -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 diff --git a/app/graphql/types/proposal_type.rb b/app/graphql/types/proposal_type.rb index 40b39cd01..7d9eb78a6 100644 --- a/app/graphql/types/proposal_type.rb +++ b/app/graphql/types/proposal_type.rb @@ -20,6 +20,7 @@ module Types field :title, String, null: true field :video_url, String, null: true field :votes_for, Types::VoteType.connection_type, null: true + field :milestones, Types::MilestoneType.connection_type, null: true def tags object.tags.public_for_api diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 4e7697218..cb823c8dd 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -20,6 +20,11 @@ module Types argument :id, ID, required: true, default_value: false 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 :proposal, Types::ProposalType, "Returns proposal for ID", null: false do argument :id, ID, required: true, default_value: false @@ -84,6 +89,14 @@ module Types Geozone.find(id) end + def milestones + Milestone.public_for_api + end + + def milestone(id:) + Milestone.find(id) + end + def proposals Proposal.public_for_api end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 47d2d2d03..b1794c652 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -16,6 +16,9 @@ class Milestone < ApplicationRecord scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) } scope :published, -> { where(publication_date: ..Date.current.end_of_day) } 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 80 diff --git a/docs/en/features/graphql.md b/docs/en/features/graphql.md index c6141eb95..c28d9deab 100644 --- a/docs/en/features/graphql.md +++ b/docs/en/features/graphql.md @@ -133,6 +133,7 @@ The models are the following: | `Budget` | Participatory budgets | | `Budget::Investment` | Budget investments | | `Comment` | Comments on debates, proposals and other comments | +| `Milestone` | Proposals, investments and processes milestones | | `Geozone` | Geozones (districts) | | `ProposalNotification` | Notifications related to proposals | | `Tag` | Tags on debates and proposals | diff --git a/docs/es/features/graphql.md b/docs/es/features/graphql.md index 0048fbb02..d4bb79a66 100644 --- a/docs/es/features/graphql.md +++ b/docs/es/features/graphql.md @@ -133,6 +133,7 @@ La lista de modelos es la siguiente: | `Budget` | Presupuestos participativos | | `Budget::Investment` | Proyectos de gasto | | `Comment` | Comentarios en debates, propuestas y otros comentarios | +| `Milestone` | Hitos en propuestas, proyectos de gasto y procesos | | `Geozone` | Geozonas (distritos) | | `ProposalNotification` | Notificaciones asociadas a propuestas | | `Tag` | Tags en debates y propuestas | diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index c39939c8c..f03f42ecb 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -678,6 +678,16 @@ describe "Consul Schema" do 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 it "does not include hidden comments" do budget = create(:budget)