finapps 5.0.23 → 5.0.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a680cc81ef178bcca5fa52772b2c0630802442a0e320c3557e3153f3643d18b
4
- data.tar.gz: a8f4a002fb6368f40c71afc3e6d7a677bdbf17f3eee1dc5422767b16baff3aee
3
+ metadata.gz: f21200338d07c1ab7882266ee53bb695bcd2214fd54c3dd8bd1e4f54f07003fd
4
+ data.tar.gz: 95168dfe1ade82536cd5ccb0a967a451cfabc6c3323796955e97f821c81c03ac
5
5
  SHA512:
6
- metadata.gz: 8438628a45e0b2c399754888eee305bb1e5d5757f43d0ca57f9d095558a178d7c24b455ea4e1f6f2b746d6f69bcc29eebf9deac8c68f3dc63c6520781013280c
7
- data.tar.gz: 2b462e0519e8f2eef0826d4af2898b58da073f7b9212be0393a5676f2c20e5e67f5ce595be15d5c3234611534c546d454cf42ab7eb3fe054ee59534522590378
6
+ metadata.gz: bd3183fe7bad50f52717109c80b14766a642d895d8d3fc30bce7171428324cb372258b31d5d70f14fe0f492875109b6b415dbf2008d6fe3c05e59e93e98ee2b3
7
+ data.tar.gz: c3a257358611b37562c7d34559bd69b574fdd590a7576c82cb8fa569b298bc2b907bee86a447c052f15c59480c74df81663e033c9833601be018f196fac387c2
@@ -56,48 +56,71 @@ module FinApps
56
56
  private
57
57
 
58
58
  def build_filter(params)
59
- filter = {}
60
- filter.merge!(search_query(params[:searchTerm])) if params[:searchTerm]
61
- filter.merge!(status_query(params[:status])) if params[:status]
62
- filter.merge!(assignment_query(params[:assignment])) if params[:assignment] # assignment can be ""
63
- filter.merge!(relation_query(params[:relation])) if !params[:searchTerm] && !nil_or_empty?(params[:relation])
64
- filter
59
+ search_query(params[:searchTerm]).merge(status_query(params[:status]))
60
+ .merge(assignment_query(params[:assignment]))
61
+ .merge(consumer_query(params[:consumer]))
62
+ .merge(relation_query(params[:relation], params[:searchTerm]))
65
63
  end
66
64
 
67
65
  def search_query(term)
68
- {
69
- "$or": [
70
- { "public_id": { "$regex": "^#{term}", "$options": 'i' } },
71
- { "applicant.last_name": term },
72
- { "assignment.last_name": term },
73
- {
74
- "requestor.reference_no": {
75
- "$regex": "^#{term}", "$options": 'i'
66
+ if term
67
+ {
68
+ "$or": [
69
+ { "public_id": { "$regex": "^#{term}", "$options": 'i' } },
70
+ { "applicant.last_name": term },
71
+ { "assignment.last_name": term },
72
+ {
73
+ "requestor.reference_no": {
74
+ "$regex": "^#{term}", "$options": 'i'
75
+ }
76
76
  }
77
- }
78
- ]
79
- }
77
+ ]
78
+ }
79
+ else
80
+ {}
81
+ end
80
82
  end
81
83
 
82
84
  def status_query(status)
83
- if status.is_a?(Array)
84
- { "status": { "$in": status.map(&:to_i) } }
85
+ if status
86
+ if status.is_a?(Array)
87
+ { "status": { "$in": status.map(&:to_i) } }
88
+ else
89
+ { "status": status.to_i }
90
+ end
85
91
  else
86
- { "status": status.to_i }
92
+ {}
87
93
  end
88
94
  end
89
95
 
90
96
  def assignment_query(assignment)
91
- { "assignment.operator_id": assignment.empty? ? nil : assignment } # translate "" to null assignment
97
+ # translate "" to null assignment
98
+ if assignment
99
+ { "assignment.operator_id": assignment.empty? ? nil : assignment }
100
+ else
101
+ {}
102
+ end
103
+ end
104
+
105
+ def consumer_query(consumer)
106
+ if consumer
107
+ { "consumer_id": consumer.empty? ? nil : consumer }
108
+ else
109
+ {}
110
+ end
92
111
  end
93
112
 
94
- def relation_query(relation)
95
- {
96
- "$or": [
97
- { "public_id": { "$in": relation } },
98
- { "original_order_id": { "$in": relation } }
99
- ]
100
- }
113
+ def relation_query(relation, search_term)
114
+ if !search_term && !nil_or_empty?(relation)
115
+ {
116
+ "$or": [
117
+ { "public_id": { "$in": relation } },
118
+ { "original_order_id": { "$in": relation } }
119
+ ]
120
+ }
121
+ else
122
+ {}
123
+ end
101
124
  end
102
125
  end
103
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FinApps
4
- VERSION = '5.0.23'
4
+ VERSION = '5.0.24'
5
5
  end
@@ -102,6 +102,7 @@ RSpec.describe FinApps::REST::Orders do
102
102
  searchTerm: 'term',
103
103
  status: %w[1 7],
104
104
  assignment: 'valid_operator',
105
+ consumer: 'valid_consumer_id',
105
106
  relation: %w[valid_order_id]
106
107
  }
