Skip to content

Commit

Permalink
Update src/resolvers/recurringDonationResolver.ts
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
CarlosQ96 and coderabbitai[bot] committed Dec 16, 2024
1 parent 86fbca9 commit 7b62770
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/resolvers/recurringDonationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ export class RecurringDonationResolver {

@Query(_return => [RecurringDonationEligibleProject], { nullable: true })
async recurringDonationEligibleProjects(
@Arg('networkId', { nullable: true }) networkId?: string,
@Arg('networkId', { nullable: true }) networkId?: number,
@Arg('page', _type => Int, { nullable: true, defaultValue: 1 })
page: number = 1,
@Arg('limit', _type => Int, { nullable: true, defaultValue: 50 })
Expand All @@ -765,12 +765,17 @@ export class RecurringDonationResolver {
try {
const offset = (page - 1) * limit;

const queryParams = [offset, limit];
let networkFilter = '';
let paramIndex = 3;
if (networkId) {
networkFilter = `AND anchor_contract_address."networkId" = ${networkId}`;
networkFilter = `AND anchor_contract_address."networkId" = $${paramIndex}`;
queryParams.push(networkId);
paramIndex++;
}

return await Project.getRepository().query(`
return await Project.getRepository().query(
`
SELECT
project.id,
project.slug,
Expand All @@ -786,9 +791,11 @@ export class RecurringDonationResolver {
AND anchor_contract_address."isActive" = true
${networkFilter}
GROUP BY project.id, project.slug, project.title
OFFSET ${offset}
LIMIT ${limit}
`);
OFFSET $1
LIMIT $2
`,
queryParams,
);
} catch (error) {
throw new Error(
`Error fetching eligible projects for donation: ${error}`,
Expand Down

0 comments on commit 7b62770

Please sign in to comment.