4 Commits

Author SHA1 Message Date
63218e7f42 Fixed formating 2024-08-19 23:28:54 -04:00
7f0bb3cae7 Removed extra end 2024-08-19 23:26:43 -04:00
ad7417c233 Moved work into thread to repsond quickly 2024-08-19 23:21:56 -04:00
cf0be2336b Removed sync button from sidebar 2024-08-19 23:12:20 -04:00
2 changed files with 36 additions and 35 deletions

View File

@@ -85,44 +85,46 @@ class QboController < ApplicationController
# proceed if the request is good # proceed if the request is good
if hash.eql? signature if hash.eql? signature
if request.headers['content-type'] == 'application/json' Thread.new do
data = JSON.parse(data) if request.headers['content-type'] == 'application/json'
else data = JSON.parse(data)
# application/x-www-form-urlencoded
data = params.as_json
end
# Process the information
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
entities.each do |entity|
id = entity['id'].to_i
name = entity['name']
logger.info "Casting #{name.constantize} to obj"
# Magicly initialize the correct class
obj = name.constantize
# for merge events
obj.destroy(entity['deletedId']) if entity['deletedId']
#Check to see if we are deleting a record
if entity['operation'].eql? "Delete"
obj.destroy(id)
#if not then update!
else else
begin # application/x-www-form-urlencoded
obj.sync_by_id(id) data = params.as_json
rescue => e end
logger.error "Failed to call sync_by_id on obj" # Process the information
logger.error e.message entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
logger.error e.backtrace.join("\n") entities.each do |entity|
id = entity['id'].to_i
name = entity['name']
logger.info "Casting #{name.constantize} to obj"
# Magicly initialize the correct class
obj = name.constantize
# for merge events
obj.destroy(entity['deletedId']) if entity['deletedId']
#Check to see if we are deleting a record
if entity['operation'].eql? "Delete"
obj.destroy(id)
#if not then update!
else
begin
obj.sync_by_id(id)
rescue => e
logger.error "Failed to call sync_by_id on obj"
logger.error e.message
logger.error e.backtrace.join("\n")
end
end end
end end
# Record that last time we updated
Qbo.update_time_stamp
ActiveRecord::Base.connection.close
end end
# Record that last time we updated
Qbo.update_time_stamp
# The webhook doesn't require a response but let's make sure we don't send anything # The webhook doesn't require a response but let's make sure we don't send anything
render :nothing => true, status: 200 render :nothing => true, status: 200
else else

View File

@@ -3,4 +3,3 @@
<%= submit_tag t(:label_search) %> <%= submit_tag t(:label_search) %>
<% end %> <% end %>
<%= button_to t(:label_new_customer), new_customer_path, method: :get%> <%= button_to t(:label_new_customer), new_customer_path, method: :get%>
<%= button_to(t(:label_sync), qbo_sync_path, method: :get) if User.current.admin?%>