reports filters
This commit is contained in:
		
							parent
							
								
									ad92c1fd67
								
							
						
					
					
						commit
						0887a8c8fc
					
				| @ -1,4 +1,5 @@ | |||||||
| require "mongo" | require "mongo" | ||||||
|  | require "date" | ||||||
| 
 | 
 | ||||||
| require "db/exceptions/record_not_found" | require "db/exceptions/record_not_found" | ||||||
| require "db/exceptions/invalid_record" | require "db/exceptions/invalid_record" | ||||||
| @ -367,8 +368,28 @@ class MongoConnector | |||||||
|     @reports.insert(r.to_mongo_hash) |     @reports.insert(r.to_mongo_hash) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def reports |   def reports options={} | ||||||
|     @reports.find().to_a.map{|e| Report.new(e)} |     date = {} | ||||||
|  |     if options.has_key?("date_from") or options.has_key?("date_to") | ||||||
|  |       if options.has_key?("date_from") | ||||||
|  |         begin | ||||||
|  |           d = Date.parse(options["date_from"]) | ||||||
|  |           date["$gte"] = d.to_time | ||||||
|  |         rescue ArgumentError | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  |       if options.has_key?("date_to") | ||||||
|  |         begin | ||||||
|  |           d = Date.parse(options["date_to"]) | ||||||
|  |           date["$lt"] = d.to_time | ||||||
|  |         rescue ArgumentError | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  |       options.delete("date_from") | ||||||
|  |       options.delete("date_to") | ||||||
|  |       options["created_at"] = date unless date.empty? | ||||||
|  |     end | ||||||
|  |     @reports.find(options).to_a.map{|e| Report.new(e)} | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def report id |   def report id | ||||||
|  | |||||||
| @ -10,7 +10,11 @@ class ReportRoutes < Sinatra::Base | |||||||
|   enable :inline_templates |   enable :inline_templates | ||||||
| 
 | 
 | ||||||
|   get "/all" do |   get "/all" do | ||||||
|     json DevopsService.mongo.reports.map{|r| r.to_hash} |     options = {} | ||||||
|  |     ["project", "deploy_env", "type", "created_by", "date_from", "date_to"].each do |k| | ||||||
|  |       options[k] = params[k] unless params[k].nil? | ||||||
|  |     end | ||||||
|  |     json DevopsService.mongo.reports(options).map{|r| r.to_hash} | ||||||
| =begin | =begin | ||||||
|     res = {} |     res = {} | ||||||
|     uri = URI.parse(request.url) |     uri = URI.parse(request.url) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 amartynov
						amartynov