dscf-credit 0.1.6 → 0.1.7
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/credit/facilitator_applications_controller.rb +88 -5
- data/app/controllers/dscf/credit/scoring_parameters_controller.rb +8 -12
- data/app/models/dscf/credit/facilitator_application.rb +0 -1
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20250822092426_create_dscf_credit_facilitator_applications.rb +1 -1
- data/lib/dscf/credit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b98c5581c2ba2394b35bee75cce5a9f8de59cf7c94c12f1b8d162988a2e8a285
|
4
|
+
data.tar.gz: 6a377eaa47bd1b079f77fb24b408ebdbaf37e498703d85e3f39fbe5b0d233779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ddcceea25d14c51c2af4e3ec279751f8a69193afa3a0e8713de2fc6acb9470f0691067e3c3cbbf34b4727acb905714402c22abbc4e0e0b8bdc20bfdf16ef6a5
|
7
|
+
data.tar.gz: 620cd65a6e50a64c084aeba071ba854bc10ee9a01fd8acccb3b740c51245fc0b0138fcb249e80261fbf305c1ebe6572841d89bc882d442f9e2e09c6add0bf16e
|
@@ -4,12 +4,95 @@ module Dscf::Credit
|
|
4
4
|
include Dscf::Core::ReviewableController
|
5
5
|
|
6
6
|
def create
|
7
|
-
super
|
8
|
-
|
9
|
-
facilitator_application.user = current_user
|
10
|
-
facilitator_application.reviews.build(context: "default", status: "pending")
|
7
|
+
super do
|
8
|
+
facilitator_application = @clazz.new(model_params)
|
11
9
|
|
12
|
-
|
10
|
+
user = Dscf::Core::User.find(model_params[:user_id])
|
11
|
+
facilitator_application.user = user
|
12
|
+
facilitator_application.reviews.build(context: "default", status: "pending")
|
13
|
+
|
14
|
+
facilitator_application
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def bulk_create
|
19
|
+
if params[:facilitator_applications].blank?
|
20
|
+
return render_error(
|
21
|
+
"facilitator_application.errors.bulk_create",
|
22
|
+
errors: [ "At least one facilitator application is required" ],
|
23
|
+
status: :unprocessable_entity
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
applications_params = params.require(:facilitator_applications)
|
28
|
+
|
29
|
+
unless applications_params.is_a?(Array)
|
30
|
+
return render_error(
|
31
|
+
"facilitator_application.errors.bulk_create",
|
32
|
+
errors: [ "Expected an array of facilitator applications" ],
|
33
|
+
status: :unprocessable_entity
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
results = {
|
38
|
+
successful: [],
|
39
|
+
failed: [],
|
40
|
+
total_count: applications_params.length,
|
41
|
+
success_count: 0,
|
42
|
+
failure_count: 0
|
43
|
+
}
|
44
|
+
|
45
|
+
applications_params.each_with_index do |app_params, index|
|
46
|
+
begin
|
47
|
+
facilitator_application = @clazz.new(app_params.permit(:user_id, :bank_id))
|
48
|
+
|
49
|
+
if app_params[:user_id].present?
|
50
|
+
facilitator_application.user = Dscf::Core::User.find(app_params[:user_id])
|
51
|
+
else
|
52
|
+
raise ActiveRecord::RecordInvalid.new(facilitator_application), "User ID is required"
|
53
|
+
end
|
54
|
+
|
55
|
+
facilitator_application.reviews.build(context: "default", status: "pending")
|
56
|
+
|
57
|
+
if facilitator_application.save
|
58
|
+
results[:successful] << {
|
59
|
+
index: index,
|
60
|
+
id: facilitator_application.id,
|
61
|
+
user_id: facilitator_application.user_id,
|
62
|
+
bank_id: facilitator_application.bank_id,
|
63
|
+
message: "Successfully created"
|
64
|
+
}
|
65
|
+
results[:success_count] += 1
|
66
|
+
else
|
67
|
+
results[:failed] << {
|
68
|
+
index: index,
|
69
|
+
user_id: app_params[:user_id],
|
70
|
+
errors: facilitator_application.errors.full_messages
|
71
|
+
}
|
72
|
+
results[:failure_count] += 1
|
73
|
+
end
|
74
|
+
rescue ActiveRecord::RecordNotFound => e
|
75
|
+
results[:failed] << {
|
76
|
+
index: index,
|
77
|
+
user_id: app_params[:user_id],
|
78
|
+
errors: [ "User not found: #{e.message}" ]
|
79
|
+
}
|
80
|
+
results[:failure_count] += 1
|
81
|
+
rescue StandardError => e
|
82
|
+
results[:failed] << {
|
83
|
+
index: index,
|
84
|
+
user_id: app_params[:user_id],
|
85
|
+
errors: [ e.message ]
|
86
|
+
}
|
87
|
+
results[:failure_count] += 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
render_success(
|
92
|
+
"facilitator_application.success.bulk_create",
|
93
|
+
data: results,
|
94
|
+
status: :created
|
95
|
+
)
|
13
96
|
end
|
14
97
|
|
15
98
|
private
|
@@ -9,10 +9,10 @@ module Dscf::Credit
|
|
9
9
|
scoring_parameter.created_by = current_user
|
10
10
|
scoring_parameter.reviews.build(context: "default", status: "pending")
|
11
11
|
|
12
|
-
if
|
12
|
+
if validate_scoring_param_type_weight_limit(scoring_parameter)
|
13
13
|
scoring_parameter
|
14
14
|
else
|
15
|
-
scoring_parameter.errors.add(:weight, "would exceed the total weight limit of 1.0 for this
|
15
|
+
scoring_parameter.errors.add(:weight, "would exceed the total weight limit of 1.0 for this scoring parameter type")
|
16
16
|
render_error(errors: scoring_parameter.errors.full_messages, status: :unprocessable_entity)
|
17
17
|
return
|
18
18
|
end
|
@@ -20,8 +20,8 @@ module Dscf::Credit
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def update
|
23
|
-
unless
|
24
|
-
@obj.errors.add(:weight, "would exceed the total weight limit of 1.0 for this
|
23
|
+
unless validate_scoring_param_type_weight_limit(@obj, exclude_current: true)
|
24
|
+
@obj.errors.add(:weight, "would exceed the total weight limit of 1.0 for this scoring parameter type")
|
25
25
|
render_error(errors: @obj.errors.full_messages, status: :unprocessable_entity)
|
26
26
|
return
|
27
27
|
end
|
@@ -75,27 +75,23 @@ module Dscf::Credit
|
|
75
75
|
}
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
79
|
-
return true unless scoring_parameter.
|
78
|
+
def validate_scoring_param_type_weight_limit(scoring_parameter, exclude_current: false)
|
79
|
+
return true unless scoring_parameter.scoring_param_type_id && scoring_parameter.weight
|
80
80
|
|
81
|
-
# Get existing parameters in the same category for the same bank
|
82
81
|
existing_params = ScoringParameter.where(
|
83
82
|
bank_id: scoring_parameter.bank_id,
|
84
|
-
|
83
|
+
scoring_param_type_id: scoring_parameter.scoring_param_type_id,
|
85
84
|
active: true
|
86
85
|
)
|
87
86
|
|
88
|
-
# Exclude current parameter from the calculation when updating
|
89
87
|
if exclude_current && scoring_parameter.persisted?
|
90
88
|
existing_params = existing_params.where.not(id: scoring_parameter.id)
|
91
89
|
end
|
92
90
|
|
93
|
-
# Calculate total weight
|
94
91
|
current_total_weight = existing_params.sum(:weight)
|
95
92
|
new_total_weight = current_total_weight + scoring_parameter.weight.to_f
|
96
93
|
|
97
|
-
|
98
|
-
new_total_weight <= 1.001
|
94
|
+
new_total_weight <= 1.00
|
99
95
|
end
|
100
96
|
end
|
101
97
|
end
|
@@ -7,7 +7,6 @@ module Dscf::Credit
|
|
7
7
|
belongs_to :user, class_name: "Dscf::Core::User", foreign_key: "user_id"
|
8
8
|
belongs_to :bank, class_name: "Dscf::Credit::Bank", foreign_key: "bank_id"
|
9
9
|
|
10
|
-
validates :facilitator_info, presence: true
|
11
10
|
|
12
11
|
def self.ransackable_attributes(auth_object = nil)
|
13
12
|
%w[id user_id bank_id created_at updated_at]
|
data/config/locales/en.yml
CHANGED
@@ -299,6 +299,7 @@ en:
|
|
299
299
|
reject: "Facilitator application rejected successfully"
|
300
300
|
request_modification: "Modification requested for facilitator application successfully"
|
301
301
|
resubmit: "Facilitator application resubmitted successfully"
|
302
|
+
bulk_create: "Facilitator applications bulk creation completed"
|
302
303
|
errors:
|
303
304
|
index: "Failed to retrieve facilitator applications"
|
304
305
|
show: "Failed to retrieve facilitator application details"
|
@@ -308,6 +309,7 @@ en:
|
|
308
309
|
reject: "Failed to reject facilitator application"
|
309
310
|
request_modification: "Failed to request modification for facilitator application"
|
310
311
|
resubmit: "Failed to resubmit facilitator application"
|
312
|
+
bulk_create: "Failed to bulk create facilitator applications"
|
311
313
|
not_found: "Facilitator application not found"
|
312
314
|
|
313
315
|
# Global messages
|
data/config/routes.rb
CHANGED
@@ -3,7 +3,7 @@ class CreateDscfCreditFacilitatorApplications < ActiveRecord::Migration[8.0]
|
|
3
3
|
create_table :dscf_credit_facilitator_applications do |t|
|
4
4
|
t.references :user, null: false, foreign_key: { to_table: :dscf_core_users }
|
5
5
|
t.references :bank, null: false, foreign_key: { to_table: :dscf_credit_banks }
|
6
|
-
t.jsonb :facilitator_info, null:
|
6
|
+
t.jsonb :facilitator_info, null: true, default: {}
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
9
|
end
|
data/lib/dscf/credit/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dscf-credit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adoniyas
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-10-
|
10
|
+
date: 2025-10-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: dscf-core
|