dscf-banking 0.2.8 → 0.3.0
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 +4 -4
- data/app/controllers/dscf/banking/accounts_controller.rb +18 -0
- data/app/controllers/dscf/banking/applications_controller.rb +0 -24
- data/app/controllers/dscf/banking/documents_controller.rb +40 -0
- data/app/models/dscf/banking/application.rb +55 -2
- data/app/serializers/dscf/banking/application_serializer.rb +1 -1
- data/app/serializers/dscf/banking/document_serializer.rb +10 -3
- data/app/services/dscf/banking/account_creation_service.rb +1 -1
- data/config/initializers/review_callbacks.rb +23 -0
- data/config/initializers/review_extensions.rb +36 -0
- data/config/routes.rb +3 -0
- data/lib/dscf/banking/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77261771378e8c5903e5f77c66f3919e7528514bd7c8a44070dbe07c61c5aced
|
4
|
+
data.tar.gz: 4db5b73418dc1a2625e1d01ba578d39e38655acf41361320735f75792eb986a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e23b8ca0fe1ed1ba9320edb49c4d22685547ea1a66fe5bcb7944ffafcb29ba9525107e42efe34f570006dcfe5364e5f70fb4d4be20eb4c9c51c3057f72883eff
|
7
|
+
data.tar.gz: 475ee3557215bb66076ad7b5bd414a23c3e41422200bc9c64ebb1b21032c9f737c9407b31f4bbf8745ab562de8444d07d22c01d7c42adab7825830c35140365f
|
@@ -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)
|
@@ -22,30 +22,6 @@ 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
|
-
|
49
25
|
private
|
50
26
|
|
51
27
|
def application_data(application)
|
@@ -4,6 +4,42 @@ module Dscf::Banking
|
|
4
4
|
|
5
5
|
before_action :find_application
|
6
6
|
|
7
|
+
def index
|
8
|
+
super do
|
9
|
+
documents = @application.documents
|
10
|
+
options = { each_serializer: DocumentSerializer }
|
11
|
+
[documents, options]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
super do
|
17
|
+
document = @application.documents.find(params[:id])
|
18
|
+
options = { serializer: DocumentSerializer }
|
19
|
+
[document, options]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
document = @application.documents.build(model_params)
|
25
|
+
|
26
|
+
if document.save
|
27
|
+
# Attach file if provided
|
28
|
+
document.files.attach(params[:document][:file]) if params[:document][:file].present?
|
29
|
+
|
30
|
+
render json: {
|
31
|
+
success: true,
|
32
|
+
data: DocumentSerializer.new(document).as_json
|
33
|
+
}, status: :created
|
34
|
+
else
|
35
|
+
render json: {
|
36
|
+
success: false,
|
37
|
+
error: "Failed to create document",
|
38
|
+
errors: document.errors.full_messages
|
39
|
+
}, status: :unprocessable_entity
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
7
43
|
private
|
8
44
|
|
9
45
|
def find_application
|
@@ -49,5 +85,9 @@ module Dscf::Banking
|
|
49
85
|
update: []
|
50
86
|
}
|
51
87
|
end
|
88
|
+
|
89
|
+
def serializer_class
|
90
|
+
Dscf::Banking::DocumentSerializer
|
91
|
+
end
|
52
92
|
end
|
53
93
|
end
|
@@ -22,6 +22,7 @@ module Dscf::Banking
|
|
22
22
|
before_validation :generate_application_number, if: -> { new_record? && application_number.blank? }
|
23
23
|
before_update :set_timestamps_on_status_change
|
24
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,7 +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
|
+
review_st = latest_review&.status || status
|
50
|
+
|
51
|
+
# Sync application status with review status
|
52
|
+
sync_status_with_review(review_st) if latest_review
|
53
|
+
|
54
|
+
review_st
|
49
55
|
end
|
50
56
|
|
51
57
|
def self.ransackable_attributes(auth_object = nil)
|
@@ -77,10 +83,57 @@ module Dscf::Banking
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def create_account_if_approved
|
80
|
-
|
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?
|
81
92
|
return if has_account?
|
82
93
|
|
83
94
|
AccountCreationService.call(self)
|
84
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
|
85
138
|
end
|
86
139
|
end
|
@@ -9,7 +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
|
+
has_many :documents, serializer: Dscf::Banking::DocumentSerializer
|
13
13
|
|
14
14
|
def has_account?
|
15
15
|
object.has_account?
|
@@ -1,8 +1,15 @@
|
|
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, :file_urls, :created_at, :updated_at
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def file_urls
|
6
|
+
return [] unless object.files.attached?
|
7
|
+
|
8
|
+
object.files.map do |file|
|
9
|
+
Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true)
|
10
|
+
end
|
11
|
+
rescue StandardError
|
12
|
+
[]
|
13
|
+
end
|
7
14
|
end
|
8
15
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Rails.application.config.to_prepare do
|
2
|
+
ActiveSupport::Notifications.subscribe("review.created") do |name, start, finish, id, payload|
|
3
|
+
reviewable = payload[:reviewable]
|
4
|
+
|
5
|
+
if reviewable.is_a?(Dscf::Banking::Application)
|
6
|
+
reviewable.reload
|
7
|
+
review_status = reviewable.review_status
|
8
|
+
|
9
|
+
status_map = {
|
10
|
+
"submitted" => "submitted",
|
11
|
+
"under_review" => "under_review",
|
12
|
+
"approved" => "approved",
|
13
|
+
"rejected" => "rejected",
|
14
|
+
"request_modification" => "request_modification"
|
15
|
+
}
|
16
|
+
|
17
|
+
mapped_status = status_map[review_status]
|
18
|
+
if mapped_status && reviewable.status != mapped_status
|
19
|
+
reviewable.update!(status: mapped_status)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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
data/lib/dscf/banking/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eyosiyas Mekbib
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-10-
|
10
|
+
date: 2025-10-16 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -482,6 +482,8 @@ 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_callbacks.rb
|
486
|
+
- config/initializers/review_extensions.rb
|
485
487
|
- config/locales/en.yml
|
486
488
|
- config/routes.rb
|
487
489
|
- db/migrate/20250830211002_create_dscf_banking_product_categories.rb
|