blob: 86f8de91e2b535af4022ce593848ca3299b49208 (
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
39
40
41
42
|
# frozen_string_literal: true
module Mutations
module Packages
class BulkDestroy < ::Mutations::BaseMutation
graphql_name 'DestroyPackages'
MAX_PACKAGES = 20
TOO_MANY_IDS_ERROR = "Cannot delete more than #{MAX_PACKAGES} packages"
argument :ids,
[::Types::GlobalIDType[::Packages::Package]],
required: true,
description: "Global IDs of the Packages. Max #{MAX_PACKAGES}"
def resolve(ids:)
raise_resource_not_available_error!(TOO_MANY_IDS_ERROR) if ids.size > MAX_PACKAGES
model_ids = ids.map(&:model_id)
service = ::Packages::MarkPackagesForDestructionService.new(
packages: packages_from(model_ids),
current_user: current_user
)
result = service.execute
raise_resource_not_available_error! if result.reason == :unauthorized
errors = result.error? ? Array.wrap(result[:message]) : []
{ errors: errors }
end
private
def packages_from(ids)
::Packages::Package.displayable
.id_in(ids)
end
end
end
end
|