cats_core 1.0.49 → 1.0.50

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: 88f88c106a10c160703ee6898947a371aef510da88eea9aa514ff93e20c4e806
4
- data.tar.gz: 2baa107b490e7372ed823c6d8fec83e91a19de41f77a48cd187e99eb2dc934bf
3
+ metadata.gz: b13a3549ac212c8e869ce5aff6b3508787e75af7afaeadba4b0e99f5476b101e
4
+ data.tar.gz: d4993f0e36936fc4ed18ae9accca173189056c3cddae7fc2f16704f6509bac80
5
5
  SHA512:
6
- metadata.gz: f12a36ca3a10c537f09e6fd12b07e66d70b0bc69692badb2f9a0de6642d1b91f308ba53754456ecf35da935c7a380af3e7237bdda35690177ae0823acab8ef60
7
- data.tar.gz: fdb2ed8c53e2d0c2e554017dce091be7056004b28a9dc3b0cbc6c4e343855957afcb64de644ccefc7649372c5c29584f98f9fc78ba9f0b0e6bb24bb96c434458
6
+ metadata.gz: 91d4ba5e59ef7da90cf36d6073d20819496bae612eff73cdeccada481293a956311732201b049da61e84ba1c12b1a7464d636202b101f66a49bcf22146211440
7
+ data.tar.gz: afdceef95b3321eaea7ebad43bd622b814ef268f97b20c5815af07376fc710b338b74a25bc3e81d6c4b366f00e30e6553c2f2dcc38e84685bc670201ce4e4e13
@@ -8,7 +8,9 @@ module Cats
8
8
  def available_space(id, level)
9
9
  case level
10
10
  when HUB
11
- warehouse_ids = Cats::Core::Location.find(id).children.map(&:id)
11
+ hub = Cats::Core::Location.find(id)
12
+ warehouses = hub.children
13
+ warehouse_ids = warehouses.map(&:id)
12
14
  stores = Cats::Core::Store.joins(:warehouse)
13
15
  .where(
14
16
  cats_core_locations: {
@@ -19,19 +21,48 @@ module Cats
19
21
  wh_details = []
20
22
  stores.each do |key, value|
21
23
  total_space = value.inject(0) { |sum, val| sum + val.available_space }
22
- details = value.map { |val| { store_id: val.id, total_space: val.available_space } }
23
- wh_details << { warehouse_id: key, total_space: total_space, details: details }
24
+ details = value.map do |val|
25
+ { store_id: val.id, code: val.code, name: val.name, total_space: val.available_space }
26
+ end
27
+ warehouse = warehouses.find(key)
28
+ wh_details << {
29
+ warehouse_id: key,
30
+ code: warehouse.code,
31
+ name: warehouse.name,
32
+ total_space: total_space,
33
+ details: details
34
+ }
24
35
  end
25
36
  hub_space = wh_details.inject(0) { |sum, val| sum + val[:total_space] }
26
- space = { hub_id: id, total_space: hub_space, details: wh_details }
37
+ space = {
38
+ hub_id: id,
39
+ code: hub.code,
40
+ name: hub.name,
41
+ total_space: hub_space,
42
+ details: wh_details
43
+ }
27
44
  when WAREHOUSE
45
+ warehouse = Cats::Core::Location.find(id)
28
46
  stores = Cats::Core::Store.where(warehouse_id: id)
29
- details = stores.map { |store| { store_id: store.id, total_space: store.available_space } }
47
+ details = stores.map do |store|
48
+ { store_id: store.id, code: store.code, name: store.name, total_space: store.available_space }
49
+ end
30
50
  total_space = stores.inject(0) { |sum, val| sum + val.available_space }
31
- space = { warehouse_id: id, total_space: total_space, details: details }
51
+ space = {
52
+ warehouse_id: id,
53
+ code: warehouse.code,
54
+ name: warehouse.name,
55
+ total_space: total_space,
56
+ details: details
57
+ }
32
58
  when STORE
33
59
  store = Cats::Core::Store.find(id)
34
- space = { store_id: store.id, total_space: store.available_space }
60
+ space = {
61
+ store_id: store.id,
62
+ code: store.code,
63
+ name: store.name,
64
+ total_space: store.available_space
65
+ }
35
66
  end
36
67
  space
37
68
  end
data/config/routes.rb CHANGED
@@ -33,11 +33,11 @@ Cats::Core::Engine.routes.draw do
33
33
  to: 'spaces#available_space',
34
34
  as: :hub_space,
35
35
  defaults: { level: Cats::Core::SpaceService::HUB }
36
- get '/warehousess/:id/space',
36
+ get '/warehouses/:id/space',
37
37
  to: 'spaces#available_space',
38
38
  as: :warehouse_space,
39
39
  defaults: { level: Cats::Core::SpaceService::WAREHOUSE }
40
- get '/store/:id/space',
40
+ get '/stores/:id/space',
41
41
  to: 'spaces#available_space',
42
42
  as: :store_space,
43
43
  defaults: { level: Cats::Core::SpaceService::STORE }
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.49'.freeze
3
+ VERSION = '1.0.50'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.49
4
+ version: 1.0.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers