From 196c3294443a208c71f21a8beada276c0191716c Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 16 Dec 2024 01:20:04 -0500 Subject: [PATCH] add filters for network and tokens for recurringdonations --- src/resolvers/recurringDonationResolver.ts | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/resolvers/recurringDonationResolver.ts b/src/resolvers/recurringDonationResolver.ts index be68e0f57..df52666d5 100644 --- a/src/resolvers/recurringDonationResolver.ts +++ b/src/resolvers/recurringDonationResolver.ts @@ -184,6 +184,9 @@ class UserRecurringDonationsArgs { @Field(_type => [String], { nullable: true, defaultValue: [] }) filteredTokens: string[]; + + @Field(_type => Int, { nullable: true }) + networkId?: number; } @ObjectType() @@ -428,6 +431,12 @@ export class RecurringDonationResolver { }, }) orderBy: RecurringDonationSortBy, + @Arg('networkId', _type => Int, { nullable: true }) networkId: number, + @Arg('filteredTokens', _type => [String], { + nullable: true, + defaultValue: [], + }) + filteredTokens: string[], ) { const project = await findProjectById(projectId); if (!project) { @@ -481,6 +490,12 @@ export class RecurringDonationResolver { }); } + if (filteredTokens && filteredTokens.length > 0) { + query.andWhere(`recurringDonation.currency IN (:...filteredTokens)`, { + filteredTokens, + }); + } + if (searchTerm) { query.andWhere( new Brackets(qb => { @@ -508,6 +523,13 @@ export class RecurringDonationResolver { }), ); } + + if (networkId) { + query.andWhere(`recurringDonation.networkId = :networkId`, { + networkId, + }); + } + const [recurringDonations, donationsCount] = await query .take(take) .skip(skip) @@ -576,6 +598,7 @@ export class RecurringDonationResolver { includeArchived, finishStatus, filteredTokens, + networkId, }: UserRecurringDonationsArgs, @Ctx() ctx: ApolloContext, ) { @@ -639,6 +662,12 @@ export class RecurringDonationResolver { }); } + if (networkId) { + query.andWhere(`recurringDonation.networkId = :networkId`, { + networkId, + }); + } + const [recurringDonations, totalCount] = await query .take(take) .skip(skip)