cats_core 1.4.17 → 1.4.18

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: 41699f66a4650b220cf3d02f028da8baade6d675d25f06823342d8fb11287309
4
- data.tar.gz: a1e7903ad574573c09a87df11fc67ca133546abee2a44efd3e2d12cd0d44982f
3
+ metadata.gz: 3e9cb9c40a02753dac38f29bc222ca8f49af59d44f952126919be10544c4fe30
4
+ data.tar.gz: 6c96f5a25060732795cd874c04d8f41f711597015e0d49586bbbcf91b171a72f
5
5
  SHA512:
6
- metadata.gz: a32b2685361ee616976123043970cf782d6180ac5b5d1d885ed3bf78dc4a36774ae004fc5640dd0fa50223f522c5c009a7be3ffb988c3edd05f7e454119e950b
7
- data.tar.gz: 4cf9dcd0928eeaec7bceb628cb21486263b07f426cb9846ae587c8112eec488e938a1735ebac5d7338a5a65cea507d15223a9a7eb2499575348106b893dc3acc
6
+ metadata.gz: 28a2461af42fd0325081029bd524488716f838e4574ae2bec6589f328b2731189b0b108d9909e426734b502608c7a02de1cc3c1ab7514c12dd97c1a9b2a08a25
7
+ data.tar.gz: 7a9f3d7e2f05170d74387a034e2ef0c9205c9e1f1bc0d95dcb470fb29099e64a002d250d126f5cd098b1d01af8d7f5cd41d38f239e62bb66c1156107e6b1a2b0
@@ -8,11 +8,34 @@ module Cats
8
8
  render json: { success: true, data: serialize(query.result) }
9
9
  end
10
10
 
11
+ def bulk_create
12
+ p = bulk_create_params
13
+ source = Location.find(p[:source_id])
14
+ destinations = Location.where(id: p[:destination_ids]).pluck(:id, :name)
15
+ data = p[:destination_ids].each_with_object([]) do |id, res|
16
+ destination_name = destinations.find { |d| d[0] == id }[1]
17
+ res << {
18
+ region_id: p[:region_id],
19
+ source_id: p[:source_id],
20
+ destination_id: id,
21
+ name: "#{source.name} - #{destination_name}"
22
+ }
23
+ end
24
+
25
+ result = Route.insert_all!(data, record_timestamps: true)
26
+ routes = Route.where(id: result.rows.flatten)
27
+ render json: { success: true, data: serialize(routes) }
28
+ end
29
+
11
30
  private
12
31
 
13
32
  def model_params
14
33
  params.require(:payload).permit(:region_id, :source_id, :destination_id)
15
34
  end
35
+
36
+ def bulk_create_params
37
+ params.require(:payload).permit(:region_id, :source_id, destination_ids: [])
38
+ end
16
39
  end
17
40
  end
18
41
  end
@@ -7,6 +7,8 @@ module Cats
7
7
 
8
8
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
9
9
  validates :plan_item_id, uniqueness: { scope: :beneficiary_category_id }
10
+
11
+ delegate(:name, to: :beneficiary_category, prefix: true)
10
12
  end
11
13
  end
12
14
  end
@@ -9,6 +9,7 @@ module Cats
9
9
 
10
10
  delegate(:reference_no, to: :transport_requisition, prefix: 'requisition')
11
11
  delegate(:abbreviation, to: :unit, prefix: true)
12
+ delegate(:source_name, to: :dispatch_plan_item, prefix: false)
12
13
 
13
14
  def commodity_name
14
15
  dispatch_plan_item.commodity.source.commodity_category.name
@@ -17,6 +18,10 @@ module Cats
17
18
  def woreda
18
19
  dispatch_plan_item.destination.name
19
20
  end
21
+
22
+ def region
23
+ dispatch_plan_item.destination.root.name
24
+ end
20
25
  end
21
26
  end
22
27
  end
data/config/routes.rb CHANGED
@@ -80,6 +80,7 @@ Cats::Core::Engine.routes.draw do
80
80
  resources :transporters, except: %i[destroy]
81
81
 
82
82
  post '/routes/filter', controller: :routes, action: :filter
83
+ post '/routes/bulk_create', controller: :routes, action: :bulk_create
83
84
  resources :routes, except: %i[destroy]
84
85
 
85
86
  post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.17'.freeze
3
+ VERSION = '1.4.18'.freeze
4
4
  end
5
5
  end
@@ -3,5 +3,6 @@ FactoryBot.define do
3
3
  region factory: :location
4
4
  source factory: :woreda
5
5
  destination factory: :woreda
6
+ name { "#{source.name} - #{destination.name}"}
6
7
  end
7
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.17
4
+ version: 1.4.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.