mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
get previuos transaction from database
This commit is contained in:
parent
95303c30e0
commit
1fdd2e1014
@ -9,12 +9,7 @@ import { User } from './User'
|
|||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Transaction {
|
export class Transaction {
|
||||||
constructor(
|
constructor(transaction: dbTransaction, user: User, linkedUser: User | null = null) {
|
||||||
transaction: dbTransaction,
|
|
||||||
user: User,
|
|
||||||
linkedUser: User | null = null,
|
|
||||||
previuosBalance: Decimal = new Decimal(0),
|
|
||||||
) {
|
|
||||||
this.id = transaction.id
|
this.id = transaction.id
|
||||||
this.user = user
|
this.user = user
|
||||||
this.previous = transaction.previous
|
this.previous = transaction.previous
|
||||||
@ -52,7 +47,10 @@ export class Transaction {
|
|||||||
this.linkId = transaction.contribution
|
this.linkId = transaction.contribution
|
||||||
? transaction.contribution.contributionLinkId
|
? transaction.contribution.contributionLinkId
|
||||||
: transaction.transactionLinkId || null
|
: transaction.transactionLinkId || null
|
||||||
this.previousBalance = previuosBalance.toDecimalPlaces(2, Decimal.ROUND_DOWN)
|
this.previousBalance =
|
||||||
|
(transaction.previousTransaction &&
|
||||||
|
transaction.previousTransaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN)) ||
|
||||||
|
new Decimal(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Field(() => Int)
|
@Field(() => Int)
|
||||||
|
|||||||
@ -286,14 +286,12 @@ export class TransactionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// transactions
|
// transactions
|
||||||
userTransactions.forEach((userTransaction, idx) => {
|
userTransactions.forEach((userTransaction) => {
|
||||||
const linkedUser =
|
const linkedUser =
|
||||||
userTransaction.typeId === TransactionTypeId.CREATION
|
userTransaction.typeId === TransactionTypeId.CREATION
|
||||||
? communityUser
|
? communityUser
|
||||||
: involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
|
: involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
|
||||||
const previousBalance =
|
transactions.push(new Transaction(userTransaction, self, linkedUser))
|
||||||
idx < userTransactions.length - 1 ? userTransactions[idx + 1].balance : new Decimal(0)
|
|
||||||
transactions.push(new Transaction(userTransaction, self, linkedUser, previousBalance))
|
|
||||||
})
|
})
|
||||||
logger.debug(`TransactionTypeId.CREATION: transactions=${transactions}`)
|
logger.debug(`TransactionTypeId.CREATION: transactions=${transactions}`)
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { EntityRepository, Repository } from '@dbTools/typeorm'
|
|||||||
import { Transaction } from '@entity/Transaction'
|
import { Transaction } from '@entity/Transaction'
|
||||||
|
|
||||||
import { Order } from '@enum/Order'
|
import { Order } from '@enum/Order'
|
||||||
import { TransactionTypeId } from '@enum/TransactionTypeId'
|
|
||||||
|
|
||||||
@EntityRepository(Transaction)
|
@EntityRepository(Transaction)
|
||||||
export class TransactionRepository extends Repository<Transaction> {
|
export class TransactionRepository extends Repository<Transaction> {
|
||||||
@ -11,22 +10,15 @@ export class TransactionRepository extends Repository<Transaction> {
|
|||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
order: Order,
|
order: Order,
|
||||||
onlyCreation?: boolean,
|
|
||||||
): Promise<[Transaction[], number]> {
|
): Promise<[Transaction[], number]> {
|
||||||
const query = this.createQueryBuilder('userTransaction')
|
const query = this.createQueryBuilder('userTransaction')
|
||||||
.leftJoinAndSelect(
|
.leftJoinAndSelect(
|
||||||
'userTransaction.contribution',
|
'userTransaction.previousTransaction',
|
||||||
'contribution',
|
'transaction',
|
||||||
'userTransaction.id = contribution.transactionId',
|
'userTransaction.previous = transaction.id',
|
||||||
)
|
)
|
||||||
.where('userTransaction.userId = :userId', { userId })
|
.where('userTransaction.userId = :userId', { userId })
|
||||||
|
|
||||||
if (onlyCreation) {
|
|
||||||
query.andWhere('userTransaction.typeId = :typeId', {
|
|
||||||
typeId: TransactionTypeId.CREATION,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return query
|
return query
|
||||||
.orderBy('userTransaction.balanceDate', order)
|
.orderBy('userTransaction.balanceDate', order)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|||||||
@ -55,12 +55,7 @@ const virtualLinkTransaction = (
|
|||||||
contribution: null,
|
contribution: null,
|
||||||
...defaultModelFunctions,
|
...defaultModelFunctions,
|
||||||
}
|
}
|
||||||
return new Transaction(
|
return new Transaction(linkDbTransaction, user)
|
||||||
linkDbTransaction,
|
|
||||||
user,
|
|
||||||
null,
|
|
||||||
previousBalance.toDecimalPlaces(2, Decimal.ROUND_DOWN),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const virtualDecayTransaction = (
|
const virtualDecayTransaction = (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user