Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhoc committed Sep 23, 2024
1 parent 9a4fb45 commit eccc75d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
26 changes: 26 additions & 0 deletions modules/mobile/app/models/mobile/v0/debt.rb
Original file line number Diff line number Diff line change
@@ -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
43 changes: 15 additions & 28 deletions modules/mobile/app/serializers/mobile/v0/debts_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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

0 comments on commit eccc75d

Please sign in to comment.