cats_core 1.4.8 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/access_controller.rb +2 -2
- data/app/controllers/cats/core/application_controller.rb +2 -2
- data/app/controllers/cats/core/commodities_controller.rb +2 -15
- data/app/controllers/cats/core/commodity_categories_controller.rb +8 -39
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +4 -3
- data/app/controllers/cats/core/dispatch_plans_controller.rb +3 -3
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +3 -2
- data/app/controllers/cats/core/dispatches_controller.rb +16 -20
- data/app/controllers/cats/core/locations_controller.rb +5 -4
- data/app/controllers/cats/core/lost_commodities_controller.rb +3 -2
- data/app/controllers/cats/core/monthly_plans_controller.rb +5 -4
- data/app/controllers/cats/core/notifications_controller.rb +1 -0
- data/app/controllers/cats/core/receipt_transactions_controller.rb +16 -18
- data/app/controllers/cats/core/receipts_controller.rb +9 -13
- data/app/controllers/cats/core/roles_controller.rb +7 -7
- data/app/controllers/cats/core/routes_controller.rb +1 -1
- data/app/controllers/cats/core/stacks_controller.rb +3 -2
- data/app/controllers/cats/core/transporters_controller.rb +2 -2
- data/app/controllers/cats/core/unit_of_measures_controller.rb +1 -37
- data/app/controllers/cats/core/users_controller.rb +33 -44
- data/app/controllers/concerns/cats/core/common.rb +23 -6
- data/app/models/cats/core/commodity.rb +9 -0
- data/app/models/cats/core/transport_requisition.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1eacca23e0a10e3a707dcc45f51e2c44013fccb7a35182f3d7476c95d0bcad8
|
4
|
+
data.tar.gz: bcbcaf4bda959f028521528e8e7c979bca422037c9e4abb913449f831cadc73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b34d8901501515edaa28a7aea773ccea4156f079124be80200ab77673f22357e3f1e7891e667244ec8ffcc11a6310a5a575a36ab549468dc292fc7ad5bc868b5
|
7
|
+
data.tar.gz: bc9c7ea903b2cfaf05db1819391c0c5b2d2999498b3ee488263c240bc2971a67fe85b24911afd1432ef7aef81bc6b6f473cfc0ba34516839a93cc69b06571ad1
|
@@ -4,7 +4,7 @@ module Cats
|
|
4
4
|
skip_before_action :authenticate, only: [:login]
|
5
5
|
|
6
6
|
def login
|
7
|
-
user =
|
7
|
+
user = User.find_by(email: auth_params[:email])
|
8
8
|
if user
|
9
9
|
if user.authenticate(auth_params[:password])
|
10
10
|
roles = user.roles.map(&:name)
|
@@ -18,7 +18,7 @@ module Cats
|
|
18
18
|
id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles,
|
19
19
|
details: user.details
|
20
20
|
}
|
21
|
-
jwt =
|
21
|
+
jwt = TokenAuthService.issue(payload)
|
22
22
|
render json: { token: jwt, user: payload }
|
23
23
|
else
|
24
24
|
render json: { error: 'Invalid password.' }, status: 400
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
def current_user
|
7
7
|
return if token.nil?
|
8
8
|
|
9
|
-
user =
|
9
|
+
user = User.find(auth['id'])
|
10
10
|
@current_user ||= user
|
11
11
|
end
|
12
12
|
|
@@ -27,7 +27,7 @@ module Cats
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def auth
|
30
|
-
|
30
|
+
TokenAuthService.decode(token)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -4,28 +4,15 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def approve
|
7
|
-
commodity =
|
7
|
+
commodity = Commodity.find(params[:id])
|
8
8
|
result = commodity.approve
|
9
9
|
render json: { success: result, data: serialize(commodity) }
|
10
10
|
rescue StandardError => e
|
11
11
|
render json: { success: false, error: e.message }
|
12
12
|
end
|
13
13
|
|
14
|
-
def update
|
15
|
-
if @obj.status == Cats::Core::Commodity::APPROVED
|
16
|
-
render json: { success: false, error: 'An approved record cannot be edited.' }
|
17
|
-
return
|
18
|
-
end
|
19
|
-
|
20
|
-
if @obj.update(model_params)
|
21
|
-
render json: { success: true, data: serialize(@obj) }
|
22
|
-
else
|
23
|
-
render json: { success: false, error: @obj.errors.full_messages[0] }, status: :unprocessable_entity
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
14
|
def filter
|
28
|
-
query =
|
15
|
+
query = Commodity.ransack(params[:q])
|
29
16
|
render json: { success: true, data: serialize(query.result) }
|
30
17
|
end
|
31
18
|
|
@@ -1,62 +1,31 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class CommodityCategoriesController < ApplicationController
|
4
|
-
|
4
|
+
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
super do
|
8
|
+
CommodityCategory.all.reject(&:has_children?)
|
9
|
+
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def all
|
13
|
-
data =
|
13
|
+
data = CommodityCategory.all
|
14
14
|
render json: { success: true, data: data }
|
15
15
|
end
|
16
16
|
|
17
17
|
def root
|
18
|
-
data =
|
18
|
+
data = CommodityCategory.roots
|
19
19
|
render json: { success: true, data: serialize(data) }
|
20
20
|
end
|
21
21
|
|
22
|
-
def show
|
23
|
-
data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
|
24
|
-
render json: { success: true, data: data }
|
25
|
-
end
|
26
|
-
|
27
22
|
def children
|
28
|
-
parent =
|
29
|
-
data
|
30
|
-
render json: { success: true, data: data }
|
31
|
-
end
|
32
|
-
|
33
|
-
def create
|
34
|
-
obj = Cats::Core::CommodityCategory.new(model_params)
|
35
|
-
if obj.save
|
36
|
-
data = ActiveModelSerializers::SerializableResource.new(obj)
|
37
|
-
render json: { success: true, data: data }, status: :created
|
38
|
-
else
|
39
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def update
|
44
|
-
if @commodity_category.update(model_params)
|
45
|
-
data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
|
46
|
-
render json: { success: true, data: data }
|
47
|
-
else
|
48
|
-
render json: {
|
49
|
-
success: false, error: @commodity_category.errors.full_messages[0]
|
50
|
-
}, status: :unprocessable_entity
|
51
|
-
end
|
23
|
+
parent = CommodityCategory.find(params[:id])
|
24
|
+
render json: { success: true, data: serialize(parent.children) }
|
52
25
|
end
|
53
26
|
|
54
27
|
private
|
55
28
|
|
56
|
-
def set_commodity_category
|
57
|
-
@commodity_category = Cats::Core::CommodityCategory.find(params[:id])
|
58
|
-
end
|
59
|
-
|
60
29
|
def model_params
|
61
30
|
params.require('payload').permit(:code, :name, :description, :parent_id)
|
62
31
|
end
|
@@ -4,12 +4,13 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
DispatchPlanItem.where(dispatch_plan_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def filter
|
12
|
-
query =
|
13
|
+
query = DispatchPlanItem.ransack(params[:q])
|
13
14
|
render json: { success: true, data: serialize(query.result) }
|
14
15
|
end
|
15
16
|
|
@@ -4,12 +4,12 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def plans_for_user
|
7
|
-
plans =
|
7
|
+
plans = DispatchPlan.where(prepared_by: current_user)
|
8
8
|
render json: { success: true, data: serialize(plans) }
|
9
9
|
end
|
10
10
|
|
11
11
|
def filter
|
12
|
-
query =
|
12
|
+
query = DispatchPlan.ransack(params[:q])
|
13
13
|
render json: { success: true, data: serialize(query.result) }
|
14
14
|
end
|
15
15
|
|
@@ -23,7 +23,7 @@ module Cats
|
|
23
23
|
|
24
24
|
def approve
|
25
25
|
service = DispatchPlanService.new
|
26
|
-
plan =
|
26
|
+
plan = DispatchPlan.find(params[:id])
|
27
27
|
plan = service.approve(plan)
|
28
28
|
render json: { success: true, data: serialize(plan) }
|
29
29
|
rescue StandardError => e
|
@@ -4,8 +4,9 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
DispatchTransaction.where(dispatch_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
# This end-point is used to create upstream dispatch transactions.
|
@@ -4,41 +4,41 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
before_action :set_service, only: %i[create_receipt_authorization approve start search confirm]
|
7
|
-
before_action :set_dispatch, only: %i[approve start confirm commodity]
|
8
7
|
|
9
8
|
def index
|
10
|
-
|
11
|
-
|
9
|
+
super do
|
10
|
+
Dispatch.where(dispatch_plan_item_id: params[:id])
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def create
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
render json: { success: false, error: dispatch.errors.full_messages[0] }, status: :unprocessable_entity
|
15
|
+
super do
|
16
|
+
dispatch = Dispatch.new(model_params)
|
17
|
+
dispatch.dispatch_status = Dispatch::DRAFT
|
18
|
+
dispatch.prepared_by = current_user
|
19
|
+
dispatch
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
23
|
def approve
|
26
|
-
|
27
|
-
|
24
|
+
dispatch = set_object
|
25
|
+
dispatch.approve
|
26
|
+
render json: { success: true, data: serialize(dispatch) }
|
28
27
|
rescue StandardError => e
|
29
28
|
render json: { success: false, error: e.message }
|
30
29
|
end
|
31
30
|
|
32
31
|
def start
|
33
|
-
dispatch = @service.start(
|
32
|
+
dispatch = @service.start(set_object)
|
34
33
|
render json: { success: true, data: serialize(dispatch) }
|
35
34
|
rescue StandardError => e
|
36
35
|
render json: { success: false, error: e.message }
|
37
36
|
end
|
38
37
|
|
39
38
|
def confirm
|
40
|
-
|
41
|
-
|
39
|
+
dispatch = set_object
|
40
|
+
dispatch.confirm
|
41
|
+
render json: { success: true, data: serialize(dispatch) }
|
42
42
|
rescue StandardError => e
|
43
43
|
render json: { success: false, error: e.message }
|
44
44
|
end
|
@@ -49,7 +49,7 @@ module Cats
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def commodity
|
52
|
-
data =
|
52
|
+
data = set_object.dispatch_plan_item.commodity
|
53
53
|
render json: { success: true, data: serialize(data) }
|
54
54
|
end
|
55
55
|
|
@@ -59,10 +59,6 @@ module Cats
|
|
59
59
|
@service = DispatchService.new
|
60
60
|
end
|
61
61
|
|
62
|
-
def set_dispatch
|
63
|
-
@dispatch = Cats::Core::Dispatch.find(params[:id])
|
64
|
-
end
|
65
|
-
|
66
62
|
def model_params
|
67
63
|
params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no,
|
68
64
|
:driver_name, :driver_phone, :quantity, :remark)
|
@@ -4,17 +4,18 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
Location.where(location_type: params[:location_type])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def children
|
12
|
-
parent =
|
13
|
+
parent = Location.find(params[:id])
|
13
14
|
render json: { success: true, data: serialize(parent.children) }
|
14
15
|
end
|
15
16
|
|
16
17
|
def filter
|
17
|
-
query =
|
18
|
+
query = Location.ransack(params[:q])
|
18
19
|
render json: { success: true, data: serialize(query.result) }
|
19
20
|
end
|
20
21
|
|
@@ -6,17 +6,18 @@ module Cats
|
|
6
6
|
before_action :set_service, only: %i[generate remove_items generate_monthly_needs]
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
9
|
+
super do
|
10
|
+
MonthlyPlan.where(plan: params[:id])
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def filter
|
14
|
-
query =
|
15
|
+
query = MonthlyPlan.ransack(params[:q])
|
15
16
|
render json: { success: true, data: serialize(query.result) }
|
16
17
|
end
|
17
18
|
|
18
19
|
def approve
|
19
|
-
plan =
|
20
|
+
plan = MonthlyPlan.find(params[:id])
|
20
21
|
plan.approve
|
21
22
|
render json: { success: true, data: serialize(plan) }
|
22
23
|
rescue StandardError => e
|
@@ -2,6 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class NotificationsController < ApplicationController
|
4
4
|
before_action :set_notification, only: %i[mark_as_read mark_as_unread]
|
5
|
+
|
5
6
|
def index
|
6
7
|
data = Notification.messages(current_user.notifications.newest_first)
|
7
8
|
render json: { success: true, data: data }
|
@@ -4,28 +4,26 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
ReceiptTransaction.where(receipt_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def create
|
12
|
-
|
13
|
-
|
14
|
-
# Look for a transaction with the same destination as incoming
|
15
|
-
transaction = Cats::Core::ReceiptTransaction.find_by(
|
16
|
-
receipt_id: p[:receipt_id],
|
17
|
-
destination_id: p[:destination_id]
|
18
|
-
)
|
19
|
-
if transaction
|
20
|
-
transaction.quantity += p[:quantity]
|
21
|
-
else
|
22
|
-
transaction = Cats::Core::ReceiptTransaction.new(p)
|
23
|
-
end
|
13
|
+
super do
|
14
|
+
p = model_params
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
# Look for a transaction with the same destination as incoming
|
17
|
+
transaction = ReceiptTransaction.find_by(
|
18
|
+
receipt_id: p[:receipt_id],
|
19
|
+
destination_id: p[:destination_id]
|
20
|
+
)
|
21
|
+
if transaction
|
22
|
+
transaction.quantity += p[:quantity]
|
23
|
+
else
|
24
|
+
transaction = ReceiptTransaction.new(p)
|
25
|
+
end
|
26
|
+
transaction
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -4,25 +4,21 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
Receipt.where(dispatch_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def create
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
render json: { success: true, data: serialize(receipt) }
|
17
|
-
else
|
18
|
-
render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
|
13
|
+
super do
|
14
|
+
service = ReceiptService.new
|
15
|
+
receipt = service.init(model_params)
|
16
|
+
receipt
|
19
17
|
end
|
20
|
-
rescue StandardError => e
|
21
|
-
render json: { success: false, error: e.message }
|
22
18
|
end
|
23
19
|
|
24
20
|
def start_stacking
|
25
|
-
receipt =
|
21
|
+
receipt = Receipt.find(params[:id])
|
26
22
|
service = ReceiptService.new
|
27
23
|
result = service.start_stacking(receipt)
|
28
24
|
render json: { success: true, data: serialize(result) }
|
@@ -31,7 +27,7 @@ module Cats
|
|
31
27
|
end
|
32
28
|
|
33
29
|
def finish_stacking
|
34
|
-
receipt =
|
30
|
+
receipt = Receipt.find(params[:id])
|
35
31
|
service = ReceiptService.new
|
36
32
|
result = service.finish_stacking(receipt)
|
37
33
|
render json: { success: true, data: serialize(result) }
|
@@ -6,21 +6,21 @@ module Cats
|
|
6
6
|
before_action :set_role, only: [:users]
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
super do
|
10
|
+
Role.joins(:application_module)
|
11
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def unassigned_roles
|
15
|
-
user =
|
16
|
-
roles =
|
16
|
+
user = User.find(params[:id])
|
17
|
+
roles = Role.where(application_module_id: user.application_module_id)
|
17
18
|
unassigned = roles - user.roles
|
18
19
|
render json: { success: true, data: serialize(unassigned) }
|
19
20
|
end
|
20
21
|
|
21
22
|
def users
|
22
|
-
data
|
23
|
-
render json: { success: true, data: data }
|
23
|
+
render json: { success: true, data: serialize(@role.users) }
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TransportersController < ApplicationController
|
4
|
-
include
|
4
|
+
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
query =
|
7
|
+
query = Transporter.ransack(params[:q])
|
8
8
|
render json: { success: true, data: serialize(query.result) }
|
9
9
|
end
|
10
10
|
|
@@ -1,46 +1,10 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class UnitOfMeasuresController < ApplicationController
|
4
|
-
|
5
|
-
|
6
|
-
def index
|
7
|
-
data = ActiveModelSerializers::SerializableResource.new(Cats::Core::UnitOfMeasure.all)
|
8
|
-
render json: { success: true, data: data }
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
12
|
-
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
13
|
-
render json: { success: true, data: data }
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
obj = Cats::Core::UnitOfMeasure.new(model_params)
|
18
|
-
if obj.save
|
19
|
-
data = ActiveModelSerializers::SerializableResource.new(obj)
|
20
|
-
render json: { success: true, data: data }, status: :created
|
21
|
-
else
|
22
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def update
|
27
|
-
if @unit_of_measure.update(model_params)
|
28
|
-
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
29
|
-
render json: { success: true, data: data }
|
30
|
-
else
|
31
|
-
render json: {
|
32
|
-
success: false,
|
33
|
-
error: @unit_of_measure.errors.full_messages[0]
|
34
|
-
}, status: :unprocessable_entity
|
35
|
-
end
|
36
|
-
end
|
4
|
+
include Common
|
37
5
|
|
38
6
|
private
|
39
7
|
|
40
|
-
def set_unit_of_measure
|
41
|
-
@unit_of_measure = Cats::Core::UnitOfMeasure.find(params[:id])
|
42
|
-
end
|
43
|
-
|
44
8
|
def model_params
|
45
9
|
params.require(:payload).permit(:abbreviation, :name, :unit_type)
|
46
10
|
end
|
@@ -3,95 +3,84 @@ module Cats
|
|
3
3
|
class UsersController < ApplicationController
|
4
4
|
include Common
|
5
5
|
|
6
|
-
before_action :set_user, only: %i[update roles assign_role revoke_role stores warehouse hub]
|
7
|
-
|
8
6
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
super do
|
8
|
+
User.joins(:application_module).where(cats_core_application_modules: { prefix: params[:prefix] })
|
9
|
+
end
|
12
10
|
end
|
13
11
|
|
14
12
|
def create
|
15
|
-
|
16
|
-
|
13
|
+
super do
|
14
|
+
prefix = model_params[:application_prefix]
|
15
|
+
application_module = ApplicationModule.find_by(prefix: prefix)
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
render json: { success: true, data: serialize(obj) }, status: :created
|
22
|
-
else
|
23
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
17
|
+
obj = User.new(model_params.except(:application_prefix))
|
18
|
+
obj.application_module = application_module
|
19
|
+
obj
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
23
|
def update
|
24
|
+
user = set_object
|
28
25
|
if model_params[:application_prefix]
|
29
26
|
prefix = model_params[:application_prefix]
|
30
|
-
application_module =
|
31
|
-
|
32
|
-
|
27
|
+
application_module = ApplicationModule.find_by(prefix: prefix)
|
28
|
+
user.assign_attributes(model_params.except(:application_prefix))
|
29
|
+
user.application_module = application_module
|
33
30
|
else
|
34
|
-
|
31
|
+
user.assign_attributes(model_params)
|
35
32
|
end
|
36
33
|
|
37
|
-
if
|
38
|
-
render json: { success: true, data: serialize(
|
34
|
+
if user.save
|
35
|
+
render json: { success: true, data: serialize(user) }
|
39
36
|
else
|
40
|
-
render json: { success: false, error:
|
37
|
+
render json: { success: false, error: user.errors.full_messages[0] }, status: :unprocessable_entity
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
41
|
def roles
|
45
|
-
data
|
46
|
-
render json: { success: true, data: data }
|
42
|
+
render json: { success: true, data: serialize(set_object.roles) }
|
47
43
|
end
|
48
44
|
|
49
45
|
def assign_role
|
50
|
-
role =
|
51
|
-
|
46
|
+
role = Role.find(params[:role_id])
|
47
|
+
user = set_object
|
48
|
+
user.roles << role
|
52
49
|
|
53
50
|
case role.name
|
54
51
|
when 'warehouse_manager'
|
55
|
-
|
52
|
+
user.add_detail(:warehouse, params[:warehouse_id])
|
56
53
|
when 'hub_manager'
|
57
|
-
|
54
|
+
user.add_detail(:hub, params[:hub_id])
|
58
55
|
when 'regional_manager'
|
59
|
-
|
56
|
+
user.add_detail(:region, params[:region_id])
|
60
57
|
end
|
61
58
|
|
62
|
-
data
|
63
|
-
render json: { success: true, data: data }
|
59
|
+
render json: { success: true, data: serialize(role) }
|
64
60
|
end
|
65
61
|
|
66
62
|
def revoke_role
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
render json: { success: true, data:
|
63
|
+
user = set_object
|
64
|
+
role = Role.find(params[:role_id])
|
65
|
+
user.roles.delete(role)
|
66
|
+
user.remove_detail(role.name) if %w[warehouse_manager hub_manager regional_manager].include?(role.name)
|
67
|
+
render json: { success: true, data: serialize(role) }
|
72
68
|
end
|
73
69
|
|
74
70
|
def stores
|
75
|
-
data
|
76
|
-
render json: { success: true, data: data }
|
71
|
+
render json: { success: true, data: serialize(set_object.stores) }
|
77
72
|
end
|
78
73
|
|
79
74
|
def warehouse
|
80
|
-
data
|
81
|
-
render json: { success: true, data: data }
|
75
|
+
render json: { success: true, data: serialize(set_object.warehouse) }
|
82
76
|
end
|
83
77
|
|
84
78
|
def hub
|
85
|
-
data
|
86
|
-
render json: { success: true, data: data }
|
79
|
+
render json: { success: true, data: serialize(set_object.hub) }
|
87
80
|
end
|
88
81
|
|
89
82
|
private
|
90
83
|
|
91
|
-
def set_user
|
92
|
-
@user = Cats::Core::User.find(params[:id])
|
93
|
-
end
|
94
|
-
|
95
84
|
def model_params
|
96
85
|
params.require(:payload).permit(
|
97
86
|
:first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
|
@@ -9,8 +9,12 @@ module Cats
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def index
|
12
|
-
data =
|
13
|
-
|
12
|
+
data = if block_given?
|
13
|
+
yield
|
14
|
+
else
|
15
|
+
@clazz.all
|
16
|
+
end
|
17
|
+
render json: { success: true, data: serialize(data) }
|
14
18
|
end
|
15
19
|
|
16
20
|
def show
|
@@ -18,20 +22,33 @@ module Cats
|
|
18
22
|
end
|
19
23
|
|
20
24
|
def create
|
21
|
-
obj =
|
25
|
+
obj = if block_given?
|
26
|
+
yield
|
27
|
+
else
|
28
|
+
@clazz.new(model_params)
|
29
|
+
end
|
22
30
|
if obj.save
|
23
31
|
render json: { success: true, data: serialize(obj) }, status: :created
|
24
32
|
else
|
25
33
|
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
26
34
|
end
|
35
|
+
rescue StandardError => e
|
36
|
+
render json: { success: false, error: e.message }
|
27
37
|
end
|
28
38
|
|
29
39
|
def update
|
30
|
-
if
|
31
|
-
|
40
|
+
obj = if block_given?
|
41
|
+
yield
|
42
|
+
else
|
43
|
+
obj = @obj
|
44
|
+
end
|
45
|
+
if obj.update(model_params)
|
46
|
+
render json: { success: true, data: serialize(obj) }
|
32
47
|
else
|
33
|
-
render json: { success: false, error:
|
48
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
34
49
|
end
|
50
|
+
rescue StandardError => e
|
51
|
+
render json: { success: false, error: e.message }
|
35
52
|
end
|
36
53
|
|
37
54
|
private
|
@@ -37,6 +37,7 @@ module Cats
|
|
37
37
|
validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
|
38
38
|
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
39
39
|
validates :status, presence: true, inclusion: { in: STATUSES }
|
40
|
+
validate :validate_updateability, on: :update
|
40
41
|
|
41
42
|
delegate(:abbreviation, to: :unit_of_measure, prefix: 'unit')
|
42
43
|
delegate(:reference_no, to: :source, prefix: true)
|
@@ -45,6 +46,14 @@ module Cats
|
|
45
46
|
source.commodity_category.name
|
46
47
|
end
|
47
48
|
|
49
|
+
def validate_updateability
|
50
|
+
return unless status
|
51
|
+
|
52
|
+
return if status_changed?
|
53
|
+
|
54
|
+
errors.add(:base, 'Commodity cannot be updated because it is in approved state.') if status == APPROVED
|
55
|
+
end
|
56
|
+
|
48
57
|
def approve
|
49
58
|
raise(StandardError, 'Commodity already approved.') if status == APPROVED
|
50
59
|
|
@@ -29,7 +29,7 @@ module Cats
|
|
29
29
|
raise(StandardError, 'Transport requisition is already approved.') if status == APPROVED
|
30
30
|
|
31
31
|
if transport_requisition_items.count.zero?
|
32
|
-
raise(StandardError, 'Transport requisition has no requisition items.')
|
32
|
+
raise(StandardError, 'Transport requisition has no requisition items.')
|
33
33
|
end
|
34
34
|
|
35
35
|
self.status = APPROVED
|
data/lib/cats/core/version.rb
CHANGED
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.4.
|
4
|
+
version: 1.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|