add.rb 857 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Form::UploadCache::Add < BaseMutation
  4. description 'Upload files for a form'
  5. argument :form_id, Gql::Types::FormIdType, 'FormID for the uploads.'
  6. argument :files, [Gql::Types::Input::UploadFileInputType], 'Files to be uploaded.'
  7. field :uploaded_files, [Gql::Types::StoredFileType], null: false, description: 'Information about the uploaded files.'
  8. def resolve(form_id:, files:)
  9. cache = UploadCache.new(form_id)
  10. result = files.map do |file|
  11. cache.add(
  12. data: file.content,
  13. filename: file.name,
  14. preferences: { 'Content-Type' => file.type },
  15. created_by_id: context.current_user.id
  16. )
  17. end
  18. { uploaded_files: result }
  19. end
  20. end
  21. end