mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
use interface for decay constructor
This commit is contained in:
parent
a6e7036339
commit
0bcf2cbd8c
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user