diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index f1204e730..4416a738f 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -1,20 +1,22 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' +interface DecayInterface { + balance: Decimal + decay: Decimal + start: Date | null + end: Date | null + duration: number | null +} + @ObjectType() export class Decay { - constructor( - balance: Decimal, - decay: Decimal, - start: Date | null, - end: Date | null, - duration: number | null, - ) { - this.balance = balance - this.decay = decay - this.start = start - this.end = end - this.duration = duration + constructor(data: DecayInterface) { + this.balance = data.balance + this.decay = data.decay + this.start = data.start + this.end = data.end + this.duration = data.duration } @Field(() => Decimal) diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 3c3a684ef..523ca06bc 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -17,21 +17,23 @@ export class Transaction { this.balanceDate = transaction.balanceDate if (!transaction.decayStart) { // TODO: hot fix, we should separate decay calculation from decay graphql model - this.decay = new Decay( - transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - new Decimal(0), - null, - null, - null, - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: new Decimal(0), + start: null, + end: null, + duration: null, + }) } else { - this.decay = new Decay( - transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - transaction.decayStart, - transaction.balanceDate, - Math.round((transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000), - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + start: transaction.decayStart, + end: transaction.balanceDate, + duration: Math.round( + (transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000, + ), + }) } this.memo = transaction.memo this.creationDate = transaction.creationDate