cats_core 1.2.15 → 1.2.16

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: '0259f4a23c09b64cad9bc0f1c1488eb6671590d9cb0b159943a9420644137f18'
4
- data.tar.gz: 16af2ac84725a7fc0ce5fe87e485d6dbae46bca0d3b8f290a219175ff8c14a5c
3
+ metadata.gz: 83ed27840275615cce0b4a2fdee9d147a61407eef87df375e9db5e0424d4e923
4
+ data.tar.gz: 06a77ee55dec5a1d292afeaa225b35629867d85eac43640d5073aab84b657634
5
5
  SHA512:
6
- metadata.gz: dc637444ec8abe5e3f00b3b540915d49458edf3b460658209d4ec95ac5db30a7ed070673dbbe40d9476be8c626cf503b86dac8d456f7d000a44928f1955bfd3a
7
- data.tar.gz: 489b67dc9d9709d2d0bf93d653662eafb40faddff1659f5a7af122008cf0dd05a0270d89d2f4d29a1f44eb1efd15238085c994908c21f1c14767d067e556815d
6
+ metadata.gz: f57ac8ebc0d69cb0abc5e0b19a28ae3afd4b3549a72b2fe34469bf63e15bc05067fa101bc378b97f073b5650b66d21516d9ea7998d165e8e5b133d971e08dbfe
7
+ data.tar.gz: 41f293dd59320cafef958b1d1dcf6b2342e2af1d696e31fb761ff50cf749966e5a993062d23f3e859c32bbb0431cba93c333b7410977be67a33c1bb8575e829a
@@ -3,11 +3,26 @@ module Cats
3
3
  class DispatchPlansController < ApplicationController
4
4
  include Common
5
5
 
6
+ def plans_for_user
7
+ plans = Cats::Core::DispatchPlan.where(prepared_by: current_user)
8
+ render json: { success: true, data: serialize(plans) }
9
+ end
10
+
6
11
  def filter
7
12
  query = Cats::Core::DispatchPlan.ransack(params[:q])
8
13
  render json: { success: true, data: serialize(query.result) }
9
14
  end
10
15
 
16
+ def create
17
+ obj = Cats::Core::DispatchPlan.new(model_params)
18
+ obj.prepared_by = current_user
19
+ if obj.save
20
+ render json: { success: true, data: serialize(obj) }, status: :created
21
+ else
22
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ end
25
+
11
26
  def approve
12
27
  plan = Cats::Core::DispatchPlan.find(params[:id])
13
28
  plan.approve
@@ -6,6 +6,9 @@ module Cats
6
6
  STATUSES = [DRAFT, APPROVED].freeze
7
7
 
8
8
  belongs_to :request, polymorphic: true, optional: true
9
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
10
+ belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
11
+
9
12
  has_many :dispatch_plan_items
10
13
 
11
14
  validates :reference_no, presence: true, uniqueness: true
@@ -6,7 +6,7 @@ module Cats
6
6
 
7
7
  validates :price, presence: true, numericality: { greater_than: 0 }
8
8
  validates :rank, numericality: { greater_than: 0 }, allow_nil: true
9
- validate :validate_winner_is_set_for_rank
9
+ validate :validate_rank_is_set_for_winner
10
10
 
11
11
  delegate(:name, to: :transporter, prefix: true)
12
12
 
@@ -18,10 +18,10 @@ module Cats
18
18
  save!
19
19
  end
20
20
 
21
- def validate_winner_is_set_for_rank
22
- return if winner
21
+ def validate_rank_is_set_for_winner
22
+ return if rank
23
23
 
24
- errors.add(:rank, 'cannot be set for a non-winning offer.') if rank
24
+ errors.add(:winner, 'cannot be set for a non-ranked offer.') if winner
25
25
  end
26
26
  end
27
27
  end
data/config/routes.rb CHANGED
@@ -33,6 +33,7 @@ Cats::Core::Engine.routes.draw do
33
33
  get 'stores', controller: :users, action: :stores
34
34
  get 'warehouse', controller: :users, action: :warehouse
35
35
  get 'hub', controller: :users, action: :hub
36
+ get 'plans', controller: :dispatch_plans, action: :plans_for_user
36
37
  post 'assign_role'
37
38
  post 'revoke_role'
38
39
  end
@@ -7,6 +7,15 @@ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
7
7
  t.references :request, polymorphic: true
8
8
  t.boolean :upstream, null: false, default: false
9
9
 
10
+ t.references :prepared_by,
11
+ null: false,
12
+ index: { name: 'pb_on_dp_indx' },
13
+ foreign_key: { to_table: :cats_core_users }
14
+ t.references :approved_by,
15
+ null: true,
16
+ index: { name: 'ab_on_dp_indx' },
17
+ foreign_key: { to_table: :cats_core_users }
18
+
10
19
  t.timestamps
11
20
  end
12
21
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.15'.freeze
3
+ VERSION = '1.2.16'.freeze
4
4
  end
5
5
  end
@@ -4,5 +4,7 @@ FactoryBot.define do
4
4
  status { Cats::Core::DispatchPlan::DRAFT }
5
5
  request { nil }
6
6
  upstream { false }
7
+ prepared_by factory: :user
8
+ approved_by { nil }
7
9
  end
8
10
  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.2.15
4
+ version: 1.2.16
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-12-13 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers