mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add simple filter for list transaction link admin query
This commit is contained in:
parent
3575d2d2aa
commit
d0b2a28ae2
13
backend/src/graphql/arg/TransactionLinkFilters.ts
Normal file
13
backend/src/graphql/arg/TransactionLinkFilters.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { ArgsType, Field } from 'type-graphql'
|
||||
|
||||
@ArgsType()
|
||||
export default class TransactionLinkFilters {
|
||||
@Field(() => Boolean, { nullable: true })
|
||||
withDeleted?: boolean
|
||||
|
||||
@Field(() => Boolean, { nullable: true })
|
||||
withExpired?: boolean
|
||||
|
||||
@Field(() => Boolean, { nullable: true })
|
||||
withRedeemed?: boolean
|
||||
}
|
||||
@ -9,6 +9,8 @@ import {
|
||||
ObjectLiteral,
|
||||
getConnection,
|
||||
In,
|
||||
MoreThan,
|
||||
FindOperator,
|
||||
} from '@dbTools/typeorm'
|
||||
import { UserAdmin, SearchUsersResult } from '@model/UserAdmin'
|
||||
import { PendingCreation } from '@model/PendingCreation'
|
||||
@ -34,6 +36,7 @@ import { TransactionTypeId } from '@enum/TransactionTypeId'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { Decay } from '@model/Decay'
|
||||
import Paginated from '@arg/Paginated'
|
||||
import TransactionLinkFilters from '@arg/TransactionLinkFilters'
|
||||
import { Order } from '@enum/Order'
|
||||
import { communityUser } from '@/util/communityUser'
|
||||
|
||||
@ -377,13 +380,23 @@ export class AdminResolver {
|
||||
async listTransactionLinksAdmin(
|
||||
@Args()
|
||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||
@Args()
|
||||
{ withDeleted = true, withExpired = true, withRedeemed = true }: TransactionLinkFilters,
|
||||
@Arg('userId', () => Int) userId: number,
|
||||
): Promise<TransactionLink[]> {
|
||||
const user = await dbUser.findOneOrFail({ id: userId })
|
||||
const where: {
|
||||
userId: number
|
||||
redeemedBy?: number | null
|
||||
validUntil?: FindOperator<Date> | null
|
||||
} = {
|
||||
userId,
|
||||
}
|
||||
if (!withRedeemed) where.redeemedBy = null
|
||||
if (!withExpired) where.validUntil = MoreThan(new Date())
|
||||
const transactionLinks = await dbTransactionLink.find({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
where,
|
||||
withDeleted,
|
||||
order: {
|
||||
createdAt: order,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user