fixed type and added sort param

This commit is contained in:
amartynov 2014-12-03 14:52:14 +03:00
parent 0887a8c8fc
commit 1addbe31b4
2 changed files with 13 additions and 1 deletions

View File

@ -389,6 +389,18 @@ class MongoConnector
options.delete("date_to")
options["created_at"] = date unless date.empty?
end
if options.has_key?("type")
begin
options["type"] = Integer(options["type"])
rescue ArgumentError
options.delete("type")
end
end
sort = -1
if options.has_key?("sort")
sort = 1 if options["sort"] == "asc"
options.delete("sort")
end
@reports.find(options).to_a.map{|e| Report.new(e)}
end

View File

@ -11,7 +11,7 @@ class ReportRoutes < Sinatra::Base
get "/all" do
options = {}
["project", "deploy_env", "type", "created_by", "date_from", "date_to"].each do |k|
["project", "deploy_env", "type", "created_by", "date_from", "date_to", "sort"].each do |k|
options[k] = params[k] unless params[k].nil?
end
json DevopsService.mongo.reports(options).map{|r| r.to_hash}