Skip to content

Commit

Permalink
Add a deposit form link to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Oct 19, 2024
1 parent 9798b2d commit 55cf881
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/graphql/mutations/essence_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class EssenceCreate < BaseMutation
argument :attributes, Types::EssenceAttributes, required: true

def resolve(item_identifier:, collection_identifier:, filename:, attributes:)
raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated]

collection = Collection.find_by(identifier: collection_identifier)

item = collection.items.find_by(identifier: item_identifier)
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/mutations/essence_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class EssenceUpdate < BaseMutation
argument :attributes, Types::EssenceAttributes, required: true

def resolve(id:, attributes:)
raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated]

essence = ::Essence.find(id)
raise GraphQL::ExecutionError.new 'Error updating essence', extensions: essence.errors.to_hash unless essence.update(**attributes)

Expand Down
20 changes: 20 additions & 0 deletions app/graphql/mutations/set_collection_has_deposit_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Mutations
class SetCollectionHasDepositForm < BaseMutation
description 'Marks as collection a having a deposit form'

argument :identifier, String, required: true

def resolve(identifier:)
raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated]

collection = ::Collection.find_by(identifier:)
collection.has_deposit_form = true

raise GraphQL::ExecutionError.new 'Error updating collection', extensions: collection.errors.to_hash unless collection.save

{}
end
end
end
1 change: 1 addition & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Types
class MutationType < Types::BaseObject
field :essence_update, mutation: Mutations::EssenceUpdate
field :essence_create, mutation: Mutations::EssenceCreate
field :set_collection_has_deposit_form, mutation: Mutations::SetCollectionHasDepositForm
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHasDepositFormToCollection < ActiveRecord::Migration[7.2]
def change
add_column :collections, :has_deposit_form, :boolean
end
end
31 changes: 31 additions & 0 deletions nabu.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ type Mutation {
"""
input: EssenceUpdateInput!
): EssenceUpdatePayload

"""
Marks as collection a having a deposit form
"""
setCollectionHasDepositForm(
"""
Parameters for SetCollectionHasDepositForm
"""
input: SetCollectionHasDepositFormInput!
): SetCollectionHasDepositFormPayload
}

type Person {
Expand Down Expand Up @@ -343,6 +353,27 @@ type Query {
userByUnikey(unikey: String!): EmailUser
}

"""
Autogenerated input type of SetCollectionHasDepositForm
"""
input SetCollectionHasDepositFormInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
identifier: String!
}

"""
Autogenerated return type of SetCollectionHasDepositForm.
"""
type SetCollectionHasDepositFormPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
}

type University {
collections: [Collection]
id: ID!
Expand Down

0 comments on commit 55cf881

Please sign in to comment.