From eccc75d89bd5354b766b4d1c258b9705e49d4fa9 Mon Sep 17 00:00:00 2001 From: Tonksthebear Date: Mon, 23 Sep 2024 11:08:17 -0700 Subject: [PATCH 1/3] WIP --- modules/mobile/app/models/mobile/v0/debt.rb | 26 +++++++++++ .../serializers/mobile/v0/debts_serializer.rb | 43 +++++++------------ 2 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 modules/mobile/app/models/mobile/v0/debt.rb diff --git a/modules/mobile/app/models/mobile/v0/debt.rb b/modules/mobile/app/models/mobile/v0/debt.rb new file mode 100644 index 00000000000..82610a3a6f6 --- /dev/null +++ b/modules/mobile/app/models/mobile/v0/debt.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'common/models/resource' + +module Mobile + module V0 + class Debt < Common::Resource + attribute :id, Types::String + attribute :file_number, Types::String.optional.default(nil) + attribute :payee_number, Types::String.optional.default(nil) + attribute :deduction_code, Types::String.optional.default(nil) + attribute :benefit_type, Types::String.optional.default(nil) + attribute :diary_code, Types::String.optional.default(nil) + attribute :diary_code_description, Types::String.optional.default(nil) + attribute :amount_overpaid, Types::Float.optional.default(nil) + attribute :amount_withheld, Types::Float.optional.default(nil) + attribute :original_a_r, Types::Float.optional.default(nil) + attribute :current_a_r, Types::Float.optional.default(nil) + attribute :debt_history, Types::Array do + attribute :date, Types::Date + attribute :letter_code, Types::String + attribute :description, Types::String + end + end + end +end diff --git a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb index 493a1ec904b..b33db1f5397 100644 --- a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb +++ b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb @@ -19,6 +19,7 @@ class DebtsSerializer :originalAR, :currentAR, :debtHistory + def initialize(debts, id = nil) resource = if debts.is_a? Array debts.map { |debt| serialize_debt(debt, id) } @@ -32,38 +33,24 @@ def initialize(debts, id = nil) private def dependent_debts?(debts) - Array.wrap(debts).any? { |debt| debt['payeeNumber'] != '00' } + Array.wrap(debts).any? { |debt| debt.payee_number != '00' } end def serialize_debt(debt, id = nil) - DebtStruct.new(id: id || debt['id'], - fileNumber: debt['fileNumber'], - payeeNumber: debt['payeeNumber'], - personEntitled: debt['personEntitled'], - deductionCode: debt['deductionCode'], - benefitType: debt['benefitType'], - diaryCode: debt['diaryCode'], - diaryCodeDescription: debt['diaryCodeDescription'], - amountOverpaid: debt['amountOverpaid'], - amountWithheld: debt['amountWithheld'], - originalAR: debt['originalAR'], - currentAR: debt['currentAR'], - debtHistory: debt['debtHistory']) + Debt.new(id: id || debt['id'], + fileNumber: debt['fileNumber'], + payeeNumber: debt['payeeNumber'], + personEntitled: debt['personEntitled'], + deductionCode: debt['deductionCode'], + benefitType: debt['benefitType'], + diaryCode: debt['diaryCode'], + diaryCodeDescription: debt['diaryCodeDescription'], + amountOverpaid: debt['amountOverpaid'], + amountWithheld: debt['amountWithheld'], + originalAR: debt['originalAR'], + currentAR: debt['currentAR'], + debtHistory: debt['debtHistory']) end end - - DebtStruct = Struct.new(:id, - :fileNumber, - :payeeNumber, - :personEntitled, - :deductionCode, - :benefitType, - :diaryCode, - :diaryCodeDescription, - :amountOverpaid, - :amountWithheld, - :originalAR, - :currentAR, - :debtHistory) end end From 5ee9381957373ecbbf61d26dded2eb810891d4a3 Mon Sep 17 00:00:00 2001 From: Tonksthebear Date: Mon, 23 Sep 2024 11:25:55 -0700 Subject: [PATCH 2/3] Fix issues --- modules/mobile/app/models/mobile/v0/debt.rb | 5 +- .../serializers/mobile/v0/debts_serializer.rb | 58 +++++++++++-------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/modules/mobile/app/models/mobile/v0/debt.rb b/modules/mobile/app/models/mobile/v0/debt.rb index 82610a3a6f6..ab02abc9341 100644 --- a/modules/mobile/app/models/mobile/v0/debt.rb +++ b/modules/mobile/app/models/mobile/v0/debt.rb @@ -8,14 +8,15 @@ class Debt < Common::Resource attribute :id, Types::String attribute :file_number, Types::String.optional.default(nil) attribute :payee_number, Types::String.optional.default(nil) + attribute :person_entitled, Types::String.optional.default(nil) attribute :deduction_code, Types::String.optional.default(nil) attribute :benefit_type, Types::String.optional.default(nil) attribute :diary_code, Types::String.optional.default(nil) attribute :diary_code_description, Types::String.optional.default(nil) attribute :amount_overpaid, Types::Float.optional.default(nil) attribute :amount_withheld, Types::Float.optional.default(nil) - attribute :original_a_r, Types::Float.optional.default(nil) - attribute :current_a_r, Types::Float.optional.default(nil) + attribute :original_ar, Types::Float.optional.default(nil) + attribute :current_ar, Types::Float.optional.default(nil) attribute :debt_history, Types::Array do attribute :date, Types::Date attribute :letter_code, Types::String diff --git a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb index b33db1f5397..3005c884406 100644 --- a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb +++ b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb @@ -7,18 +7,18 @@ class DebtsSerializer set_type :debts - attributes :fileNumber, - :payeeNumber, - :personEntitled, - :deductionCode, - :benefitType, - :diaryCode, - :diaryCodeDescription, - :amountOverpaid, - :amountWithheld, - :originalAR, - :currentAR, - :debtHistory + attributes :file_number, + :payee_number, + :person_entitled, + :deduction_code, + :benefit_type, + :diary_code, + :diary_code_description, + :amount_overpaid, + :amount_withheld, + :original_ar, + :current_ar, + :debt_history def initialize(debts, id = nil) resource = if debts.is_a? Array @@ -33,23 +33,31 @@ def initialize(debts, id = nil) private def dependent_debts?(debts) - Array.wrap(debts).any? { |debt| debt.payee_number != '00' } + Array.wrap(debts).any? { |debt| debt['payeeNumber'] != '00' } end def serialize_debt(debt, id = nil) + debt_history = Array.wrap(debt['debtHistory']).map do |history| + { + date: history['date'], + letter_code: history['letterCode'], + description: history['description'] + } + end + Debt.new(id: id || debt['id'], - fileNumber: debt['fileNumber'], - payeeNumber: debt['payeeNumber'], - personEntitled: debt['personEntitled'], - deductionCode: debt['deductionCode'], - benefitType: debt['benefitType'], - diaryCode: debt['diaryCode'], - diaryCodeDescription: debt['diaryCodeDescription'], - amountOverpaid: debt['amountOverpaid'], - amountWithheld: debt['amountWithheld'], - originalAR: debt['originalAR'], - currentAR: debt['currentAR'], - debtHistory: debt['debtHistory']) + file_number: debt['fileNumber'], + payee_number: debt['payeeNumber'], + person_entitled: debt['personEntitled'], + deduction_code: debt['deductionCode'], + benefit_type: debt['benefitType'], + diary_code: debt['diaryCode'], + diary_code_description: debt['diaryCodeDescription'], + amount_overpaid: debt['amountOverpaid'], + amount_withheld: debt['amountWithheld'], + original_ar: debt['originalAR'], + current_ar: debt['currentAR'], + debt_history:) end end end From 3a960d4d724aeebeda5598b9268b239d17fda96b Mon Sep 17 00:00:00 2001 From: Tonksthebear Date: Mon, 23 Sep 2024 11:28:52 -0700 Subject: [PATCH 3/3] Remove optional from parameters --- modules/mobile/app/models/mobile/v0/debt.rb | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/mobile/app/models/mobile/v0/debt.rb b/modules/mobile/app/models/mobile/v0/debt.rb index ab02abc9341..bf25937eb4b 100644 --- a/modules/mobile/app/models/mobile/v0/debt.rb +++ b/modules/mobile/app/models/mobile/v0/debt.rb @@ -6,17 +6,17 @@ module Mobile module V0 class Debt < Common::Resource attribute :id, Types::String - attribute :file_number, Types::String.optional.default(nil) - attribute :payee_number, Types::String.optional.default(nil) - attribute :person_entitled, Types::String.optional.default(nil) - attribute :deduction_code, Types::String.optional.default(nil) - attribute :benefit_type, Types::String.optional.default(nil) - attribute :diary_code, Types::String.optional.default(nil) - attribute :diary_code_description, Types::String.optional.default(nil) - attribute :amount_overpaid, Types::Float.optional.default(nil) - attribute :amount_withheld, Types::Float.optional.default(nil) - attribute :original_ar, Types::Float.optional.default(nil) - attribute :current_ar, Types::Float.optional.default(nil) + attribute :file_number, Types::String + attribute :payee_number, Types::String + attribute :person_entitled, Types::String + attribute :deduction_code, Types::String + attribute :benefit_type, Types::String + attribute :diary_code, Types::String + attribute :diary_code_description, Types::String + attribute :amount_overpaid, Types::Float + attribute :amount_withheld, Types::Float + attribute :original_ar, Types::Float + attribute :current_ar, Types::Float attribute :debt_history, Types::Array do attribute :date, Types::Date attribute :letter_code, Types::String