istox 0.1.96.pre.4 → 0.1.96.pre.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26643b17747b3d165425592f1b207d70a73adc00f61d1e7cf072894351a915d4
4
- data.tar.gz: 50fd97a587e3be01dfaaa3fe847e7b3b4eab718f34914c83717facf3a3f616a4
3
+ metadata.gz: b6415266fa69f54afa019c6977a40531f8b24ee2f9b56831982744149ecb57e6
4
+ data.tar.gz: b3d7e9486516751cf6a33a6e999a73c900172e1759e94310445a63ae0fecf6ce
5
5
  SHA512:
6
- metadata.gz: 3e7cb3f8fbf3f30250230a8388170ebd97619e2a12621192a65e7da2ad022b05dae88ee4dd579b039fa5f9333cfb1b0c67f8c3752d34e450360bb1e8868daf3b
7
- data.tar.gz: 8b57e73c6be0c69348fb4f35243995c85e1792cd436503c402a0733e6f9a8bec83159ff5f6f6056fa83d089e4b561e6e07d9b431b6138896008f54198812e663
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
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.96-4'.freeze
2
+ VERSION = '0.1.96-5'.freeze
3
3
  end
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
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