mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix what don't work
This commit is contained in:
parent
06c80ebdfd
commit
0d33202946
@ -5,8 +5,7 @@ import { Transaction } from '../../typeorm/entity/Transaction'
|
|||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Decay {
|
export class Decay {
|
||||||
constructor()
|
constructor(json: any) {
|
||||||
constructor(json?: any) {
|
|
||||||
if (json) {
|
if (json) {
|
||||||
this.balance = Number(json.balance)
|
this.balance = Number(json.balance)
|
||||||
this.decayStart = json.decay_start
|
this.decayStart = json.decay_start
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export class Transaction {
|
|||||||
this.balance = Number(json.balance)
|
this.balance = Number(json.balance)
|
||||||
this.decayStart = json.decay_start
|
this.decayStart = json.decay_start
|
||||||
this.decayEnd = json.decay_end
|
this.decayEnd = json.decay_end
|
||||||
this.decayDuration = parseFloat(json.decay_duration)
|
|
||||||
this.memo = json.memo
|
this.memo = json.memo
|
||||||
this.transactionId = json.transaction_id
|
this.transactionId = json.transaction_id
|
||||||
this.name = json.name
|
this.name = json.name
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { Balance } from '../models/Balance'
|
|||||||
import { apiGet } from '../../apis/HttpRequest'
|
import { apiGet } from '../../apis/HttpRequest'
|
||||||
import { User as dbUser } from '../../typeorm/entity/User'
|
import { User as dbUser } from '../../typeorm/entity/User'
|
||||||
import { Balance as dbBalance } from '../../typeorm/entity/Balance'
|
import { Balance as dbBalance } from '../../typeorm/entity/Balance'
|
||||||
import calculateDecay from '../../util/decay'
|
import { calculateDecay } from '../../util/decay'
|
||||||
import { roundFloorFrom4 } from '../../util/round'
|
import { roundFloorFrom4 } from '../../util/round'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import { User as dbUser } from '../../typeorm/entity/User'
|
|||||||
import { Balance as dbBalance } from '../../typeorm/entity/Balance'
|
import { Balance as dbBalance } from '../../typeorm/entity/Balance'
|
||||||
import listTransactions from './listTransactions'
|
import listTransactions from './listTransactions'
|
||||||
import { roundFloorFrom4 } from '../../util/round'
|
import { roundFloorFrom4 } from '../../util/round'
|
||||||
import calculateDecay from '../../util/decay'
|
import { calculateDecay } from '../../util/decay'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class TransactionResolver {
|
export class TransactionResolver {
|
||||||
@ -41,7 +41,7 @@ export class TransactionResolver {
|
|||||||
const now = new Date()
|
const now = new Date()
|
||||||
transactions.balance = roundFloorFrom4(balanceEntity.amount)
|
transactions.balance = roundFloorFrom4(balanceEntity.amount)
|
||||||
transactions.decay = roundFloorFrom4(
|
transactions.decay = roundFloorFrom4(
|
||||||
calculateDecay(balanceEntity.amount, balanceEntity.recordDate, now),
|
await calculateDecay(balanceEntity.amount, balanceEntity.recordDate, now),
|
||||||
)
|
)
|
||||||
transactions.decayDate = now.toString()
|
transactions.decayDate = now.toString()
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ async function calculateAndAddDecayTransactions(
|
|||||||
decay: boolean,
|
decay: boolean,
|
||||||
skipFirstTransaction: boolean,
|
skipFirstTransaction: boolean,
|
||||||
): Promise<Transaction[]> {
|
): Promise<Transaction[]> {
|
||||||
const finalTransactions: Transaction[] = []
|
let finalTransactions: Transaction[] = []
|
||||||
const transactionIds: number[] = []
|
const transactionIds: number[] = []
|
||||||
const involvedUserIds: number[] = []
|
const involvedUserIds: number[] = []
|
||||||
|
|
||||||
@ -29,14 +29,14 @@ async function calculateAndAddDecayTransactions(
|
|||||||
.createQueryBuilder('transaction')
|
.createQueryBuilder('transaction')
|
||||||
.where('transaction.id IN (:...transactions)', { transactions: transactionIds })
|
.where('transaction.id IN (:...transactions)', { transactions: transactionIds })
|
||||||
.leftJoinAndSelect(
|
.leftJoinAndSelect(
|
||||||
'transaction.sendCoin',
|
'transaction.transactionSendCoin',
|
||||||
'transactionSendCoin',
|
'transactionSendCoin'
|
||||||
'transactionSendCoin.transactionid = transaction.id',
|
//'transactionSendCoin.transaction_id = transaction.id',
|
||||||
)
|
)
|
||||||
.leftJoinAndSelect(
|
.leftJoinAndSelect(
|
||||||
'transaction.creation',
|
'transaction.transactionCreation',
|
||||||
'transactionCreation',
|
'transactionCreation'
|
||||||
'transactionSendCoin.transactionid = transaction.id',
|
//'transactionSendCoin.transaction_id = transaction.id',
|
||||||
)
|
)
|
||||||
.getMany()
|
.getMany()
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ async function calculateAndAddDecayTransactions(
|
|||||||
|
|
||||||
const decayStartTransaction = await Decay.getDecayStartBlock()
|
const decayStartTransaction = await Decay.getDecayStartBlock()
|
||||||
|
|
||||||
userTransactions.forEach(async (userTransaction: dbUserTransaction, i: number) => {
|
await userTransactions.forEach(async (userTransaction: dbUserTransaction, i: number) => {
|
||||||
const transaction = transactionIndiced[userTransaction.transactionId]
|
const transaction = transactionIndiced[userTransaction.transactionId]
|
||||||
const finalTransaction = new Transaction()
|
const finalTransaction = new Transaction()
|
||||||
finalTransaction.transactionId = transaction.id
|
finalTransaction.transactionId = transaction.id
|
||||||
@ -117,6 +117,7 @@ async function calculateAndAddDecayTransactions(
|
|||||||
if (i > 0 || !skipFirstTransaction) {
|
if (i > 0 || !skipFirstTransaction) {
|
||||||
finalTransactions.push(finalTransaction)
|
finalTransactions.push(finalTransaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i === userTransactions.length - 1 && decay) {
|
if (i === userTransactions.length - 1 && decay) {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const decay = await calculateDecayWithInterval(
|
const decay = await calculateDecayWithInterval(
|
||||||
@ -135,7 +136,6 @@ async function calculateAndAddDecayTransactions(
|
|||||||
finalTransactions.push(decayTransaction)
|
finalTransactions.push(decayTransaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return finalTransactions
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return finalTransactions
|
return finalTransactions
|
||||||
|
|||||||
@ -27,6 +27,6 @@ export class TransactionCreation extends BaseEntity {
|
|||||||
targetDate: Timestamp
|
targetDate: Timestamp
|
||||||
|
|
||||||
@OneToOne(() => Transaction)
|
@OneToOne(() => Transaction)
|
||||||
@JoinColumn()
|
@JoinColumn({ name: 'transaction_id' })
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,6 @@ export class TransactionSendCoin extends BaseEntity {
|
|||||||
amount: number
|
amount: number
|
||||||
|
|
||||||
@OneToOne(() => Transaction)
|
@OneToOne(() => Transaction)
|
||||||
@JoinColumn()
|
@JoinColumn({ name: 'transaction_id' })
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ async function calculateDecayWithInterval(
|
|||||||
to: number,
|
to: number,
|
||||||
): Promise<Decay> {
|
): Promise<Decay> {
|
||||||
const decayStartBlock = await Decay.getDecayStartBlock()
|
const decayStartBlock = await Decay.getDecayStartBlock()
|
||||||
const result = new Decay()
|
const result = new Decay(undefined)
|
||||||
result.balance = amount
|
result.balance = amount
|
||||||
result.decayStart = from
|
result.decayStart = from
|
||||||
result.decayEnd = from
|
result.decayEnd = from
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user