dscf-credit 0.2.0 → 0.2.2

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: ab8778ae93f1e301f3f98e4715c341f177f6e12e47ab00a042355c098bdb4945
4
- data.tar.gz: cfa7f52505d8cfae80563bb1d2790346dd9f115af2db68b5339b3a65af33e709
3
+ metadata.gz: 3c8471bd555308d0b88c282f893299234859a46f02ae02c003f02b147115e1ae
4
+ data.tar.gz: 3becd29b404c498ff195e300afa0c313a00155cb20d2ec600f39da1d36e1a45e
5
5
  SHA512:
6
- metadata.gz: a5385b0be9ebdce8e6e763a14f40476f707c2860d2fdb83d2134b5cfd944967a6eda0e590ada5fdabff8d931ef79dbc6d1544078641e5dc31d2ea588af4c2192
7
- data.tar.gz: 6b4dcca19fd39513f9048c1e699be0838246e284c5a4e881cf6345e8127688fe305e74a58d042ddcf37ceb3623300f72c5718a1aa7a82e852183fbd3056b3b25
6
+ metadata.gz: c205f203030be0f10872f4dcc1dac30b3ad797abe5a006a071bd579459bd13bf95fb821144d86f96c021e8eb1b7494e1544b6a046eb7b67150484cfeb7910116
7
+ data.tar.gz: 4910b18be7d23f314940a74e70b2cf1e032b8134e50903ed1770283e5a363af87b5986f32d0308799620326fda211c123a735747d4d9eedd240c958153b87d66
@@ -102,7 +102,7 @@ module Dscf::Credit
102
102
  end
103
103
 
104
104
  def eager_loaded_associations
105
- [ :user, :bank, reviews: { reviewed_by: :user_profile } ]
105
+ [ :user, :bank, { user: { businesses: :business_type } }, reviews: { reviewed_by: :user_profile } ]
106
106
  end
107
107
 
108
108
  def allowed_order_columns
@@ -111,7 +111,7 @@ module Dscf::Credit
111
111
 
112
112
  def default_serializer_includes
113
113
  {
114
- default: [ :user, :bank, reviews: { reviewed_by: :user_profile } ]
114
+ default: [ :user, :bank, { user: { businesses: :business_type } }, reviews: { reviewed_by: :user_profile } ]
115
115
  }
116
116
  end
117
117
  end
@@ -10,7 +10,9 @@ module Dscf::Credit
10
10
  end
11
11
 
12
12
  def eager_loaded_associations
13
- [ :facilitator_application, reviews: { reviewed_by: :user_profile } ]
13
+ [
14
+ { facilitator_application: { user: { businesses: :business_type } } },
15
+ reviews: { reviewed_by: :user_profile } ]
14
16
  end
15
17
 
16
18
  def allowed_order_columns
@@ -19,8 +21,10 @@ module Dscf::Credit
19
21
 
20
22
  def default_serializer_includes
21
23
  {
22
- index: [ :facilitator_application, reviews: { reviewed_by: :user_profile } ],
23
- show: [ :facilitator_application, reviews: { reviewed_by: :user_profile } ],
24
+ index: [ { facilitator_application: { user: { businesses: :business_type } } },
25
+ reviews: { reviewed_by: :user_profile } ],
26
+ show: [ { facilitator_application: { user: { businesses: :business_type } } },
27
+ reviews: { reviewed_by: :user_profile } ],
24
28
  create: [ :reviews ],
25
29
  update: [ :facilitator_application, reviews: { reviewed_by: :user_profile } ]
26
30
  }
@@ -62,7 +62,7 @@ module Dscf::Credit
62
62
 
63
63
  def default_serializer_includes
