dscf-banking 0.2.7 → 0.2.9

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: c92f5cf56bdb2b4a3f6d15d1c75cfd1ac51da1e2e525ba7a568e80f289564d8a
4
- data.tar.gz: 34962544cd525e20993f49a278655c6d291803c86a411b90eb3946f1aec62aea
3
+ metadata.gz: df271e9f69727201aab1508e782bf5a18e7b59fba9e67dffd2224d92319f9280
4
+ data.tar.gz: '0618830ecf6bbab8f90cfffc3da24303cd08788cc8387d42070c4093b9be5b45'
5
5
  SHA512:
6
- metadata.gz: 12ba4363d0f4ab6b8edf6a432539b325d68a58d7ef49b1a1d0d756ccbe7880d311eeb903e63d19920a4bc25631b1c345abcabf5bb95cd8307ffa3be2b694c43d
7
- data.tar.gz: 2b8514d69f366c986b88f393fb8e7102974c71ae3936ab618b21ad59318c2002df6b1b21db304465177351189be07486ce4552f2ac0dbdb556fb4e1010a86b2b
6
+ metadata.gz: 8ff010dc9f9a04cddbcebf7dcdd83b5ba0b592a6bac40da63422002a7db9e2f9ecede7ae7aef4cc0cafd8ce579c2d8df8c3773f1e4ea8261de8839de353c8788
7
+ data.tar.gz: 8e52eeaa335df4fbeb0af438cbb1ac1f9a9c9ee15de8629212ad9bae3ce7eb2984e2936f485f9a5edb052e45ab7bd2738c0cc3fe898dcf5ce5bcb5971ed4d393
@@ -195,6 +195,24 @@ module Dscf::Banking
195
195
  }, status: :not_found
196
196
  end
197
197
 
198
+ def me
199
+ accounts = Dscf::Banking::Account
200
+ .joins(:application)
201
+ .where("dscf_banking_applications.user_id = ?", current_user.id)
202
+ .includes(:application, :virtual_account_product)
203
+
204
+ # Apply ordering
205
+ order_column = allowed_order_columns.include?(params[:order_by]) ? params[:order_by] : "created_at"
206
+ order_direction = %w[asc desc].include?(params[:order_direction]) ? params[:order_direction] : "desc"
207
+ accounts = accounts.order("dscf_banking_accounts.#{order_column} #{order_direction}")
208
+
209
+ render json: {
210
+ success: true,
211
+ data: accounts.map { |account| account_data(account) },
212
+ message: "User accounts retrieved successfully"
213
+ }
214
+ end
215
+
198
216
  private
199
217
 
200
218
  def account_data(account)
@@ -24,7 +24,7 @@ module Dscf::Banking
24
24
 
25
25
  private
26
26
 
