Module: Queries::Concerns::Users
- Extended by:
- ActiveSupport::Concern
- Included in:
- DwcOccurrence::Filter, Query::Filter
- Defined in:
- lib/queries/concerns/users.rb
Overview
Helpers for queries that reference created/updated fields
!! You must have `#base_query` defined in the module to use this concern !! You must call set_user_dates in initialize()
-
TODO: Isolate code to a gem
-
TODO: validate User/Project relationships
Concern specs are in
spec/lib/queries/person/filter_spec.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.and_clauses ⇒ Object
74 75 76 |
# File 'lib/queries/concerns/users.rb', line 74 def self.and_clauses [ :updated_since_facet ] end |
.merge_clauses ⇒ Object
70 71 72 |
# File 'lib/queries/concerns/users.rb', line 70 def self.merge_clauses [ :created_updated_facet ] end |
.params ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/queries/concerns/users.rb', line 14 def self.params [ :user_id, :user_target, :user_date_start, :user_date_end, :updated_since ] end |
Instance Method Details
#created_updated_facet ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/queries/concerns/users.rb', line 83 def created_updated_facet return nil if user_id.empty? && user_target.nil? && user_date_start.nil? && user_date_end.nil? s, e = Utilities::Dates.normalize_and_order_dates( user_date_start, user_date_end) # TODO: this is ultimately going to require hourly scope s += ' 00:00:00' # adjust dates to beginning e += ' 23:59:59' # and end of date days q = nil # hand date range # What date? if !user_date_start.nil? || !user_date_end.nil? case user_target when 'updated' q = base_query.updated_in_date_range(s, e) when 'created' q = base_query.created_in_date_range(s, e) else q = base_query.updated_in_date_range(s, e).or(base_query.created_in_date_range(s,e)) end end q = base_query if q.nil? # handle user_id if !user_id.empty? case user_target when 'updated' q = q.where(updated_by_id: user_id) when 'created' q = q.where(created_by_id: user_id) else q = q.where(created_by_id: user_id).or(q.where(updated_by_id: user_id)) end end q end |
#set_user_dates(params) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/queries/concerns/users.rb', line 62 def set_user_dates(params) @user_id = params[:user_id] @user_target = params[:user_target] # Add validation ? @user_date_start = params[:user_date_start] @user_date_end = params[:user_date_end] @updated_since = params[:updated_since] end |
#updated_since_facet ⇒ Object
78 79 80 81 |
# File 'lib/queries/concerns/users.rb', line 78 def updated_since_facet return nil if updated_since.blank? table[:updated_at].gteq(updated_since) end |