64
64
  {
65
- index: [ :bank, :category, :parameter_normalizers, reviews: { reviewed_by: :user_profile } ],
65
+ index: [ :bank, :category, :parameter_normalizers, :scoring_param_type, reviews: { reviewed_by: :user_profile } ],
66
66
  show: [
67
67
  :bank, :category, :created_by, :scoring_param_type, :previous_version, :parameter_normalizers,
68
68
  reviews: { reviewed_by: :user_profile }
@@ -16,15 +16,28 @@ module Dscf::Credit
16
16
  )
17
17
  end
18
18
 
19
- rejected_user_ids = Dscf::Credit::FacilitatorApplication.joins(:reviews)
20
- .where(dscf_core_reviews: { status: "rejected" })
21
- .pluck(:user_id)
22
- .uniq
19
+ users = @clazz
20
+ .joins(businesses: :business_type)
21
+ .where(dscf_core_business_types: { id: business_type.id })
22
+ .where(
23
+ <<-SQL.squish
24
+ NOT EXISTS (
25
+ SELECT 1
26
+ FROM dscf_credit_facilitator_applications fa
27
+ WHERE fa.user_id = dscf_core_users.id
28
+ AND NOT EXISTS (
29
+ SELECT 1
30
+ FROM dscf_core_reviews r
31
+ WHERE r.reviewable_type = 'Dscf::Credit::FacilitatorApplication'
32
+ AND r.reviewable_id = fa.id
33
+ AND r.status = 'rejected'
34
+ )
35
+ )
36
+ SQL
37
+ )
38
+ .distinct
23
39
 
24
- @clazz.joins(businesses: :business_type)
25
- .where(dscf_core_business_types: { name: business_type_name })
26
- .where(id: rejected_user_ids)
27
- .distinct
40
+ users
28
41
  else
29
42
  @clazz.all
30
43
  end
@@ -107,41 +107,47 @@ module Dscf::Credit
107
107
  end
108
108
 
109
109
  def extract_parameter_value(parameter)
110
- param_type_name = parameter.scoring_param_type.name
111
110
  parameter_id = parameter.id.to_s
112
111
 
113
- # Get the appropriate JSON field based on parameter type
114
- json_field = get_json_field_for_param_type(param_type_name)
115
- return nil unless json_field
112
+ all_json_fields = {
113
+ user_info: loan_application.user_info || {},
114
+ bank_info: loan_application.bank_info || {},
115
+ facilitator_info: loan_application.facilitator_info || {},
116
+ field_assessment: loan_application.field_assessment || {}
117
+ }
118
+
119
+ param_data = nil
120
+ found_in_field = nil
121
+
122
+ all_json_fields.each do |field_name, field_data|
123
+ if field_data.key?(parameter_id)
124
+ param_data = field_data[parameter_id]
125
+ found_in_field = field_name
126
+ break # Stop at first match (IDs should be unique across fields)
127
+ end
128
+ end
129
+
130
+ if param_data.nil?
131
+ Rails.logger.warn "Parameter #{parameter_id} (#{parameter.name}) not found in any JSON field for loan_app #{loan_application.id}"
132
+ return nil
133
+ end
116
134
 
117
- # Extract value using parameter ID as key
118
- param_data = json_field[parameter_id]
119
- return nil unless param_data.is_a?(Hash)
135
+ unless param_data.is_a?(Hash)
136
+ Rails.logger.warn "Invalid param_data for #{parameter_id} in #{found_in_field}: expected Hash, got #{param_data.class}"
137
+ return nil
138
+ end
120
139
 
121
- # Validate that the param_name matches (optional safety check)
140
+ # Validate param_name matches (optional safety check)
122
141
  expected_param_name = param_data["param_name"]
123
142
  if expected_param_name && expected_param_name != parameter.name
124
- Rails.logger.warn "Parameter name mismatch for ID #{parameter_id}: expected '#{parameter.name}', got '#{expected_param_name}'"
143
+ Rails.logger.warn "Parameter name mismatch for ID #{parameter_id} in #{found_in_field}: expected '#{parameter.name}', got '#{expected_param_name}'"
125
144
  end
126
145
 
127
- param_data["value"]
146
+ raw_value = param_data["value"]
147
+ Rails.logger.debug "Extracted #{parameter.name} (ID #{parameter_id}) from #{found_in_field}: value=#{raw_value}"
148
+ raw_value
128
149
  end
129
150
 
130
- def get_json_field_for_param_type(param_type_name)
131
- case param_type_name.downcase
132
- when "user_info"
133
- loan_application.user_info || {}
134
- when "bank_info"
135
- loan_application.bank_info || {}
136
- when "facilitator_info"
137
- loan_application.facilitator_info || {}
138
- when "field_assessment"
139
- loan_application.field_assessment || {}
140
- else
141
- Rails.logger.warn "Unknown parameter type: #{param_type_name}"
142
- nil
143
- end
144
- end
145
151
 
146
152
  def normalize_parameter_value(parameter, raw_value)
147
153
  return 0.0 if raw_value.nil?
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Credit
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
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.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adoniyas
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-05 00:00:00.000000000 Z
10
+ date: 2025-10-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dscf-core