cats_core 1.1.17 → 1.1.21
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/receipts_controller.rb +23 -0
- data/app/controllers/cats/core/roles_controller.rb +6 -0
- data/app/controllers/cats/core/users_controller.rb +59 -2
- data/app/notifications/cats/core/dispatch_notification.rb +27 -0
- data/app/serializers/cats/core/role_serializer.rb +3 -0
- data/app/serializers/cats/core/user_serializer.rb +3 -0
- data/app/services/cats/core/dispatch_service.rb +20 -0
- data/config/routes.rb +10 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/locations.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106712bfb38bd512ae9d06d20301aa81a5a199bb6522728cddcf6c1d688fe444
|
4
|
+
data.tar.gz: 80cf7130c7cbbb47bcf4120c021e54aa2e9eb7bf5578260664339a6cbca18e78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1741bedb659f842852f836dd020c79f45d4ec901f8e076be97007c06fec9a69cb5793ac7612a46b08e9fd06b92b6892bebb2baa39cb0d49b1a48bffba9c93f48
|
7
|
+
data.tar.gz: 7fb859382f5faf676437e39cdb7f64c0201a47bb7b9409dd4d41a8ec5e30d13713415f21a04a2b8e2c7fd40c0315c800d1dd64d5277ea846ff279357486a9a4f
|
@@ -8,6 +8,29 @@ module Cats
|
|
8
8
|
render json: { success: true, data: serialize(receipts) }
|
9
9
|
end
|
10
10
|
|
11
|
+
def create
|
12
|
+
p = model_params
|
13
|
+
receipt = Cats::Core::Receipt.find_by(
|
14
|
+
dispatch_id: p[:dispatch_id],
|
15
|
+
commodity_status: p[:commodity_status]
|
16
|
+
)
|
17
|
+
if receipt
|
18
|
+
receipt.quantity += p[:quantity]
|
19
|
+
if receipt.save
|
20
|
+
render json: { success: true, data: serialize(receipt) }
|
21
|
+
else
|
22
|
+
render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
|
23
|
+
end
|
24
|
+
else
|
25
|
+
obj = Cats::Core::Receipt.new(model_params)
|
26
|
+
if obj.save
|
27
|
+
render json: { success: true, data: serialize(obj) }, status: :created
|
28
|
+
else
|
29
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
11
34
|
def start_stacking
|
12
35
|
receipt = Cats::Core::Receipt.find(params[:id])
|
13
36
|
service = ReceiptService.new
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class RolesController < ApplicationController
|
4
|
+
include Common
|
5
|
+
|
4
6
|
before_action :set_role, only: [:users]
|
5
7
|
|
6
8
|
def users
|
@@ -13,6 +15,10 @@ module Cats
|
|
13
15
|
def set_role
|
14
16
|
@role = Role.find_by(name: params[:name])
|
15
17
|
end
|
18
|
+
|
19
|
+
def model_params
|
20
|
+
params.require(:payload).permit(:name, :application_module_id)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -1,7 +1,57 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class UsersController < ApplicationController
|
4
|
-
|
4
|
+
include Common
|
5
|
+
|
6
|
+
before_action :set_user, only: %i[update roles assign_role stores warehouse hub]
|
7
|
+
|
8
|
+
def index
|
9
|
+
users = Cats::Core::User.joins(:application_module)
|
10
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
11
|
+
render json: { success: true, data: serialize(users) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
prefix = model_params[:application_prefix]
|
16
|
+
application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
|
17
|
+
|
18
|
+
obj = Cats::Core::User.new(model_params.except(:application_prefix))
|
19
|
+
obj.application_module = application_module
|
20
|
+
if obj.save
|
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
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
if model_params[:application_prefix]
|
29
|
+
prefix = model_params[:application_prefix]
|
30
|
+
application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
|
31
|
+
@user.assign_attributes(model_params.except(:application_prefix))
|
32
|
+
@user.application_module = application_module
|
33
|
+
else
|
34
|
+
@user.assign_attributes(model_params)
|
35
|
+
end
|
36
|
+
|
37
|
+
if @user.save
|
38
|
+
render json: { success: true, data: serialize(@user) }
|
39
|
+
else
|
40
|
+
render json: { success: false, error: @user.errors.full_messages[0] }, status: :unprocessable_entity
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def roles
|
45
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.roles)
|
46
|
+
render json: { success: true, data: data }
|
47
|
+
end
|
48
|
+
|
49
|
+
def assign_role
|
50
|
+
role = Cats::Core::Role.find(params[:role_id])
|
51
|
+
@user.roles << role
|
52
|
+
data = ActiveModelSerializers::SerializableResource.new(@user)
|
53
|
+
render json: { success: true, data: data }
|
54
|
+
end
|
5
55
|
|
6
56
|
def stores
|
7
57
|
data = ActiveModelSerializers::SerializableResource.new(@user.stores)
|
@@ -21,7 +71,14 @@ module Cats
|
|
21
71
|
private
|
22
72
|
|
23
73
|
def set_user
|
24
|
-
@user = User.find(params[:id])
|
74
|
+
@user = Cats::Core::User.find(params[:id])
|
75
|
+
end
|
76
|
+
|
77
|
+
def model_params
|
78
|
+
params.require(:payload).permit(
|
79
|
+
:first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
|
80
|
+
:application_prefix
|
81
|
+
)
|
25
82
|
end
|
26
83
|
end
|
27
84
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchNotification < Noticed::Base
|
4
|
+
deliver_by :database
|
5
|
+
|
6
|
+
param :dispatch
|
7
|
+
|
8
|
+
def message
|
9
|
+
dispatch = params[:dispatch]
|
10
|
+
title = 'Dispatch Notification'
|
11
|
+
date = Date.today
|
12
|
+
body = <<~BODY
|
13
|
+
Commodity with the following details has been dispatched to you:
|
14
|
+
Dispatch Ref. = #{dispatch.reference_no}
|
15
|
+
Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
|
16
|
+
Commodity = #{dispatch.allocation_item.allocation.commodity.name}
|
17
|
+
Allocated Quantity = #{dispatch.allocation_item.quantity}
|
18
|
+
Quantity = #{dispatch.quantity}
|
19
|
+
Truck Plate No. = #{dispatch.plate_no}
|
20
|
+
Driver Name = #{dispatch.driver_name}
|
21
|
+
Driver Phone = #{dispatch.driver_phone}
|
22
|
+
BODY
|
23
|
+
{ title: title, date: date, body: body }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -109,6 +109,7 @@ module Cats
|
|
109
109
|
dispatch.save
|
110
110
|
transactions = Cats::Core::DispatchTransaction.where(destination: dispatch)
|
111
111
|
transactions.each(&:commit)
|
112
|
+
send_notification(dispatch)
|
112
113
|
dispatch
|
113
114
|
end
|
114
115
|
|
@@ -131,6 +132,25 @@ module Cats
|
|
131
132
|
|
132
133
|
dispatch
|
133
134
|
end
|
135
|
+
|
136
|
+
def send_notification(dispatch)
|
137
|
+
notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
|
138
|
+
raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
|
139
|
+
|
140
|
+
users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
|
141
|
+
location_id = dispatch.allocation_item.destination_id
|
142
|
+
recipients = users.map do |user|
|
143
|
+
details = user.details
|
144
|
+
if (details.key?('warehouse') && details['warehouse'] == location_id) ||
|
145
|
+
(details.key?('hub') && details['hub'] == location_id)
|
146
|
+
user
|
147
|
+
end
|
148
|
+
end.compact
|
149
|
+
return if recipients.empty?
|
150
|
+
|
151
|
+
notification = DispatchNotification.with(dispatch: dispatch)
|
152
|
+
notification.deliver(recipients)
|
153
|
+
end
|
134
154
|
end
|
135
155
|
end
|
136
156
|
end
|
data/config/routes.rb
CHANGED
@@ -5,6 +5,12 @@ Cats::Core::Engine.routes.draw do
|
|
5
5
|
get '/notifications/unread', controller: :notifications, action: :unread
|
6
6
|
get '/notifications/read', controller: :notifications, action: :read
|
7
7
|
|
8
|
+
resources :application_modules, param: :prefix do
|
9
|
+
member do
|
10
|
+
get 'users', controller: :users, action: :index
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
resources :menus, only: [:index]
|
9
15
|
resources :notifications, only: [:index] do
|
10
16
|
member do
|
@@ -12,6 +18,8 @@ Cats::Core::Engine.routes.draw do
|
|
12
18
|
post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
|
13
19
|
end
|
14
20
|
end
|
21
|
+
|
22
|
+
get '/roles/:id/', controller: :roles, action: :show
|
15
23
|
resources :roles, param: :name do
|
16
24
|
member do
|
17
25
|
get 'users', controller: :roles, action: :users
|
@@ -19,9 +27,11 @@ Cats::Core::Engine.routes.draw do
|
|
19
27
|
end
|
20
28
|
resources :users do
|
21
29
|
member do
|
30
|
+
get 'roles'
|
22
31
|
get 'stores', controller: :users, action: :stores
|
23
32
|
get 'warehouse', controller: :users, action: :warehouse
|
24
33
|
get 'hub', controller: :users, action: :hub
|
34
|
+
post 'assign_role'
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
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.1.
|
4
|
+
version: 1.1.21
|
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-10-
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- app/models/cats/core/transporter.rb
|
287
287
|
- app/models/cats/core/unit_of_measure.rb
|
288
288
|
- app/models/cats/core/user.rb
|
289
|
+
- app/notifications/cats/core/dispatch_notification.rb
|
289
290
|
- app/notifications/cats/core/simple_notification.rb
|
290
291
|
- app/serializers/cats/core/commodity_category_serializer.rb
|
291
292
|
- app/serializers/cats/core/commodity_serializer.rb
|
@@ -296,7 +297,9 @@ files:
|
|
296
297
|
- app/serializers/cats/core/receipt_serializer.rb
|
297
298
|
- app/serializers/cats/core/receipt_transaction_serializer.rb
|
298
299
|
- app/serializers/cats/core/role_menu_serializer.rb
|
300
|
+
- app/serializers/cats/core/role_serializer.rb
|
299
301
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
302
|
+
- app/serializers/cats/core/user_serializer.rb
|
300
303
|
- app/services/cats/core/dispatch_service.rb
|
301
304
|
- app/services/cats/core/menu_service.rb
|
302
305
|
- app/services/cats/core/notification_service.rb
|