default values for filters

This commit is contained in:
Moriz Wahl 2022-03-23 08:20:37 +01:00
parent d0b2a28ae2
commit d1770ccb1a
2 changed files with 7 additions and 7 deletions

View File

@ -2,12 +2,12 @@ import { ArgsType, Field } from 'type-graphql'
@ArgsType()
export default class TransactionLinkFilters {
@Field(() => Boolean, { nullable: true })
@Field(() => Boolean, { nullable: true, defaultValue: true })
withDeleted?: boolean
@Field(() => Boolean, { nullable: true })
@Field(() => Boolean, { nullable: true, defaultValue: true })
withExpired?: boolean
@Field(() => Boolean, { nullable: true })
@Field(() => Boolean, { nullable: true, defaultValue: true })
withRedeemed?: boolean
}

View File

@ -381,7 +381,7 @@ export class AdminResolver {
@Args()
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
@Args()
{ withDeleted = true, withExpired = true, withRedeemed = true }: TransactionLinkFilters,
filters: TransactionLinkFilters,
@Arg('userId', () => Int) userId: number,
): Promise<TransactionLink[]> {
const user = await dbUser.findOneOrFail({ id: userId })
@ -392,11 +392,11 @@ export class AdminResolver {
} = {
userId,
}
if (!withRedeemed) where.redeemedBy = null
if (!withExpired) where.validUntil = MoreThan(new Date())
if (!filters.withRedeemed) where.redeemedBy = null
if (!filters.withExpired) where.validUntil = MoreThan(new Date())
const transactionLinks = await dbTransactionLink.find({
where,
withDeleted,
withDeleted: filters.withDeleted,
order: {
createdAt: order,
},