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 +4 -4
- data/app/controllers/cats/core/routes_controller.rb +23 -0
- data/app/models/cats/core/beneficiary_plan_item.rb +2 -0
- data/app/models/cats/core/transport_requisition_item.rb +5 -0
- data/config/routes.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/routes.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9cb9c40a02753dac38f29bc222ca8f49af59d44f952126919be10544c4fe30
|
4
|
+
data.tar.gz: 6c96f5a25060732795cd874c04d8f41f711597015e0d49586bbbcf91b171a72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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
|
data/lib/cats/core/version.rb
CHANGED