istox 0.1.96.pre.4 → 0.1.96.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/istox/helpers/filter.rb +34 -0
- data/lib/istox/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6415266fa69f54afa019c6977a40531f8b24ee2f9b56831982744149ecb57e6
|
4
|
+
data.tar.gz: b3d7e9486516751cf6a33a6e999a73c900172e1759e94310445a63ae0fecf6ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d2137ec153125cd0bca6f0287b351af6d24d65077eeae9a5fc0ddac0251a86498f9f3084e7a05462035e44d9d183803d4ced4f5d5ddd8fd9b1416f8957b582
|
7
|
+
data.tar.gz: 19b78ac868b7c66452c6770fc15c8d3bf3ad689c86931bac44969227b8785235cd9c11033adc1bf72cfb9dd7aa848f80432aa75e3780e203885f65fb84a828cc
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Istox
|
2
|
+
module Filter
|
3
|
+
def self.filter_query(query:, filters:)
|
4
|
+
current_page = filters.page
|
5
|
+
offset = (current_page - 1) * filters.limit
|
6
|
+
|
7
|
+
filters&.filter&.each do |x|
|
8
|
+
query = query.where("#{x.type.downcase} LIKE ?", "%#{x.value}%")
|
9
|
+
end
|
10
|
+
|
11
|
+
filters&.sort&.each do |x|
|
12
|
+
query = query.order("#{x.field.downcase} #{x.order.upcase}")
|
13
|
+
end
|
14
|
+
|
15
|
+
total = query.count
|
16
|
+
data = query.limit(filters.limit).offset(offset)
|
17
|
+
|
18
|
+
page_count = (total + filters.limit - 1) / filters.limit
|
19
|
+
|
20
|
+
{
|
21
|
+
data: data,
|
22
|
+
pagination: {
|
23
|
+
page: current_page,
|
24
|
+
limit: filters.limit,
|
25
|
+
previousPage: current_page - 1,
|
26
|
+
currentPage: current_page,
|
27
|
+
nextPage: current_page < page_count ? current_page + 1 : 0,
|
28
|
+
pageCount: page_count,
|
29
|
+
totalCount: total
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.96.pre.
|
4
|
+
version: 0.1.96.pre.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
@@ -294,6 +294,7 @@ files:
|
|
294
294
|
- lib/istox/helpers/bunny_boot.rb
|
295
295
|
- lib/istox/helpers/common_helper.rb
|
296
296
|
- lib/istox/helpers/f_math.rb
|
297
|
+
- lib/istox/helpers/filter.rb
|
297
298
|
- lib/istox/helpers/graphql_client.rb
|
298
299
|
- lib/istox/helpers/grpc_client.rb
|
299
300
|
- lib/istox/helpers/gruf_listener_hook.rb
|