Method: UdSync::OperationsController#index

Defined in:
app/controllers/ud_sync/operations_controller.rb

#indexObject



3
4
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
# File 'app/controllers/ud_sync/operations_controller.rb', line 3

def index
  render body: false, status: 401 and return if forbidden?

  operations = UdSync::Operation
  if current_user_present?
    operations = operations.where(owner_id: current_user.id)
  end

  if params[:since].present?
    since = DateTime.parse(params[:since])
    operations = operations.where('created_at >= ?', since)
  end

  operations = operations.all

  render json: {
    operations: operations.map do |operation|
      {
        id:        operation.id.to_s,
        name:      operation.name,
        record_id: operation.external_id,
        entity:    operation.entity_name,
        date:      operation.created_at.iso8601,
      }
    end
  }
end