summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/design_management/upload.rb
blob: 2ccf2ef8ff5f3c535bc18949863239e0f735e143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Mutations
  module DesignManagement
    class Upload < Base
      graphql_name "DesignManagementUpload"

      argument :files, [ApolloUploadServer::Upload],
               required: true,
               description: "The files to upload."

      authorize :create_design

      field :designs, [Types::DesignManagement::DesignType],
            null: false,
            description: "The designs that were uploaded by the mutation."

      field :skipped_designs, [Types::DesignManagement::DesignType],
            null: false,
            description: "Any designs that were skipped from the upload due to there " \
                         "being no change to their content since their last version"

      def resolve(project_path:, iid:, files:)
        issue = authorized_find!(project_path: project_path, iid: iid)
        project = issue.project

        result = ::DesignManagement::SaveDesignsService.new(project, current_user, issue: issue, files: files)
                   .execute

        {
          designs: Array.wrap(result[:designs]),
          skipped_designs: Array.wrap(result[:skipped_designs]),
          errors: Array.wrap(result[:message])
        }
      end
    end
  end
end