cats_core 1.1.15 → 1.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c73eb407823b6e404e576cd94dd8ac14228db71edce2fab923be1fc4a76752a
4
- data.tar.gz: 43743939e2a9b6f3aaa3f27c5898e52619d7c00ec36896cd2d4c587a90ead623
3
+ metadata.gz: 4ac17edba232672ae0f11dc2042dbb8c58f7a3bbe6f5f032e3407a23292b1db8
4
+ data.tar.gz: d35a4ea6ab6e34d1a3ea13b784056916a22dc60d9da2ab9e015d34863dd7173d
5
5
  SHA512:
6
- metadata.gz: 224e70bc25588e883cdc642db7e85dfb18c2389a9f147ada262a3891feedaf595f827fe28fb8c092449ef2ec7f3c70c8dff4a7f20891fb4d5756ec61e363a2f8
7
- data.tar.gz: 9eaf7c258dcf29107a7ec15c6db97c088dfa5569a3ceabcccd4c179f82c6edecc7e231139c403abe52577cea6153795ea0723eaab91d821c9b4726ccfe1c3399
6
+ metadata.gz: c46e405c2735c8a73c814c71429c2bfeebf2a39f8130aa574e750f996006722fed3bc7a90508fab437359c9530f50578060b3c619b5cc2a029f617515df92529
7
+ data.tar.gz: c53c84bc2f39768f72eaeab44bcee50e70d621028a72bace55aa263a618b4eaf69249ca5969defad1060bbe5428bb1d60ae15926de4028eabed76a4b7a7d8ad8
@@ -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,26 @@
1
1
  module Cats
2
2
  module Core
3
3
  class UsersController < ApplicationController
4
- before_action :set_user, only: %i[stores warehouse hub]
4
+ include Common
5
+
6
+ before_action :set_user, only: %i[roles assign_role stores warehouse hub]
7
+
8
+ def index
9
+ users = Cats::Core::User.where(application_module_id: params[:id])
10
+ render json: { success: true, data: serialize(users) }
11
+ end
12
+
13
+ def roles
14
+ data = ActiveModelSerializers::SerializableResource.new(@user.roles)
15
+ render json: { success: true, data: data }
16
+ end
17
+
18
+ def assign_role
19
+ role = Cats::Core::Role.find(params[:role_id])
20
+ @user.roles << role
21
+ data = ActiveModelSerializers::SerializableResource.new(@user)
22
+ render json: { success: true, data: data }
23
+ end
5
24
 
6
25
  def stores
7
26
  data = ActiveModelSerializers::SerializableResource.new(@user.stores)
@@ -21,7 +40,14 @@ module Cats
21
40
  private
22
41
 
23
42
  def set_user
24
- @user = User.find(params[:id])
43
+ @user = Cats::Core::User.find(params[:id])
44
+ end
45
+
46
+ def model_params
47
+ params.require(:payload).permit(
48
+ :first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
49
+ :application_module_id
50
+ )
25
51
  end
26
52
  end
27
53
  end
@@ -9,7 +9,10 @@ module Cats
9
9
  validates :gift_date, :quantity, presence: true
10
10
  validates :quantity, numericality: { greater_than: 0 }
11
11
 
12
- before_save :set_commodity_category
12
+ delegate(:name, to: :commodity_category, prefix: true)
13
+ delegate(:abbreviation, to: :unit_of_measure, prefix: true)
14
+
15
+ before_validation :set_commodity_category
13
16
  after_create :update_donation
14
17
 
15
18
  def update_donation
@@ -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
@@ -0,0 +1,3 @@
1
+ class RoleSerializer < ActiveModel::Serializer
2
+ attributes :id, :name, :application_module_id
3
+ end
@@ -0,0 +1,3 @@
1
+ class UserSerializer < ActiveModel::Serializer
2
+ attributes :id, :first_name, :last_name, :email, :phone_number, :active, :details, :application_module_id
3
+ 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,8 @@ 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
+ get '/application_modules/:id/users', controller: :users, action: :index, as: :application_users
9
+
8
10
  resources :menus, only: [:index]
9
11
  resources :notifications, only: [:index] do
10
12
  member do
@@ -12,6 +14,8 @@ Cats::Core::Engine.routes.draw do
12
14
  post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
13
15
  end
14
16
  end
17
+
18
+ get '/roles/:id/', controller: :roles, action: :show
15
19
  resources :roles, param: :name do
16
20
  member do
17
21
  get 'users', controller: :roles, action: :users
@@ -19,9 +23,11 @@ Cats::Core::Engine.routes.draw do
19
23
  end
20
24
  resources :users do
21
25
  member do
26
+ get 'roles'
22
27
  get 'stores', controller: :users, action: :stores
23
28
  get 'warehouse', controller: :users, action: :warehouse
24
29
  get 'hub', controller: :users, action: :hub
30
+ post 'assign_role'
25
31
  end
26
32
  end
27
33
 
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.15'.freeze
3
+ VERSION = '1.1.19'.freeze
4
4
  end
5
5
  end
@@ -20,4 +20,9 @@ FactoryBot.define do
20
20
  location_type { Cats::Core::Location::WOREDA }
21
21
  parent
22
22
  end
23
+
24
+ factory :zone, parent: :location, class: 'Cats::Core::Location' do
25
+ location_type { Cats::Core::Location::ZONE }
26
+ parent
27
+ end
23
28
  end
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.15
4
+ version: 1.1.19
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-02 00:00:00.000000000 Z
11
+ date: 2021-10-04 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