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