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 {
|
export class Balance {
|
||||||
constructor(data: {
|
constructor(data: {
|
||||||
balance: Decimal
|
balance: Decimal
|
||||||
decay: Decimal
|
|
||||||
lastBookedBalance: Decimal
|
|
||||||
balanceGDT: number | null
|
balanceGDT: number | null
|
||||||
count: number
|
count: number
|
||||||
linkCount: number
|
linkCount: number
|
||||||
lastBookedDate?: Date | null
|
|
||||||
}) {
|
}) {
|
||||||
this.balance = data.balance
|
this.balance = data.balance
|
||||||
this.decay = data.decay
|
|
||||||
this.lastBookedBalance = data.lastBookedBalance
|
|
||||||
this.balanceGDT = data.balanceGDT || null
|
this.balanceGDT = data.balanceGDT || null
|
||||||
this.count = data.count
|
this.count = data.count
|
||||||
this.linkCount = data.linkCount
|
this.linkCount = data.linkCount
|
||||||
this.lastBookedDate = data.lastBookedDate || null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the actual balance, decay included
|
// the actual balance, decay included
|
||||||
@Field(() => Decimal)
|
@Field(() => Decimal)
|
||||||
balance: Decimal
|
balance: Decimal
|
||||||
|
|
||||||
// the decay since the last booked balance
|
|
||||||
@Field(() => Decimal)
|
|
||||||
decay: Decimal
|
|
||||||
|
|
||||||
@Field(() => Decimal)
|
|
||||||
lastBookedBalance: Decimal
|
|
||||||
|
|
||||||
@Field(() => Number, { nullable: true })
|
@Field(() => Number, { nullable: true })
|
||||||
balanceGDT: number | null
|
balanceGDT: number | null
|
||||||
|
|
||||||
@ -42,8 +29,4 @@ export class Balance {
|
|||||||
// the count of transaction links
|
// the count of transaction links
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
linkCount: 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 { ObjectType, Field, Int } from 'type-graphql'
|
||||||
import Decimal from 'decimal.js-light'
|
import Decimal from 'decimal.js-light'
|
||||||
|
|
||||||
|
interface DecayInterface {
|
||||||
|
balance: Decimal
|
||||||
|
decay: Decimal
|
||||||
|
roundedDecay: Decimal
|
||||||
|
start: Date | null
|
||||||
|
end: Date | null
|
||||||
|
duration: number | null
|
||||||
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Decay {
|
export class Decay {
|
||||||
constructor(
|
constructor({ balance, decay, roundedDecay, start, end, duration }: DecayInterface) {
|
||||||
balance: Decimal,
|
|
||||||
decay: Decimal,
|
|
||||||
start: Date | null,
|
|
||||||
end: Date | null,
|
|
||||||
duration: number | null,
|
|
||||||
) {
|
|
||||||
this.balance = balance
|
this.balance = balance
|
||||||
this.decay = decay
|
this.decay = decay
|
||||||
|
this.roundedDecay = roundedDecay
|
||||||
this.start = start
|
this.start = start
|
||||||
this.end = end
|
this.end = end
|
||||||
this.duration = duration
|
this.duration = duration
|
||||||
@ -23,6 +27,9 @@ export class Decay {
|
|||||||
@Field(() => Decimal)
|
@Field(() => Decimal)
|
||||||
decay: Decimal
|
decay: Decimal
|
||||||
|
|
||||||
|
@Field(() => Decimal)
|
||||||
|
roundedDecay: Decimal
|
||||||
|
|
||||||
@Field(() => Date, { nullable: true })
|
@Field(() => Date, { nullable: true })
|
||||||
start: Date | null
|
start: Date | null
|
||||||
|
|
||||||
|
|||||||
@ -17,21 +17,26 @@ export class Transaction {
|
|||||||
this.balanceDate = transaction.balanceDate
|
this.balanceDate = transaction.balanceDate
|
||||||
if (!transaction.decayStart) {
|
if (!transaction.decayStart) {
|
||||||
// TODO: hot fix, we should separate decay calculation from decay graphql model
|
// TODO: hot fix, we should separate decay calculation from decay graphql model
|
||||||
this.decay = new Decay(
|
this.decay = new Decay({
|
||||||
transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
||||||
new Decimal(0),
|
decay: new Decimal(0),
|
||||||
null,
|
roundedDecay: new Decimal(0),
|
||||||
null,
|
start: null,
|
||||||
null,
|
end: null,
|
||||||
)
|
duration: null,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.decay = new Decay(
|
this.decay = new Decay({
|
||||||
transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
||||||
transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR),
|
decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR),
|
||||||
transaction.decayStart,
|
// TODO: add correct value when decay must be rounded in transaction context
|
||||||
transaction.balanceDate,
|
roundedDecay: new Decimal(0),
|
||||||
Math.round((transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000),
|
start: transaction.decayStart,
|
||||||
)
|
end: transaction.balanceDate,
|
||||||
|
duration: Math.round(
|
||||||
|
(transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000,
|
||||||
|
),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
this.memo = transaction.memo
|
this.memo = transaction.memo
|
||||||
this.creationDate = transaction.creationDate
|
this.creationDate = transaction.creationDate
|
||||||
|
|||||||
@ -29,8 +29,6 @@ export class BalanceResolver {
|
|||||||
if (!lastTransaction) {
|
if (!lastTransaction) {
|
||||||
return new Balance({
|
return new Balance({
|
||||||
balance: new Decimal(0),
|
balance: new Decimal(0),
|
||||||
decay: new Decimal(0),
|
|
||||||
lastBookedBalance: new Decimal(0),
|
|
||||||
balanceGDT,
|
balanceGDT,
|
||||||
count: 0,
|
count: 0,
|
||||||
linkCount: 0,
|
linkCount: 0,
|
||||||
@ -69,12 +67,9 @@ export class BalanceResolver {
|
|||||||
balance: calculatedDecay.balance
|
balance: calculatedDecay.balance
|
||||||
.minus(sumHoldAvailableAmount.toString())
|
.minus(sumHoldAvailableAmount.toString())
|
||||||
.toDecimalPlaces(2, Decimal.ROUND_DOWN), // round towards zero
|
.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,
|
balanceGDT,
|
||||||
count,
|
count,
|
||||||
linkCount,
|
linkCount,
|
||||||
lastBookedDate: lastTransaction.balanceDate,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ function calculateDecay(
|
|||||||
const decay: Decay = {
|
const decay: Decay = {
|
||||||
balance: amount,
|
balance: amount,
|
||||||
decay: new Decimal(0),
|
decay: new Decimal(0),
|
||||||
|
roundedDecay: new Decimal(0),
|
||||||
start: null,
|
start: null,
|
||||||
end: null,
|
end: null,
|
||||||
duration: null,
|
duration: null,
|
||||||
@ -52,6 +53,10 @@ function calculateDecay(
|
|||||||
decay.end = to
|
decay.end = to
|
||||||
decay.balance = decayFormula(amount, decay.duration)
|
decay.balance = decayFormula(amount, decay.duration)
|
||||||
decay.decay = decay.balance.minus(amount)
|
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
|
return decay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,12 +68,12 @@ const virtualDecayTransaction = (
|
|||||||
userId: -1,
|
userId: -1,
|
||||||
previous: -1,
|
previous: -1,
|
||||||
typeId: TransactionTypeId.DECAY,
|
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
|
balance: decay.balance
|
||||||
.minus(holdAvailabeAmount.toString())
|
.minus(holdAvailabeAmount.toString())
|
||||||
.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
||||||
balanceDate: time,
|
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,
|
decayStart: decay.start,
|
||||||
memo: '',
|
memo: '',
|
||||||
creationDate: null,
|
creationDate: null,
|
||||||
|
|||||||
@ -30,10 +30,3 @@ yarn dev_down
|
|||||||
yarn dev_reset
|
yarn dev_reset
|
||||||
```
|
```
|
||||||
Runs all down migrations and after this all up migrations.
|
Runs all down migrations and after this all up migrations.
|
||||||
|
|
||||||
|
|
||||||
## Reset DB
|
|
||||||
```
|
|
||||||
yarn dev_reset
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
<b-col cols="7">
|
<b-col cols="7">
|
||||||
<div>
|
<div>
|
||||||
{{ previousBookedBalance | GDD }}
|
{{ previousBookedBalance | GDD }}
|
||||||
|
{{ decay === '0' ? $t('math.minus') : '' }}
|
||||||
{{ decay | GDD }} {{ $t('math.equal') }}
|
{{ decay | GDD }} {{ $t('math.equal') }}
|
||||||
<b>{{ balance | GDD }}</b>
|
<b>{{ balance | GDD }}</b>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
const pkg = require('../../package')
|
const pkg = require('../../package')
|
||||||
|
|
||||||
const constants = {
|
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: {
|
CONFIG_VERSION: {
|
||||||
DEFAULT: 'DEFAULT',
|
DEFAULT: 'DEFAULT',
|
||||||
EXPECTED: 'v1.2022-03-18',
|
EXPECTED: 'v1.2022-03-18',
|
||||||
|
|||||||
@ -47,12 +47,9 @@ export const transactionsQuery = gql`
|
|||||||
transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
|
transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
|
||||||
balance {
|
balance {
|
||||||
balance
|
balance
|
||||||
decay
|
|
||||||
lastBookedBalance
|
|
||||||
balanceGDT
|
balanceGDT
|
||||||
count
|
count
|
||||||
linkCount
|
linkCount
|
||||||
lastBookedDate
|
|
||||||
}
|
}
|
||||||
transactions {
|
transactions {
|
||||||
id
|
id
|
||||||
|
|||||||
@ -53,11 +53,9 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
logo: 'img/brand/green.png',
|
|
||||||
balance: 0,
|
balance: 0,
|
||||||
GdtBalance: 0,
|
GdtBalance: 0,
|
||||||
transactions: [],
|
transactions: [],
|
||||||
bookedBalance: 0,
|
|
||||||
transactionCount: 0,
|
transactionCount: 0,
|
||||||
transactionLinkCount: 0,
|
transactionLinkCount: 0,
|
||||||
pending: true,
|
pending: true,
|
||||||
|
|||||||
@ -147,6 +147,7 @@
|
|||||||
"aprox": "~",
|
"aprox": "~",
|
||||||
"equal": "=",
|
"equal": "=",
|
||||||
"exclaim": "!",
|
"exclaim": "!",
|
||||||
|
"minus": "−",
|
||||||
"pipe": "|"
|
"pipe": "|"
|
||||||
},
|
},
|
||||||
"navigation": {
|
"navigation": {
|
||||||
|
|||||||
@ -147,6 +147,7 @@
|
|||||||
"aprox": "~",
|
"aprox": "~",
|
||||||
"equal": "=",
|
"equal": "=",
|
||||||
"exclaim": "!",
|
"exclaim": "!",
|
||||||
|
"minus": "−",
|
||||||
"pipe": "|"
|
"pipe": "|"
|
||||||
},
|
},
|
||||||
"navigation": {
|
"navigation": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user