107
108
  end
@@ -121,20 +122,21 @@ RSpec.describe FinApps::REST::Orders do
121
122
  subject
122
123
  url =
123
124
  "#{versioned_api_path}/orders?filter=%7B%22$or%22:%5B%7B%22public_id%22:" \
124
- '%7B%22$regex%22:%22%5Eterm%22,%22$options%22:%22i%22%7D%7D,%7B%22applicant.last_name%22:%22term%22%7D' \
125
- ',%7B%22assignment.last_name%22:%22term%22%7D,%7B%22requestor.reference_no%22:%7B%22$regex%22:%22%5E' \
126
- 'term%22,%22$options%22:%22i%22%7D%7D%5D,%22status%22:%7B%22$in%22:%5B1,7%5D%7D,%22assignment.' \
127
- 'operator_id%22:%22valid_operator%22%7D&page=2&requested=25&sort=status'
125
+ '%7B%22$regex%22:%22%5Eterm%22,%22$options%22:%22i%22%7D%7D,%7B%22applicant.last_name%22:%22' \
126
+ 'term%22%7D,%7B%22assignment.last_name%22:%22term%22%7D,%7B%22requestor.reference_no%22:%7B%22' \
127
+ '$regex%22:%22%5Eterm%22,%22$options%22:%22i%22%7D%7D%5D,%22status%22:%7B%22$in%22:%5B1,7%5D%7D,' \
128
+ '%22assignment.operator_id%22:%22valid_operator%22,%22consumer_id%22:%22valid_consumer_id%22%7D' \
129
+ '&page=2&requested=25&sort=status'
128
130
  expect(WebMock).to have_requested(:get, url)
129
131
  end
130
132
  it 'builds query and sends proper request with searchTerm/relation exclusivity' do
131
133
  params[:searchTerm] = nil
132
134
  subject
133
135
  url =
134
- "#{versioned_api_path}/orders?filter=%7B%22status%22:%7B%22$in%22:%5B1," \
135
- '7%5D%7D,%22assignment.operator_id%22:%22valid_operator%22,%22$or%22:%5B%7B%22public_id%22:%7B%22$in' \
136
- '%22:%5B%22valid_order_id%22%5D%7D%7D,%7B%22original_order_id%22:%7B%22$in%22:%5B%22valid_order_id%22' \
137
- '%5D%7D%7D%5D%7D&page=2&requested=25&sort=status'
136
+ "#{versioned_api_path}/orders?filter=%7B%22status%22:%7B%22$in%22:%5B1,7%5D%7D," \
137
+ '%22assignment.operator_id%22:%22valid_operator%22,%22consumer_id%22:%22valid_consumer_id%22,' \
138
+ '%22$or%22:%5B%7B%22public_id%22:%7B%22$in%22:%5B%22valid_order_id%22%5D%7D%7D,%7B%22original_order_id%22:' \
139
+ '%7B%22$in%22:%5B%22valid_order_id%22%5D%7D%7D%5D%7D&page=2&requested=25&sort=status'
138
140
  expect(WebMock).to have_requested(:get, url)
139
141
  end
140
142
  it 'builds null assignment query properly when supplied w/ empty string' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.23
4
+ version: 5.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finapps_core