summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/packages/destroy_file.rb
blob: c7dd2df704ee092d93812e286eadcbe004510593 (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
# frozen_string_literal: true

module Mutations
  module Packages
    class DestroyFile < ::Mutations::BaseMutation
      graphql_name 'DestroyPackageFile'

      authorize :destroy_package

      argument :id,
               ::Types::GlobalIDType[::Packages::PackageFile],
               required: true,
               description: 'ID of the Package file.'

      def resolve(id:)
        package_file = authorized_find!(id: id)

        if package_file.update(status: :pending_destruction)
          return { errors: [] }
        end

        { errors: package_file.errors.full_messages }
      end
    end
  end
end