27
- def application_data(application)
27
+ def application_data(application)
28
28
  {
29
29
  id: application.id,
30
30
  application_number: application.application_number,
@@ -52,7 +52,7 @@ module Dscf::Banking
52
52
  end
53
53
 
54
54
  def eager_loaded_associations
55
- [ :user, :virtual_account_product, :documents, reviews: { reviewed_by: :user_profile } ]
55
+ [ :user, :virtual_account_product, :account, :documents, reviews: { reviewed_by: :user_profile } ]
56
56
  end
57
57
 
58
58
  def allowed_order_columns
@@ -21,7 +21,8 @@ module Dscf::Banking
21
21
 
22
22
  before_validation :generate_application_number, if: -> { new_record? && application_number.blank? }
23
23
  before_update :set_timestamps_on_status_change
24
- after_update :create_account_if_approved
24
+ after_commit :create_account_if_approved, on: :update
25
+ after_find :sync_status_if_needed
25
26
 
26
27
  def approve!(approved_by = nil)
27
28
  update!(status: :approved, completed_at: Time.current)
@@ -45,13 +46,12 @@ module Dscf::Banking
45
46
 
46
47
  def review_status
47
48
  latest_review = reviews.where(context: "default").order(created_at: :desc).first
48
- latest_review&.status || status
49
- end
49
+ review_st = latest_review&.status || status
50
50
 
51
- def create_account_if_approved
52
- if review_status == "approved" && !has_account?
53
- AccountCreationService.call(self)
54
- end
51
+ # Sync application status with review status
52
+ sync_status_with_review(review_st) if latest_review
53
+
54
+ review_st
55
55
  end
56
56
 
57
57
  def self.ransackable_attributes(auth_object = nil)
@@ -81,5 +81,59 @@ module Dscf::Banking
81
81
  end
82
82
  end
83
83
  end
84
+
85
+ def create_account_if_approved
86
+ # First sync the status with the latest review
87
+ current_review_status = review_status # This will call sync_status_with_review
88
+
89
+ reload # Reload to get the updated status
90
+
91
+ return unless status_approved?
92
+ return if has_account?
93
+
94
+ AccountCreationService.call(self)
95
+ end
96
+
97
+ def sync_status_with_review(review_st)
98
+ return if @syncing_status
99
+
100
+ status_map = {
101
+ "submitted" => "submitted",
102
+ "under_review" => "under_review",
103
+ "approved" => "approved",
104
+ "rejected" => "rejected",
105
+ "request_modification" => "request_modification"
106
+ }
107
+
108
+ mapped_status = status_map[review_st]
109
+ if mapped_status && status != mapped_status && !new_record?
110
+ @syncing_status = true
111
+
112
+ # Prepare attributes for update
113
+ attributes_to_update = { status: mapped_status }
114
+
115
+ # If rejecting, also set rejection_reason from review feedback
116
+ if mapped_status == "rejected"
117
+ latest_review = reviews.where(context: "default", status: "rejected").order(created_at: :desc).first
118
+ if latest_review&.feedback.present?
119
+ attributes_to_update[:rejection_reason] = latest_review.feedback
120
+ end
121
+ end
122
+
123
+ update!(attributes_to_update)
124
+ @syncing_status = false
125
+ end
126
+ end
127
+
128
+ def sync_status_if_needed
129
+ return if @status_synced || new_record?
130
+
131
+ latest_review = reviews.where(context: "default").order(created_at: :desc).first
132
+ if latest_review && latest_review.status != status
133
+ sync_status_with_review(latest_review.status)
134
+ end
135
+
136
+ @status_synced = true
137
+ end
84
138
  end
85
139
  end
@@ -1,8 +1,12 @@
1
1
  module Dscf::Banking
2
2
  class DocumentSerializer < ActiveModel::Serializer
3
- attributes :id, :document_type, :is_verified, :verified_at, :metadata, :created_at, :updated_at
3
+ attributes :id, :document_type, :is_verified, :verified_at, :metadata, :created_at, :updated_at, :file_url
4
4
 
5
5
  # Remove polymorphic association that causes ActiveStorage issues
6
6
  # belongs_to :verified_by, polymorphic: true, optional: true
7
+
8
+ def file_url
9
+ object.file_url
10
+ end
7
11
  end
8
12
  end
@@ -47,7 +47,7 @@ module Dscf::Banking
47
47
  end
48
48
 
49
49
  def generate_account_name
50
- "Test Account - #{@application.application_number}"
50
+ "#{@application.virtual_account_product.product_name}"
51
51
  end
52
52
  end
53
53
  end
@@ -0,0 +1,36 @@
1
+ module Dscf::Banking
2
+ module ReviewExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ after_create :sync_application_status, if: -> { reviewable.is_a?(Dscf::Banking::Application) }
7
+ end
8
+
9
+ private
10
+
11
+ def sync_application_status
12
+ return unless reviewable.is_a?(Dscf::Banking::Application)
13
+
14
+ application = reviewable
15
+ review_status = application.review_status
16
+
17
+ status_map = {
18
+ "submitted" => "submitted",
19
+ "under_review" => "under_review",
20
+ "approved" => "approved",
21
+ "rejected" => "rejected",
22
+ "request_modification" => "request_modification"
23
+ }
24
+
25
+ mapped_status = status_map[review_status]
26
+ if mapped_status && application.status != mapped_status
27
+ application.update!(status: mapped_status)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ # Extend the Dscf::Core::Review model with our extensions
34
+ Rails.application.config.to_prepare do
35
+ Dscf::Core::Review.include(Dscf::Banking::ReviewExtensions) if defined?(Dscf::Core::Review)
36
+ end
data/config/routes.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  Dscf::Banking::Engine.routes.draw do
2
2
  resources :accounts do
3
+ collection do
4
+ get :me
5
+ end
3
6
  member do
4
7
  post :activate
5
8
  post :suspend
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Banking
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.9"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyosiyas Mekbib
@@ -482,6 +482,7 @@ files:
482
482
  - app/services/dscf/banking/deposit_service.rb
483
483
  - app/services/dscf/banking/transfer_service.rb
484
484
  - app/services/dscf/banking/withdrawal_service.rb
485
+ - config/initializers/review_extensions.rb
485
486
  - config/locales/en.yml
486
487
  - config/routes.rb
487
488
  - db/migrate/20250830211002_create_dscf_banking_product_categories.rb