dscf-banking 0.2.6 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 318c6e93b2062a45adb19d98709d9f0812788e0137bea60f9b56d66d2617b56a
4
- data.tar.gz: 910120a3392d73f497aa511c3f971da9326a4a7ddc45d5820430d908b0959c05
3
+ metadata.gz: bd6bfb0114ad393bd22ae2bf1db82507a7e50299aa6f7ac0c433e53ae3a24e91
4
+ data.tar.gz: 97773b5c82e95ab7d227d9473ce82658ce4df88966506d0354ee10d360749023
5
5
  SHA512:
6
- metadata.gz: 2195accd89bcc4f487e514e8209c31131c011bb5d676729d5ea18c68955d2bfd98a179a85e018c8e54901a473ee9c16da8179feb1c3580534fea68c273bc26c6
7
- data.tar.gz: 28a117bad46972db2b9759dcfeee8c3d9bba034bada79f924058b096a6873a93d84a1fd4f39942f3857bc8a94feef3462374f2334a82a2c28a470a8b9cdc86f7
6
+ metadata.gz: 41ff719fa8dceb6e423d57c80bc8d9b96aeb2ab619ab94eccffb24bc1cbe4ce852b160ecde131084e11902aedf95df074af6b3589ffe3335f28cfcf10abccdcc
7
+ data.tar.gz: 5db3b15472498d3509cfe556ade8bf5e64ff7261cd3e0a338f898351c8a59110fddba5d4a04f1857a106508a5154c88d8dcd3964fbcaa5b22800478ede721e49
@@ -22,9 +22,33 @@ module Dscf::Banking
22
22
  resubmit: { status: "submitted", update_model: true }
23
23
  }
24
24
 
25
+ # Override perform_review_action to sync application status with review status
26
+ def perform_review_action(action_name, action_config, context_name)
27
+ result = super
28
+
29
+ # After successful review action, update the application's status to match
30
+ if result.is_a?(Hash) && result[:success] && @obj
31
+ review_status = @obj.review_status
32
+ application_status_map = {
33
+ "submitted" => "submitted",
34
+ "under_review" => "under_review",
35
+ "approved" => "approved",
36
+ "rejected" => "rejected",
37
+ "request_modification" => "request_modification"
38
+ }
39
+
40
+ new_status = application_status_map[review_status]
41
+ if new_status && @obj.status != new_status
42
+ @obj.update_column(:status, Application.statuses[new_status])
43
+ end
44
+ end
45
+
46
+ result
47
+ end
48
+
25
49
  private
26
50
 
27
- def application_data(application)
51
+ def application_data(application)
28
52
  {
29
53
  id: application.id,
30
54
  application_number: application.application_number,
@@ -52,7 +76,7 @@ module Dscf::Banking
52
76
  end
53
77
 
54
78
  def eager_loaded_associations
55
- [ :user, :virtual_account_product, reviews: { reviewed_by: :user_profile } ]
79
+ [ :user, :virtual_account_product, :account, :documents, reviews: { reviewed_by: :user_profile } ]
56
80
  end
57
81
 
58
82
  def allowed_order_columns
@@ -61,10 +85,10 @@ module Dscf::Banking
61
85
 
62
86
  def default_serializer_includes
63
87
  {
64
- index: [:user, :virtual_account_product, reviews: { reviewed_by: :user_profile }],
65
- show: [:user, :virtual_account_product, :account, reviews: { reviewed_by: :user_profile }],
66
- create: [:reviews],
67
- update: [:user, :virtual_account_product, :account, reviews: { reviewed_by: :user_profile }]
88
+ index: [ :user, :virtual_account_product, :documents, reviews: { reviewed_by: :user_profile } ],
89
+ show: [ :user, :virtual_account_product, :account, :documents, reviews: { reviewed_by: :user_profile } ],
90
+ create: [ :reviews, :documents ],
91
+ update: [ :user, :virtual_account_product, :account, :documents, reviews: { reviewed_by: :user_profile } ]
68
92
  }
69
93
  end
70
94
  end
@@ -0,0 +1,53 @@
1
+ module Dscf::Banking
2
+ class DocumentsController < ApplicationController
3
+ include Dscf::Core::Common
4
+
5
+ before_action :find_application
6
+
7
+ private
8
+
9
+ def find_application
10
+ @application = Application.find(params[:application_id])
11
+ end
12
+
13
+ def model_class
14
+ Dscf::Core::Document
15
+ end
16
+
17
+ def collection
18
+ @application.documents
19
+ end
20
+
21
+ def build_resource
22
+ @application.documents.build
23
+ end
24
+
25
+ def find_resource
26
+ @application.documents.find(params[:id])
27
+ end
28
+
29
+ def model_params
30
+ params.require(:document).permit(
31
+ :document_type,
32
+ metadata: {}
33
+ ).merge(documentable: @application)
34
+ end
35
+
36
+ def eager_loaded_associations
37
+ []
38
+ end
39
+
40
+ def allowed_order_columns
41
+ %w[id document_type is_verified verified_at created_at updated_at]
42
+ end
43
+
44
+ def default_serializer_includes
45
+ {
46
+ index: [],
47
+ show: [],
48
+ create: [],
49
+ update: []
50
+ }
51
+ end
52
+ end
53
+ end
@@ -6,7 +6,7 @@ module Dscf::Banking
6
6
  render json: {
7
7
  success: false,
8
8
  error: "Transaction not found",
9
- errors: ["Transaction with ID #{params[:id]} not found"]
9
+ errors: [ "Transaction with ID #{params[:id]} not found" ]
10
10
  }, status: :not_found
11
11
  end
12
12
 
@@ -83,10 +83,10 @@ module Dscf::Banking
83
83
 
84
84
  def default_serializer_includes
85
85
  {
86
- index: [:product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile }],
87
- show: [:product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile }],
88
- create: [:reviews],
89
- update: [:product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile }]
86
+ index: [ :product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile } ],
87
+ show: [ :product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile } ],
88
+ create: [ :reviews ],
89
+ update: [ :product_category, :created_by, :approved_by, reviews: { reviewed_by: :user_profile } ]
90
90
  }
