Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile debts model #18571

Merged
merged 10 commits into from
Oct 3, 2024
27 changes: 27 additions & 0 deletions modules/mobile/app/models/mobile/v0/debt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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
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
attribute :description, Types::String
end
end
end
end
73 changes: 34 additions & 39 deletions modules/mobile/app/serializers/mobile/v0/debts_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ 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
debts.map { |debt| serialize_debt(debt, id) }
Expand All @@ -36,34 +37,28 @@ def dependent_debts?(debts)
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_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'],
file_number: debt['fileNumber'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok if any of these debt attributes are nil? Do you need a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes nil is ok for the values

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

DebtStruct = Struct.new(:id,
:fileNumber,
:payeeNumber,
:personEntitled,
:deductionCode,
:benefitType,
:diaryCode,
:diaryCodeDescription,
:amountOverpaid,
:amountWithheld,
:originalAR,
:currentAR,
:debtHistory)
end
end
Loading