cats_core 1.0.9 → 1.0.13

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: 90bb7ac6c5367ab8fd22ede292563557c104607222408c8ed5ed94a32b8a82e2
4
- data.tar.gz: b4fb9a29a7a65ce4036b361102bde71f756247b0ff37762543fe94e8fc94a06c
3
+ metadata.gz: c166b58630fc770c2447694d5d57f59edd26ab7bee0caf07f762fc16d21f4069
4
+ data.tar.gz: 7cc6aead85c41426225eb4d306e92cf85ac7024b4690324a62985b7c6b163756
5
5
  SHA512:
6
- metadata.gz: c8c6c949827ee51f1465507caa6301a49af21d47ed2acbf478cb20902733079d1fb630438a9dad3b04df4a1002d1bb9b1e07c5af6c299d250e7d4b11775e045e
7
- data.tar.gz: abdb8edd5e5bc49d7b954bd37ad23c22081b8d68d4d71fb9def9af20e45bff3ee094e355bc95a17f6ce91676c6fa0832f3d2a9a8767d17e1fdd04f5e5c942a34
6
+ metadata.gz: 8a6c48372747e4c159c7fae9d51af746740fe7d556fc9b0cee36d9ba814ccd33aa25be298681729ad474b63c7c30881b79dcdb5da2a2da47d9962f6b3df325a2
7
+ data.tar.gz: 30805a86c89f24e1472a177c7cedf1c18a5ccbc18756bf316eca62138d63247a05ee42c18004b06a1ce898ac4343341045eff7f59921d16ea70a22ac2c33d4d9
@@ -1,6 +1,6 @@
1
1
  module Cats
2
2
  module Core
3
- class ApplicationController < ActionController::Base
3
+ class ApplicationController < ActionController::API
4
4
  before_action :authenticate
5
5
 
6
6
  def current_user
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class MenusController < ApplicationController
4
+ before_action :set_service
5
+
6
+ def index
7
+ menu = @service.fetch_menu(current_user)
8
+ data = ActiveModelSerializers::SerializableResource.new(menu, each_serializer: RoleMenuSerializer)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ private
13
+
14
+ def set_service
15
+ @service = MenuService.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,7 @@ module Cats
11
11
  private
12
12
 
13
13
  def set_role
14
- @role = Role.find(params[:id])
14
+ @role = Role.find_by(name: params[:name])
15
15
  end
16
16
  end
17
17
  end
@@ -6,7 +6,7 @@ module Cats
6
6
  belongs_to :recipient, polymorphic: true
7
7
 
8
8
  def message
9
- { id: id, read: !read_at.nil? }.merge(to_notification.message)
9
+ { id: id, read: !read_at.nil?, created_at: created_at }.merge(to_notification.message)
10
10
  end
11
11
 
12
12
  def self.messages(notifications)
@@ -14,6 +14,9 @@ module Cats
14
14
 
15
15
  errors.add(:base, 'Application module does not match for role and menu')
16
16
  end
17
+
18
+ delegate(:label, to: :menu, prefix: false)
19
+ delegate(:icon, to: :menu, prefix: false)
17
20
  end
18
21
  end
19
22
  end
@@ -2,10 +2,10 @@ module Cats
2
2
  module Core
3
3
  class Store < ApplicationRecord
4
4
  belongs_to :warehouse, class_name: 'Cats::Core::Location'
5
+ belongs_to :store_keeper, class_name: 'Cats::Core::User'
5
6
  has_many :stacks
6
- has_many :receipt_plans, as: :receivable
7
7
 
8
- validates :name, :store_keeper_name, :length, :width, :height, presence: true
8
+ validates :name, :length, :width, :height, presence: true
9
9
  validates :length, :width, :height, numericality: { greater_than: 0 }
10
10
  validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
11
11
  validates :gangway_length,
@@ -20,6 +20,12 @@ module Cats
20
20
 
21
21
  errors.add(:warehouse, 'must be a valid warehouse') unless warehouse.location_type == Location::WAREHOUSE
22
22
  end
23
+
24
+ def store_keeper_name
25
+ "#{store_keeper.first_name} #{store_keeper.last_name}"
26
+ end
27
+
28
+ delegate(:phone_number, to: :store_keeper, prefix: true)
23
29
  end
24
30
  end
25
31
  end
@@ -8,9 +8,11 @@ module Cats
8
8
  has_and_belongs_to_many :roles, join_table: :cats_core_users_cats_core_roles
9
9
  has_many :notifications, as: :recipient
10
10
 
11
+ validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
11
12
  validates :first_name, :last_name, :email, presence: true
12
- validates :password, length: { minimum: 6 }
13
+ validates :password, presence: true, length: { minimum: 6 }, on: :create
13
14
  validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
15
+ validate :validate_phone_number
14
16
 
15
17
  def warehouses
16
18
  return unless details.key?('warehouses')
@@ -23,6 +25,16 @@ module Cats
23
25
 
24
26
  Cats::Core::Store.where(id: details['stores'])
25
27
  end
28
+
29
+ def validate_phone_number
30
+ return unless phone_number.present?
31
+
32
+ return if phone_number.length == 10 && /0\d{9}/.match(phone_number)
33
+
34
+ return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
35
+
36
+ errors.add(:phone_number, 'must be 10 or 12 digits and should match with local phone pattern')
37
+ end
26
38
  end
27
39
  end
28
40
  end
@@ -1,9 +1,20 @@
1
1
  # This is a simple notification class which delivers a
2
2
  # message via database delivery method. It requires a
3
- # +msg+ parameter to instantiate, which represents the
3
+ # +body+ and +title+ parameter to instantiate, which represents the
4
4
  # text message to deliver.