91
91
  end
92
92
  end
@@ -8,6 +8,7 @@ module Dscf::Banking
8
8
  belongs_to :assigned_branch_manager, class_name: "Dscf::Core::User", optional: true
9
9
  belongs_to :virtual_account_product, class_name: "Dscf::Banking::VirtualAccountProduct"
10
10
  has_one :account, class_name: "Dscf::Banking::Account"
11
+ has_many :documents, class_name: "Dscf::Core::Document", as: :documentable, dependent: :destroy
11
12
 
12
13
  validates :application_number, presence: true, uniqueness: true, length: { maximum: 50 }
13
14
  validates :applicant_type, presence: true
@@ -20,7 +21,7 @@ module Dscf::Banking
20
21
 
21
22
  before_validation :generate_application_number, if: -> { new_record? && application_number.blank? }
22
23
  before_update :set_timestamps_on_status_change
23
- after_update :create_account_if_approved
24
+ after_commit :create_account_if_approved, on: :update
24
25
 
25
26
  def approve!(approved_by = nil)
26
27
  update!(status: :approved, completed_at: Time.current)
@@ -43,22 +44,16 @@ module Dscf::Banking
43
44
  end
44
45
 
45
46
  def review_status
46
- latest_review = reviews.where(context: 'default').order(created_at: :desc).first
47
+ latest_review = reviews.where(context: "default").order(created_at: :desc).first
47
48
  latest_review&.status || status
48
49
  end
49
50
 
50
- def create_account_if_approved
51
- if review_status == 'approved' && !has_account?
52
- AccountCreationService.call(self)
53
- end
54
- end
55
-
56
51
  def self.ransackable_attributes(auth_object = nil)
57
52
  %w[id application_number status submitted_at completed_at created_at updated_at]
58
53
  end
59
54
 
60
55
  def self.ransackable_associations(auth_object = nil)
61
- %w[user virtual_account_product account reviews]
56
+ %w[user virtual_account_product account reviews documents]
62
57
  end
63
58
 
64
59
  private
@@ -80,5 +75,12 @@ module Dscf::Banking
80
75
  end
81
76
  end
82
77
  end
78
+
79
+ def create_account_if_approved
80
+ return unless review_status == "approved"
81
+ return if has_account?
82
+
83
+ AccountCreationService.call(self)
84
+ end
83
85
  end
84
86
  end
@@ -9,6 +9,7 @@ module Dscf::Banking
9
9
  belongs_to :assigned_branch_manager, optional: true
10
10
  has_one :account, serializer: AccountSerializer, if: :has_account?
11
11
  has_many :reviews, serializer: Dscf::Core::ReviewSerializer
12
+ has_many :documents, serializer: DocumentSerializer
12
13
 
13
14
  def has_account?
14
15
  object.has_account?
@@ -0,0 +1,8 @@
1
+ module Dscf::Banking
2
+ class DocumentSerializer < ActiveModel::Serializer
3
+ attributes :id, :document_type, :is_verified, :verified_at, :metadata, :created_at, :updated_at
4
+
5
+ # Remove polymorphic association that causes ActiveStorage issues
6
+ # belongs_to :verified_by, polymorphic: true, optional: true
7
+ end
8
+ end
@@ -9,7 +9,7 @@ module Dscf::Banking
9
9
  end
10
10
 
11
11
  def call
12
- return nil unless @application.review_status == 'approved'
12
+ return nil unless @application.review_status == "approved"
13
13
  return nil if account_already_exists?
14
14
 
15
15
  create_account
data/config/routes.rb CHANGED
@@ -30,6 +30,7 @@ Dscf::Banking::Engine.routes.draw do
30
30
  patch :request_modification
31
31
  patch :resubmit
32
32
  end
33
+ resources :documents, only: [ :index, :show, :create, :update, :destroy ]
33
34
  end
34
35
 
35
36
  resources :transaction_types
data/db/seeds.rb CHANGED
@@ -63,7 +63,7 @@ end
63
63
  puts "Created system deposit account: #{system_deposit_account.name}"
64
64
 
65
65
  system_withdrawal_account = Dscf::Banking::Account.find_or_create_by(
66
- name: "System Withdrawal Account",
66
+ name: "System Withdrawal Account",
67
67
  system_account: true
68
68
  ) do |account|
69
69
  account.currency = "ETB"
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Banking
3
- VERSION = "0.2.6"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyosiyas Mekbib
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-14 00:00:00.000000000 Z
10
+ date: 2025-10-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails