Class: Api::V1::StatusApplicationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v1/status_applications_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/api/v1/status_applications_controller.rb', line 5

def index
  statuses = if params[:record_id].present? && params[:record_type].present?

               # if the record acts as BizTxnEvent we need to use BizTxnEvent
               record = params[:record_type].constantize.find(params[:record_id])
               if record.respond_to?(:root_txn)
                 record_type = 'BizTxnEvent'
                 record_id = record.root_txn.id
               else
                 record_type = params[:record_type]
                 record_id = params[:record_id]
               end

               StatusApplication.where('status_application_record_id = ? and status_application_record_type = ?',
                                       record_id,
                                       record_type)
                   .includes(:tracked_status_type).order('created_at desc').collect do |status|
                 status.to_data_hash
               end

             else
               StatusApplication.all.collect { |status| status.to_data_hash }
             end

  render :json => {:success => true, :status_applications => statuses}
end

#showObject



32
33
34
35
36
# File 'app/controllers/api/v1/status_applications_controller.rb', line 32

def show
  status_application = StatusApplication.find(params[:id])

  render :json => {:success => true, :status_application => status_application.to_data_hash}
end