5
- class SimpleNotification < Noticed::Base
6
- deliver_by :database
5
+ module Cats
6
+ module Core
7
+ class SimpleNotification < Noticed::Base
8
+ deliver_by :database
7
9
 
8
- param :msg
10
+ param :body
11
+ param :title
12
+
13
+ def message
14
+ title = params[:title]
15
+ body = params[:body]
16
+ { title: title, body: body }
17
+ end
18
+ end
19
+ end
9
20
  end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class RoleMenuSerializer < ActiveModel::Serializer
4
+ attributes :id, :label, :icon, :description, :menu_items
5
+
6
+ def menu_items
7
+ object.menu.menu_items
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Cats
2
+ module Core
3
+ class MenuService
4
+ def fetch_menu(user)
5
+ user.roles.map(&:role_menus).flatten
6
+ end
7
+ end
8
+ end
9
+ end
@@ -16,22 +16,19 @@ module Cats
16
16
  }
17
17
  }.freeze
18
18
 
19
- def initialize(code, params)
19
+ def initialize(rules, code, params)
20
+ @rules = rules
20
21
  @code = code
21
22
  @params = params
22
23
  end
23
24
 
24
- def notification_rules
25
- NOTIFICATION_RULES
26
- end
27
-
28
25
  def create_notifier(rule)
29
26
  clazz = rule[:notification].constantize
30
27
  clazz.with(**@params)
31
28
  end
32
29
 
33
30
  def notify
34
- rule = notification_rules[@code]
31
+ rule = @rules[@code]
35
32
  notifier = create_notifier(rule)
36
33
  app_code = rule[:application]
37
34
  roles = rule[:recipients]
data/config/routes.rb CHANGED
@@ -2,14 +2,15 @@ Cats::Core::Engine.routes.draw do
2
2
  post '/login', controller: :access, action: :login
3
3
  get '/notifications/unread', controller: :notifications, action: :unread
4
4
  get '/notifications/read', controller: :notifications, action: :read
5
-
5
+
6
+ resources :menus, only: [:index]
6
7
  resources :notifications, only: [:index] do
7
8
  member do
8
9
  post 'mark_as_read', controller: :notifications, action: :mark_as_read
9
10
  post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
10
11
  end
11
12
  end
12
- resources :roles do
13
+ resources :roles, param: :name do
13
14
  member do
14
15
  get 'users', controller: :roles, action: :users
15
16
  end
@@ -7,6 +7,7 @@ class CreateCatsCoreUsers < ActiveRecord::Migration[6.1]
7
7
  t.boolean :active, null: false, default: true
8
8
  t.string :password_digest
9
9
  t.jsonb :details
10
+ t.string :phone_number
10
11
  t.references :application_module,
11
12
  null: false,
12
13
  index: { name: 'am_on_users_indx' },
@@ -2,8 +2,6 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_stores do |t|
4
4
  t.string :name, null: false
5
- t.string :store_keeper_name, null: false
6
- t.string :store_keeper_phone
7
5
  t.float :length, null: false
8
6
  t.float :width, null: false
9
7
  t.float :height, null: false
@@ -16,7 +14,10 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
16
14
  null: false,
17
15
  index: { name: 'warehouse_on_stores_indx' },
18
16
  foreign_key: { to_table: :cats_core_locations }
19
-
17
+ t.references :store_keeper,
18
+ null: false,
19
+ index: { name: 'store_keeper_on_store_indx' },
20
+ foreign_key: { to_table: :cats_core_users }
20
21
  t.timestamps
21
22
  end
22
23
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.9'.freeze
3
+ VERSION = '1.0.13'.freeze
4
4
  end
5
5
  end
@@ -1,8 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :store, class: 'Cats::Core::Store' do
3
3
  name { FFaker::Name.name }
4
- store_keeper_name { FFaker::Name.name }
5
- store_keeper_phone { FFaker::Name.name }
6
4
  length { 50 }
7
5
  width { 40 }
8
6
  height { 10 }
@@ -12,5 +10,7 @@ FactoryBot.define do
12
10
  gangway_width { 4 }
13
11
  gangway_corner_dist { 18 }
14
12
  warehouse
13
+ store_keeper factory: :user
14
+ store_keeper_id { create(:user).id }
15
15
  end
16
16
  end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  first_name { FFaker::Name.name }
4
4
  last_name { FFaker::Name.name }
5
5
  email { FFaker::Internet.email }
6
+ phone_number { '0913345678' }
6
7
  active { true }
7
8
  password { FFaker::Internet.password }
8
9
  details { {} }
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.0.9
4
+ version: 1.0.13
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-08-05 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -218,6 +218,7 @@ files:
218
218
  - Rakefile
219
219
  - app/controllers/cats/core/access_controller.rb
220
220
  - app/controllers/cats/core/application_controller.rb
221
+ - app/controllers/cats/core/menus_controller.rb
221
222
  - app/controllers/cats/core/notifications_controller.rb
222
223
  - app/controllers/cats/core/roles_controller.rb
223
224
  - app/controllers/cats/core/users_controller.rb
@@ -245,6 +246,8 @@ files:
245
246
  - app/models/cats/core/way_bill.rb
246
247
  - app/models/cats/core/way_bill_item.rb
247
248
  - app/notifications/cats/core/simple_notification.rb
249
+ - app/serializers/cats/core/role_menu_serializer.rb
250
+ - app/services/cats/core/menu_service.rb
248
251
  - app/services/cats/core/notification_service.rb
249
252
  - app/services/cats/core/token_auth_service.rb
250
253
  - config/routes.rb