mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into eliminate-server-user-table
This commit is contained in:
commit
e3a807ed95
@ -5,33 +5,20 @@ import Decimal from 'decimal.js-light'
|
||||
export class Balance {
|
||||
constructor(data: {
|
||||
balance: Decimal
|
||||
decay: Decimal
|
||||
lastBookedBalance: Decimal
|
||||
balanceGDT: number | null
|
||||
count: number
|
||||
linkCount: number
|
||||
lastBookedDate?: Date | null
|
||||
}) {
|
||||
this.balance = data.balance
|
||||
this.decay = data.decay
|
||||
this.lastBookedBalance = data.lastBookedBalance
|
||||
this.balanceGDT = data.balanceGDT || null
|
||||
this.count = data.count
|
||||
this.linkCount = data.linkCount
|
||||
this.lastBookedDate = data.lastBookedDate || null
|
||||
}
|
||||
|
||||
// the actual balance, decay included
|
||||
@Field(() => Decimal)
|
||||
balance: Decimal
|
||||
|
||||
// the decay since the last booked balance
|
||||
@Field(() => Decimal)
|
||||
decay: Decimal
|
||||
|
||||
@Field(() => Decimal)
|
||||
lastBookedBalance: Decimal
|
||||
|
||||
@Field(() => Number, { nullable: true })
|
||||
balanceGDT: number | null
|
||||
|
||||
@ -42,8 +29,4 @@ export class Balance {
|
||||
// the count of transaction links
|
||||
@Field(() => Number)
|
||||
linkCount: number
|
||||
|
||||
// may be null as there may be no transaction
|
||||
@Field(() => Date, { nullable: true })
|
||||
lastBookedDate: Date | null
|
||||
}
|
||||
|
||||
@ -1,17 +1,21 @@
|
||||
import { ObjectType, Field, Int } from 'type-graphql'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
interface DecayInterface {
|
||||
balance: Decimal
|
||||
decay: Decimal
|
||||
roundedDecay: 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,
|
||||
) {
|
||||
constructor({ balance, decay, roundedDecay, start, end, duration }: DecayInterface) {
|
||||
this.balance = balance
|
||||
this.decay = decay
|
||||
this.roundedDecay = roundedDecay
|
||||
this.start = start
|
||||
this.end = end
|
||||
this.duration = duration
|
||||
@ -23,6 +27,9 @@ export class Decay {
|
||||
@Field(() => Decimal)
|
||||
decay: Decimal
|
||||
|
||||
@Field(() => Decimal)
|
||||
roundedDecay: Decimal
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
start: Date | null
|
||||
|
||||
|
||||
@ -17,21 +17,26 @@ 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),
|
||||
roundedDecay: 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),
|
||||
// TODO: add correct value when decay must be rounded in transaction context
|
||||
roundedDecay: new Decimal(0),
|
||||
start: transaction.decayStart,
|
||||
end: transaction.balanceDate,
|
||||
duration: Math.round(
|
||||
(transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000,
|
||||
),
|
||||
})
|
||||
}
|
||||
this.memo = transaction.memo
|
||||
this.creationDate = transaction.creationDate
|
||||
|
||||
@ -29,8 +29,6 @@ export class BalanceResolver {
|
||||
if (!lastTransaction) {
|
||||
return new Balance({
|
||||
balance: new Decimal(0),
|
||||
decay: new Decimal(0),
|
||||
lastBookedBalance: new Decimal(0),
|
||||
balanceGDT,
|
||||
count: 0,
|
||||
linkCount: 0,
|
||||
@ -69,12 +67,9 @@ export class BalanceResolver {
|
||||
balance: calculatedDecay.balance
|
||||
.minus(sumHoldAvailableAmount.toString())
|
||||
.toDecimalPlaces(2, Decimal.ROUND_DOWN), // round towards zero
|
||||
decay: calculatedDecay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), // round towards - infinity
|
||||
lastBookedBalance: lastTransaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
||||
balanceGDT,
|
||||
count,
|
||||
linkCount,
|
||||
lastBookedDate: lastTransaction.balanceDate,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ function calculateDecay(
|
||||
const decay: Decay = {
|
||||
balance: amount,
|
||||
decay: new Decimal(0),
|
||||
roundedDecay: new Decimal(0),
|
||||
start: null,
|
||||
end: null,
|
||||
duration: null,
|
||||
@ -52,6 +53,10 @@ function calculateDecay(
|
||||
decay.end = to
|
||||
decay.balance = decayFormula(amount, decay.duration)
|
||||
decay.decay = decay.balance.minus(amount)
|
||||
decay.roundedDecay = amount
|
||||
.toDecimalPlaces(2, Decimal.ROUND_DOWN)
|
||||
.minus(decay.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN).toString())
|
||||
.mul(-1)
|
||||
return decay
|
||||
}
|
||||
|
||||
|
||||
@ -68,12 +68,12 @@ const virtualDecayTransaction = (
|
||||
userId: -1,
|
||||
previous: -1,
|
||||
typeId: TransactionTypeId.DECAY,
|
||||
amount: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query
|
||||
amount: decay.decay ? decay.roundedDecay : new Decimal(0),
|
||||
balance: decay.balance
|
||||
.minus(holdAvailabeAmount.toString())
|
||||
.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
||||
balanceDate: time,
|
||||
decay: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0),
|
||||
decay: decay.decay ? decay.roundedDecay : new Decimal(0),
|
||||
decayStart: decay.start,
|
||||
memo: '',
|
||||
creationDate: null,
|
||||
|
||||
@ -30,10 +30,3 @@ yarn dev_down
|
||||
yarn dev_reset
|
||||
```
|
||||
Runs all down migrations and after this all up migrations.
|
||||
|
||||
|
||||
## Reset DB
|
||||
```
|
||||
yarn dev_reset
|
||||
```
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
<b-col cols="7">
|
||||
<div>
|
||||
{{ previousBookedBalance | GDD }}
|
||||
{{ decay === '0' ? $t('math.minus') : '' }}
|
||||
{{ decay | GDD }} {{ $t('math.equal') }}
|
||||
<b>{{ balance | GDD }}</b>
|
||||
</div>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
const pkg = require('../../package')
|
||||
|
||||
const constants = {
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
CONFIG_VERSION: {
|
||||
DEFAULT: 'DEFAULT',
|
||||
EXPECTED: 'v1.2022-03-18',
|
||||
|
||||
@ -47,12 +47,9 @@ export const transactionsQuery = gql`
|
||||
transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
|
||||
balance {
|
||||
balance
|
||||
decay
|
||||
lastBookedBalance
|
||||
balanceGDT
|
||||
count
|
||||
linkCount
|
||||
lastBookedDate
|
||||
}
|
||||
transactions {
|
||||
id
|
||||
|
||||
@ -53,11 +53,9 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
logo: 'img/brand/green.png',
|
||||
balance: 0,
|
||||
GdtBalance: 0,
|
||||
transactions: [],
|
||||
bookedBalance: 0,
|
||||
transactionCount: 0,
|
||||
transactionLinkCount: 0,
|
||||
pending: true,
|
||||
|
||||
@ -147,6 +147,7 @@
|
||||
"aprox": "~",
|
||||
"equal": "=",
|
||||
"exclaim": "!",
|
||||
"minus": "−",
|
||||
"pipe": "|"
|
||||
},
|
||||
"navigation": {
|
||||
|
||||
@ -147,6 +147,7 @@
|
||||
"aprox": "~",
|
||||
"equal": "=",
|
||||
"exclaim": "!",
|
||||
"minus": "−",
|
||||
"pipe": "|"
|
||||
},
|
||||
"navigation": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user