Loading...
Trace | Cenit Admin
+ 33 update
2020-01-22 22:15:43 UTC
No message
  • ns_omna = Cenit.namespace(:OMNAv2)
  • do_notify = ns_omna.algorithm(:do_notify)
  • integration = ns_omna.data_type(:Integration).where(id: integration_id).first
  • # Destroy its authorization
  • begin
  • do_notify.run(['Deleting its authorization.', :info, task])
  • integration.authorization && integration.authorization.destroy
  • end
  • # Destroy its records of Order, Variant and Product
  • begin
  • ns_channel = Cenit.namespace(integration.channel)
  • condition = { integration: { 'id' => integration.id } }
  • dts = %i(Order Variant Product)
  • dts.each do |dt_name|
  • if dt = ns_channel.data_type(dt_name)
  • do_notify.run(["Deleting the records of its #{dt_name.to_s.downcase.pluralize}.", :info, task])
  • ns_omna.data_type(dt_name).where(condition).map(&:destroy)
  • dt.where(condition).map(&:destroy)
  • end
  • end
  • end
  • # Destroy the integration
  • begin
  • msg = "The integration '#{integration.name}' of '#{integration.channel}' has been eliminated."
  • integration.destroy
  • do_notify.run([msg, :info, task])
  • end
  • true