mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add linkCount and linkList in query
This commit is contained in:
parent
9332f81187
commit
549a36cb56
@ -1,4 +1,4 @@
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
import { ObjectType, Field, Int } from 'type-graphql'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
|
||||
import { User } from './User'
|
||||
@ -52,3 +52,12 @@ export class TransactionLink {
|
||||
@Field(() => User, { nullable: true })
|
||||
redeemedBy: User | null
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TransactionLinkResult {
|
||||
@Field(() => Int)
|
||||
linkCount: number
|
||||
|
||||
@Field(() => [TransactionLink])
|
||||
linkList: TransactionLink[]
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import UpdatePendingCreationArgs from '@arg/UpdatePendingCreationArgs'
|
||||
import SearchUsersArgs from '@arg/SearchUsersArgs'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { Transaction } from '@model/Transaction'
|
||||
import { TransactionLink } from '@model/TransactionLink'
|
||||
import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink'
|
||||
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
|
||||
import { TransactionRepository } from '@repository/Transaction'
|
||||
import { calculateDecay } from '@/util/decay'
|
||||
@ -376,14 +376,14 @@ export class AdminResolver {
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN])
|
||||
@Query(() => [TransactionLink])
|
||||
@Query(() => TransactionLinkResult)
|
||||
async listTransactionLinksAdmin(
|
||||
@Args()
|
||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||
@Args()
|
||||
filters: TransactionLinkFilters,
|
||||
@Arg('userId', () => Int) userId: number,
|
||||
): Promise<TransactionLink[]> {
|
||||
): Promise<TransactionLinkResult> {
|
||||
const user = await dbUser.findOneOrFail({ id: userId })
|
||||
const where: {
|
||||
userId: number
|
||||
@ -394,7 +394,7 @@ export class AdminResolver {
|
||||
}
|
||||
if (!filters.withRedeemed) where.redeemedBy = null
|
||||
if (!filters.withExpired) where.validUntil = MoreThan(new Date())
|
||||
const transactionLinks = await dbTransactionLink.find({
|
||||
const [transactionLinks, count] = await dbTransactionLink.findAndCount({
|
||||
where,
|
||||
withDeleted: filters.withDeleted,
|
||||
order: {
|
||||
@ -403,7 +403,11 @@ export class AdminResolver {
|
||||
skip: (currentPage - 1) * pageSize,
|
||||
take: pageSize,
|
||||
})
|
||||
return transactionLinks.map((tl) => new TransactionLink(tl, new User(user)))
|
||||
|
||||
return {
|
||||
linkCount: count,
|
||||
linkList: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user