cats_core 1.1.21 → 1.1.25
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/receipt_transactions_controller.rb +21 -0
- data/app/controllers/cats/core/roles_controller.rb +13 -0
- data/app/controllers/cats/core/users_controller.rb +18 -2
- data/app/models/cats/core/transaction.rb +3 -0
- data/app/models/cats/core/user.rb +10 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20210715120018_create_cats_core_roles.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: 3babdd4703726f7863d05d4b939af06ede31f1b6a0a5a715ad0f13286ea8343a
|
4
|
+
data.tar.gz: 44ed3f59a6099ba17094b8d81232c9e8cf72c6ac95118da99e1e8a23286bebf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82195965fd9917d53ff286e1d2822302f87c9ecf836b292dc8d647eef5f307a9f84d692b4dd5ff4d6a16dc1c21e9c52109966c39d459052f918cd9ad73c6914b
|
7
|
+
data.tar.gz: f7c58b63d4e6f66b9ba3011a7066175052b5e6aa92c13339d5d975cf3567108c405e5bfb571bd527c8d12f3b24b6d8ba8924f67134c2f28d5941958a9ba2fb89
|
@@ -8,6 +8,27 @@ module Cats
|
|
8
8
|
render json: { success: true, data: serialize(transactions) }
|
9
9
|
end
|
10
10
|
|
11
|
+
def create
|
12
|
+
p = model_params
|
13
|
+
|
14
|
+
# Look for a transaction with the same destination as incoming
|
15
|
+
transaction = Cats::Core::ReceiptTransaction.find_by(
|
16
|
+
source_id: p[:source_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
|
24
|
+
|
25
|
+
if transaction.save
|
26
|
+
render json: { success: true, data: serialize(transaction) }, status: :created
|
27
|
+
else
|
28
|
+
render json: { success: false, error: transaction.errors.full_messages[0] }, status: :unprocessable_entity
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
11
32
|
private
|
12
33
|
|
13
34
|
def model_params
|
@@ -5,6 +5,19 @@ module Cats
|
|
5
5
|
|
6
6
|
before_action :set_role, only: [:users]
|
7
7
|
|
8
|
+
def index
|
9
|
+
roles = Cats::Core::Role.joins(:application_module)
|
10
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
11
|
+
render json: { success: true, data: serialize(roles) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def unassigned_roles
|
15
|
+
user = Cats::Core::User.find(params[:id])
|
16
|
+
roles = Cats::Core::Role.where(application_module_id: user.application_module_id)
|
17
|
+
unassigned = roles - user.roles
|
18
|
+
render json: { success: true, data: serialize(unassigned) }
|
19
|
+
end
|
20
|
+
|
8
21
|
def users
|
9
22
|
data = ActiveModelSerializers::SerializableResource.new(@role.users)
|
10
23
|
render json: { success: true, data: data }
|
@@ -3,7 +3,7 @@ module Cats
|
|
3
3
|
class UsersController < ApplicationController
|
4
4
|
include Common
|
5
5
|
|
6
|
-
before_action :set_user, only: %i[update roles assign_role stores warehouse hub]
|
6
|
+
before_action :set_user, only: %i[update roles assign_role revoke_role stores warehouse hub]
|
7
7
|
|
8
8
|
def index
|
9
9
|
users = Cats::Core::User.joins(:application_module)
|
@@ -49,7 +49,23 @@ module Cats
|
|
49
49
|
def assign_role
|
50
50
|
role = Cats::Core::Role.find(params[:role_id])
|
51
51
|
@user.roles << role
|
52
|
-
|
52
|
+
|
53
|
+
case role.name
|
54
|
+
when 'warehouse_manager'
|
55
|
+
@user.add_detail(:warehouse, params[:warehouse_id])
|
56
|
+
when 'hub_manager'
|
57
|
+
@user.add_detail(:hub, params[:hub_id])
|
58
|
+
end
|
59
|
+
|
60
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
61
|
+
render json: { success: true, data: data }
|
62
|
+
end
|
63
|
+
|
64
|
+
def revoke_role
|
65
|
+
role = Cats::Core::Role.find(params[:role_id])
|
66
|
+
@user.roles.delete(role)
|
67
|
+
@user.remove_detail(role.name) if %w[warehouse_manager hub_manager].include?(role.name)
|
68
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
53
69
|
render json: { success: true, data: data }
|
54
70
|
end
|
55
71
|
|
@@ -18,6 +18,9 @@ module Cats
|
|
18
18
|
return unless quantity.present? && source.present?
|
19
19
|
|
20
20
|
total = self.class.where(source: source).sum(:quantity)
|
21
|
+
|
22
|
+
total -= quantity_was if id
|
23
|
+
|
21
24
|
diff = source.quantity - total
|
22
25
|
errors.add(:quantity, "total is higher than source quantity (Max = #{diff}).") if quantity > diff
|
23
26
|
end
|
@@ -31,6 +31,16 @@ module Cats
|
|
31
31
|
Cats::Core::Location.find_by(id: details['hub'], location_type: Cats::Core::Location::HUB)
|
32
32
|
end
|
33
33
|
|
34
|
+
def add_detail(key, value)
|
35
|
+
details[key] = value
|
36
|
+
save!
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_detail(key)
|
40
|
+
details.delete(key)
|
41
|
+
save!
|
42
|
+
end
|
43
|
+
|
34
44
|
def validate_phone_number
|
35
45
|
return unless phone_number.present?
|
36
46
|
|
data/config/routes.rb
CHANGED
@@ -7,6 +7,7 @@ Cats::Core::Engine.routes.draw do
|
|
7
7
|
|
8
8
|
resources :application_modules, param: :prefix do
|
9
9
|
member do
|
10
|
+
get 'roles', controller: :roles, action: :index
|
10
11
|
get 'users', controller: :users, action: :index
|
11
12
|
end
|
12
13
|
end
|
@@ -28,10 +29,12 @@ Cats::Core::Engine.routes.draw do
|
|
28
29
|
resources :users do
|
29
30
|
member do
|
30
31
|
get 'roles'
|
32
|
+
get 'unassigned_roles', controller: :roles, action: :unassigned_roles
|
31
33
|
get 'stores', controller: :users, action: :stores
|
32
34
|
get 'warehouse', controller: :users, action: :warehouse
|
33
35
|
get 'hub', controller: :users, action: :hub
|
34
36
|
post 'assign_role'
|
37
|
+
post 'revoke_role'
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
@@ -23,6 +23,6 @@ class CreateCatsCoreRoles < ActiveRecord::Migration[6.1]
|
|
23
23
|
end
|
24
24
|
|
25
25
|
add_index(:cats_core_roles, [ :name, :resource_type, :resource_id ])
|
26
|
-
add_index(:cats_core_users_cats_core_roles, [ :user_id, :role_id ])
|
26
|
+
add_index(:cats_core_users_cats_core_roles, [ :user_id, :role_id ], unique: true)
|
27
27
|
end
|
28
28
|
end
|
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.25
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|