Skip to content

Commit

Permalink
Add new filters options to graphql and export of credit notes
Browse files Browse the repository at this point in the history
  • Loading branch information
floganz committed Dec 20, 2024
1 parent 1f96976 commit b5c72f0
Show file tree
Hide file tree
Showing 13 changed files with 924 additions and 109 deletions.
34 changes: 34 additions & 0 deletions app/graphql/mutations/data_exports/credit_notes/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Mutations
module DataExports
module CreditNotes
class Create < BaseMutation
include AuthenticableApiUser
include RequiredOrganization

REQUIRED_PERMISSION = 'credit_notes:export'

graphql_name 'CreateCreditNotesDataExport'
description 'Request data export of credit notes'

input_object_class Types::DataExports::CreditNotes::CreateInput

type Types::DataExports::Object

def resolve(format:, filters:, resource_type:)
result = ::DataExports::CreateService
.call(
organization: current_organization,
user: context[:current_user],
format:,
resource_type:,
resource_query: filters
)

result.success? ? result.data_export : result_error(result)
end
end
end
end
end
37 changes: 26 additions & 11 deletions app/graphql/resolvers/credit_notes_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,43 @@ class CreditNotesResolver < Resolvers::BaseResolver

description 'Query credit notes'

argument :customer_id, ID, required: false
argument :amount_from, Integer, required: false
argument :amount_to, Integer, required: false
argument :credit_status, [Types::CreditNotes::CreditStatusTypeEnum], required: false
argument :currency, Types::CurrencyEnum, required: false
argument :customer_external_id, String, required: false
argument :customer_id, ID, required: false, description: 'Uniq ID of the customer'
argument :invoice_number, String, required: false
argument :issuing_date_from, GraphQL::Types::ISO8601Date, required: false
argument :issuing_date_to, GraphQL::Types::ISO8601Date, required: false
argument :limit, Integer, required: false
argument :page, Integer, required: false
argument :reason, [Types::CreditNotes::ReasonTypeEnum], required: false
argument :refund_status, [Types::CreditNotes::RefundStatusTypeEnum], required: false
argument :search_term, String, required: false

type Types::CreditNotes::Object.collection_type, null: false

def resolve(
page: nil,
limit: nil,
search_term: nil,
customer_id: nil
)
def resolve(args)
result = CreditNotesQuery.call(
organization: current_organization,
search_term:,
search_term: args[:search_term],
filters: {
customer_id:
amount_from: args[:amount_from],
amount_to: args[:amount_to],
credit_status: args[:credit_status],
currency: args[:currency],
customer_external_id: args[:customer_external_id],
customer_id: args[:customer_id],
invoice_number: args[:invoice_number],
issuing_date_from: args[:issuing_date_from],
issuing_date_to: args[:issuing_date_to],
reason: args[:reason],
refund_status: args[:refund_status]
},
pagination: {
page:,
limit:
page: args[:page],
limit: args[:limit]
}
)

Expand Down
15 changes: 15 additions & 0 deletions app/graphql/types/data_exports/credit_notes/create_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Types
module DataExports
module CreditNotes
class CreateInput < Types::BaseInputObject
graphql_name 'CreateDataExportsCreditNotesInput'

argument :filters, Types::DataExports::CreditNotes::FiltersInput
argument :format, Types::DataExports::FormatTypeEnum
argument :resource_type, Types::DataExports::CreditNotes::ExportTypeEnum
end
end
end
end
14 changes: 14 additions & 0 deletions app/graphql/types/data_exports/credit_notes/export_type_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Types
module DataExports
module CreditNotes
class ExportTypeEnum < Types::BaseEnum
graphql_name 'CreditNoteExportTypeEnum'

value 'credit_notes'
value 'credit_note_items'
end
end
end
end
25 changes: 25 additions & 0 deletions app/graphql/types/data_exports/credit_notes/filters_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Types
module DataExports
module CreditNotes
class FiltersInput < BaseInputObject
graphql_name 'DataExportCreditNoteFiltersInput'
description 'Export credit notes search query and filters input argument'

argument :amount_from, Integer, required: false
argument :amount_to, Integer, required: false
argument :credit_status, [Types::CreditNotes::CreditStatusTypeEnum], required: false
argument :currency, Types::CurrencyEnum, required: false
argument :customer_external_id, String, required: false
argument :customer_id, ID, required: false, description: 'Uniq ID of the customer'
argument :invoice_number, String, required: false
argument :issuing_date_from, GraphQL::Types::ISO8601Date, required: false
argument :issuing_date_to, GraphQL::Types::ISO8601Date, required: false
argument :reason, [Types::CreditNotes::ReasonTypeEnum], required: false
argument :refund_status, [Types::CreditNotes::RefundStatusTypeEnum], required: false
argument :search_term, String, required: false
end
end
end
end
2 changes: 2 additions & 0 deletions app/graphql/types/data_exports/invoices/export_type_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Types
module DataExports
module Invoices
class ExportTypeEnum < Types::BaseEnum
graphql_name 'InvoiceExportTypeEnum'

value 'invoices'
value 'invoice_fees'
end
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MutationType < Types::BaseObject
field :generate_customer_portal_url, mutation: Mutations::CustomerPortal::GenerateUrl
field :update_customer_portal_customer, mutation: Mutations::CustomerPortal::UpdateCustomer

field :create_credit_notes_data_export, mutation: Mutations::DataExports::CreditNotes::Create
field :create_invoices_data_export, mutation: Mutations::DataExports::Invoices::Create

field :create_subscription, mutation: Mutations::Subscriptions::Create
Expand Down
84 changes: 77 additions & 7 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5c72f0

Please sign in to comment.