mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2923 from gradido/refactor-get-transaction-list
refactor(backend): get transaction list
This commit is contained in:
commit
18b0cb99b3
@ -16,7 +16,6 @@ import { TransactionTypeId } from '@enum/TransactionTypeId'
|
|||||||
import { Transaction } from '@model/Transaction'
|
import { Transaction } from '@model/Transaction'
|
||||||
import { TransactionList } from '@model/TransactionList'
|
import { TransactionList } from '@model/TransactionList'
|
||||||
import { User } from '@model/User'
|
import { User } from '@model/User'
|
||||||
import { TransactionRepository } from '@repository/Transaction'
|
|
||||||
import { TransactionLinkRepository } from '@repository/TransactionLink'
|
import { TransactionLinkRepository } from '@repository/TransactionLink'
|
||||||
|
|
||||||
import { RIGHTS } from '@/auth/RIGHTS'
|
import { RIGHTS } from '@/auth/RIGHTS'
|
||||||
@ -37,6 +36,7 @@ import { BalanceResolver } from './BalanceResolver'
|
|||||||
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
||||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||||
import { getLastTransaction } from './util/getLastTransaction'
|
import { getLastTransaction } from './util/getLastTransaction'
|
||||||
|
import { getTransactionList } from './util/getTransactionList'
|
||||||
|
|
||||||
export const executeTransaction = async (
|
export const executeTransaction = async (
|
||||||
amount: Decimal,
|
amount: Decimal,
|
||||||
@ -209,8 +209,7 @@ export class TransactionResolver {
|
|||||||
// find transactions
|
// find transactions
|
||||||
// first page can contain 26 due to virtual decay transaction
|
// first page can contain 26 due to virtual decay transaction
|
||||||
const offset = (currentPage - 1) * pageSize
|
const offset = (currentPage - 1) * pageSize
|
||||||
const transactionRepository = getCustomRepository(TransactionRepository)
|
const [userTransactions, userTransactionsCount] = await getTransactionList(
|
||||||
const [userTransactions, userTransactionsCount] = await transactionRepository.findByUserPaged(
|
|
||||||
user.id,
|
user.id,
|
||||||
pageSize,
|
pageSize,
|
||||||
offset,
|
offset,
|
||||||
@ -283,7 +282,7 @@ export class TransactionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// transactions
|
// transactions
|
||||||
userTransactions.forEach((userTransaction) => {
|
userTransactions.forEach((userTransaction: dbTransaction) => {
|
||||||
const linkedUser =
|
const linkedUser =
|
||||||
userTransaction.typeId === TransactionTypeId.CREATION
|
userTransaction.typeId === TransactionTypeId.CREATION
|
||||||
? communityUser
|
? communityUser
|
||||||
|
|||||||
20
backend/src/graphql/resolver/util/getTransactionList.ts
Normal file
20
backend/src/graphql/resolver/util/getTransactionList.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||||
|
|
||||||
|
import { Order } from '@enum/Order'
|
||||||
|
|
||||||
|
export const getTransactionList = async (
|
||||||
|
userId: number,
|
||||||
|
limit: number,
|
||||||
|
offset: number,
|
||||||
|
order: Order,
|
||||||
|
): Promise<[DbTransaction[], number]> => {
|
||||||
|
return DbTransaction.findAndCount({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
order: { balanceDate: order, id: order },
|
||||||
|
relations: ['previousTransaction'],
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import { EntityRepository, Repository } from '@dbTools/typeorm'
|
|
||||||
import { Transaction } from '@entity/Transaction'
|
|
||||||
|
|
||||||
import { Order } from '@enum/Order'
|
|
||||||
|
|
||||||
@EntityRepository(Transaction)
|
|
||||||
export class TransactionRepository extends Repository<Transaction> {
|
|
||||||
findByUserPaged(
|
|
||||||
userId: number,
|
|
||||||
limit: number,
|
|
||||||
offset: number,
|
|
||||||
order: Order,
|
|
||||||
): Promise<[Transaction[], number]> {
|
|
||||||
const query = this.createQueryBuilder('userTransaction')
|
|
||||||
.leftJoinAndSelect(
|
|
||||||
'userTransaction.previousTransaction',
|
|
||||||
'transaction',
|
|
||||||
'userTransaction.previous = transaction.id',
|
|
||||||
)
|
|
||||||
.where('userTransaction.userId = :userId', { userId })
|
|
||||||
|
|
||||||
return query
|
|
||||||
.orderBy('userTransaction.balanceDate', order)
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset)
|
|
||||||
.getManyAndCount()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user