mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
change datatype for timestamps to string
This commit is contained in:
parent
ef0db3cb02
commit
dba6a1b8d6
4712
backend/package-lock.json
generated
4712
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,17 +25,19 @@ export class Decay {
|
||||
@Field(() => Number)
|
||||
balance: number
|
||||
|
||||
// timestamp in seconds
|
||||
@Field(() => Int, { nullable: true })
|
||||
decayStart: number
|
||||
decayStart: string
|
||||
|
||||
// timestamp in seconds
|
||||
@Field(() => Int, { nullable: true })
|
||||
decayEnd: number
|
||||
decayEnd: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
decayDuration?: number
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
decayStartBlock?: number
|
||||
decayStartBlock?: string
|
||||
|
||||
static decayStartBlockTransaction: Transaction | undefined
|
||||
}
|
||||
|
||||
@ -10,22 +10,11 @@ import { Decay } from './Decay'
|
||||
|
||||
@ObjectType()
|
||||
export class Transaction {
|
||||
constructor()
|
||||
constructor(json: any)
|
||||
constructor(json?: any) {
|
||||
if (json) {
|
||||
this.type = json.type
|
||||
this.balance = Number(json.balance)
|
||||
this.decayStart = json.decay_start
|
||||
this.decayEnd = json.decay_end
|
||||
|
||||
this.memo = json.memo
|
||||
this.transactionId = json.transaction_id
|
||||
this.name = json.name
|
||||
this.email = json.email
|
||||
this.date = json.date
|
||||
this.decay = json.decay ? new Decay(json.decay) : undefined
|
||||
}
|
||||
constructor() {
|
||||
this.type = ''
|
||||
this.balance = 0
|
||||
this.totalBalance = 0
|
||||
this.memo = ''
|
||||
}
|
||||
|
||||
@Field(() => String)
|
||||
@ -38,10 +27,10 @@ export class Transaction {
|
||||
totalBalance: number
|
||||
|
||||
@Field({ nullable: true })
|
||||
decayStart?: number
|
||||
decayStart?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
decayEnd?: number
|
||||
decayEnd?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
decayDuration?: number
|
||||
@ -67,15 +56,12 @@ export class Transaction {
|
||||
|
||||
@ObjectType()
|
||||
export class TransactionList {
|
||||
constructor(json: any) {
|
||||
this.gdtSum = Number(json.gdtSum)
|
||||
this.count = json.count
|
||||
this.balance = Number(json.balance)
|
||||
this.decay = Number(json.decay)
|
||||
this.decayDate = json.decay_date
|
||||
this.transactions = json.transactions.map((el: any) => {
|
||||
return new Transaction(el)
|
||||
})
|
||||
constructor() {
|
||||
this.gdtSum = 0
|
||||
this.count = 0
|
||||
this.balance = 0
|
||||
this.decay = 0
|
||||
this.decayDate = ''
|
||||
}
|
||||
|
||||
@Field(() => Number)
|
||||
|
||||
@ -46,7 +46,6 @@ export class TransactionResolver {
|
||||
)
|
||||
transactions.decayDate = now.toString()
|
||||
}
|
||||
|
||||
return transactions
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,9 @@ async function calculateAndAddDecayTransactions(
|
||||
prev.transactionId < decayStartTransaction.id &&
|
||||
current.transactionId > decayStartTransaction.id
|
||||
) {
|
||||
finalTransaction.decay.decayStartBlock = decayStartTransaction.received.getTime()
|
||||
finalTransaction.decay.decayStartBlock = (
|
||||
decayStartTransaction.received.getTime() / 1000
|
||||
).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,14 +183,8 @@ export default async function listTransactions(
|
||||
}
|
||||
}
|
||||
|
||||
const transactionList = new TransactionList({
|
||||
gdtSum: 0,
|
||||
count: userTransactionsCount,
|
||||
balance: 0,
|
||||
decay: 0,
|
||||
decay_date: '',
|
||||
transactions: transactions,
|
||||
})
|
||||
|
||||
const transactionList = new TransactionList()
|
||||
transactionList.count = userTransactionsCount
|
||||
transactionList.transactions = transactions
|
||||
return transactionList
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export class UserTransaction extends BaseEntity {
|
||||
balance: number
|
||||
|
||||
@Column({ name: 'balance_date', type: 'timestamp' })
|
||||
balanceDate: number
|
||||
balanceDate: Date
|
||||
|
||||
static findByUserPaged(
|
||||
userId: number,
|
||||
|
||||
@ -17,29 +17,31 @@ async function calculateDecay(amount: number, from: Date, to: Date): Promise<num
|
||||
|
||||
async function calculateDecayWithInterval(
|
||||
amount: number,
|
||||
from: number,
|
||||
to: number,
|
||||
from: number | Date,
|
||||
to: number | Date,
|
||||
): Promise<Decay> {
|
||||
const decayStartBlock = await Decay.getDecayStartBlock()
|
||||
const result = new Decay(undefined)
|
||||
result.balance = amount
|
||||
result.decayStart = from
|
||||
result.decayEnd = from
|
||||
const fromMillis = typeof from === 'number' ? from : from.getTime()
|
||||
const toMillis = typeof to === 'number' ? to : to.getTime()
|
||||
result.decayStart = (fromMillis / 1000).toString()
|
||||
result.decayEnd = (toMillis / 1000).toString()
|
||||
|
||||
// (amount, from.getTime(), to.getTime())
|
||||
|
||||
// if no decay start block exist or decay startet after end date
|
||||
if (decayStartBlock === undefined || decayStartBlock.received.getTime() > to) {
|
||||
if (decayStartBlock === undefined || decayStartBlock.received.getTime() > toMillis) {
|
||||
return result
|
||||
}
|
||||
|
||||
// if decay start date is before start date we calculate decay for full duration
|
||||
if (decayStartBlock.received.getTime() < from) {
|
||||
result.decayDuration = to - from
|
||||
if (decayStartBlock.received.getTime() < fromMillis) {
|
||||
result.decayDuration = toMillis - fromMillis
|
||||
}
|
||||
// if decay start in between start date and end date we caculcate decay from decay start time to end date
|
||||
else {
|
||||
result.decayDuration = to - decayStartBlock.received.getTime()
|
||||
result.decayDuration = toMillis - decayStartBlock.received.getTime()
|
||||
}
|
||||
// js use timestamp in milliseconds but we calculate with seconds
|
||||
result.decayDuration /= 1000
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user