5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/api/v1/file_assets_controller.rb', line 5
def index
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
sort = sort_hash[:property] || 'description'
dir = sort_hash[:direction] || 'ASC'
limit = params[:limit] || 25
start = params[:start] || 0
query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
file_assets = FileAsset.apply_filters(query_filter)
if !query_filter[:file_asset_holder_type].present? && !query_filter[:file_asset_holder_id].present?
file_assets = file_assets.scope_by_dba_org(current_user.party.dba_organization)
end
total_count = file_assets.count
file_assets = file_assets.limit(limit).offset(start)
file_assets.order("#{sort} #{dir}")
render json: {success: true,
total_count: total_count,
file_assets: file_assets.collect { |file| file.to_data_hash }}
end
|