Sha256: b3fa4d38796fa75cab7296cc4e270a63fa520e0a9f022eed652858ee7eef0379

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

module Logistics
  module Core
    class AdditionalDocumentService < BaseService
      def get_lookup_values(entity)
        clazz = entity.constantize
        clazz.all
      end

      def get_additional_documents(entity, rec_id)
        clazz = entity.constantize
        clazz.find(rec_id).additional_documents
      end

      def bulk_save(payload)
        error = ''
        success = true
        begin
          AdditionalDocument.create!(payload)
        rescue => e
          success = false
          error = 'Some records could not be saved!'
        end
        [success, error]
      end

      def bulk_update(payload)
        errors = []
        success = true
        payload.each do |p|
          ad = AdditionalDocument.find(p[:id])
          begin
            ad.update!(p)
          rescue => e
            success = false
            error << ad.id
          end
        end
        [success, errors]
      end

      def bulk_delete(ids)
        error = ''
        success = true
        begin
          AdditionalDocument.where(:id => ids).destroy_all
        rescue => e
          success = false
          error = 'Could not delete all records'
        end
        [success, error]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/services/logistics/core/additional_document_service.rb
logistics_core-21.11.1 app/services/logistics/core/additional_document_service.rb
logistics_core-21.08.1 app/services/logistics/core/additional_document_service.rb
logistics_core-21.03.1 app/services/logistics/core/additional_document_service.rb
logistics_core-20.10.3 app/services/logistics/core/additional_document_service.rb
logistics_core-20.10.2 app/services/logistics/core/additional_document_service.rb
logistics_core-20.10.1 app/services/logistics/core/additional_document_service.rb
logistics_core-20.9.1 app/services/logistics/core/additional_document_service.rb
logistics_core-20.8.1 app/services/logistics/core/additional_document_service.rb