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