cats_core 1.0.12 → 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: ad0f19c4e9e9d38a4038b2f94ca78ea18fb730dccb1c04bacf403a8fe5b29de5
4
- data.tar.gz: 452ec1bb9126955274e5adae51d60a903e88674da97610b1b9945c43995d1ab6
3
+ metadata.gz: c166b58630fc770c2447694d5d57f59edd26ab7bee0caf07f762fc16d21f4069
4
+ data.tar.gz: 7cc6aead85c41426225eb4d306e92cf85ac7024b4690324a62985b7c6b163756
5
5
  SHA512:
6
- metadata.gz: 40dcc3d2d091d837d24da04a8889bca46b8afa22662c27fa518fb3ef9b98c2b20aad829f3f5126e444566e6229ca67d954dfa0ac7f76e93c4f03ef80c40fded4
7
- data.tar.gz: ad35c7773f8b1ea0bf10193d70e0857096da4768029c4b1de675b1a9c005e0d6fba86f8201739fafde97122a137a2122bd4aa12b506b965a053a2606f963d418
6
+ metadata.gz: 8a6c48372747e4c159c7fae9d51af746740fe7d556fc9b0cee36d9ba814ccd33aa25be298681729ad474b63c7c30881b79dcdb5da2a2da47d9962f6b3df325a2
7
+ data.tar.gz: 30805a86c89f24e1472a177c7cedf1c18a5ccbc18756bf316eca62138d63247a05ee42c18004b06a1ce898ac4343341045eff7f59921d16ea70a22ac2c33d4d9
@@ -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
@@ -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]
@@ -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.12'.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.12
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-06 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