82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/controllers/kaui/audit_logs_controller.rb', line 82
def history
json_response do
account_id = params.require(:account_id)
object_id = params.require(:object_id)
object_type = params.require(:object_type)
cached_options_for_klient = options_for_klient
audit_logs_with_history = []
error = nil
begin
case object_type
when 'ACCOUNT'
account = Kaui::Account.find_by_id_or_key(object_id, false, false, cached_options_for_klient)
audit_logs_with_history = account.audit_logs_with_history(cached_options_for_klient)
when 'ACCOUNT_EMAIL'
account = Kaui::Account.find_by_id_or_key(account_id, false, false, cached_options_for_klient)
audit_logs_with_history = account.email_audit_logs_with_history(object_id, cached_options_for_klient)
when 'BLOCKING_STATES'
audit_logs_with_history = Kaui::Account.blocking_state_audit_logs_with_history(object_id, cached_options_for_klient)
when 'BUNDLE'
bundle = Kaui::Bundle.find_by_id(object_id, cached_options_for_klient)
audit_logs_with_history = bundle.audit_logs_with_history(cached_options_for_klient)
when 'CUSTOM_FIELD'
audit_logs_with_history = Kaui::CustomField.new({ custom_field_id: object_id }).audit_logs_with_history(cached_options_for_klient)
when 'INVOICE'
invoice = Kaui::Invoice.find_by_id(object_id, false, 'NONE', cached_options_for_klient)
audit_logs_with_history = invoice.audit_logs_with_history(cached_options_for_klient)
when 'INVOICE_ITEM'
invoice_item = Kaui::InvoiceItem.new
invoice_item.invoice_item_id = object_id
audit_logs_with_history = invoice_item.audit_logs_with_history(cached_options_for_klient)
when 'PAYMENT_ATTEMPT'
audit_logs_with_history = Kaui::Payment.attempt_audit_logs_with_history(object_id, cached_options_for_klient)
when 'PAYMENT'
payment = Kaui::Payment.find_by_id(object_id, false, false, cached_options_for_klient)
audit_logs_with_history = payment.audit_logs_with_history(cached_options_for_klient)
when 'PAYMENT_METHOD'
payment_method = Kaui::PaymentMethod.find_by_id(object_id, false, false, [], 'NONE', cached_options_for_klient)
audit_logs_with_history = payment_method.audit_logs_with_history(cached_options_for_klient)
when 'SUBSCRIPTION'
subscription = Kaui::Subscription.find_by_id(object_id, 'NONE', cached_options_for_klient)
audit_logs_with_history = subscription.audit_logs_with_history(cached_options_for_klient)
when 'SUBSCRIPTION_EVENT'
audit_logs_with_history = Kaui::Subscription.event_audit_logs_with_history(object_id, cached_options_for_klient)
when 'TRANSACTION'
audit_logs_with_history = Kaui::Transaction.new({ transaction_id: object_id }).audit_logs_with_history(cached_options_for_klient)
when 'TAG'
audit_logs_with_history = Kaui::Tag.new({ tag_id: object_id }).audit_logs_with_history(cached_options_for_klient)
when 'TAG_DEFINITION'
audit_logs_with_history = Kaui::TagDefinition.new({ id: object_id }).audit_logs_with_history(cached_options_for_klient)
else
error = "Object [#{object_type}] history is not supported."
end
rescue StandardError => e
error = e.message
end
{ audits: audit_logs_with_history, error: }
end
end
|