Skip to content

Commit

Permalink
add filters for network and tokens for recurringdonations
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Dec 16, 2024
1 parent 23e1f84 commit 196c329
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/resolvers/recurringDonationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class UserRecurringDonationsArgs {

@Field(_type => [String], { nullable: true, defaultValue: [] })
filteredTokens: string[];

@Field(_type => Int, { nullable: true })
networkId?: number;
}

@ObjectType()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -508,6 +523,13 @@ export class RecurringDonationResolver {
}),
);
}

if (networkId) {
query.andWhere(`recurringDonation.networkId = :networkId`, {
networkId,
});
}

const [recurringDonations, donationsCount] = await query
.take(take)
.skip(skip)
Expand Down Expand Up @@ -576,6 +598,7 @@ export class RecurringDonationResolver {
includeArchived,
finishStatus,
filteredTokens,
networkId,
}: UserRecurringDonationsArgs,
@Ctx() ctx: ApolloContext,
) {
Expand Down Expand Up @@ -639,6 +662,12 @@ export class RecurringDonationResolver {
});
}

if (networkId) {
query.andWhere(`recurringDonation.networkId = :networkId`, {
networkId,
});
}

const [recurringDonations, totalCount] = await query
.take(take)
.skip(skip)
Expand Down

0 comments on commit 196c329

Please sign in to comment.