Skip to content

Commit

Permalink
Merge pull request #152 from Giveth/fix-add-rf-rounds-to-query
Browse files Browse the repository at this point in the history
handle-rf-rounds
  • Loading branch information
MohammadPCh authored Nov 15, 2024
2 parents 2f1109e + be649ac commit 1043814
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/server-extension/project-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,43 @@ export class ProjectResolver {
paramIndex++;
}

// Add vouch/flag condition
conditions.push(`organisation_project.vouch = $${paramIndex}`);
parameters.push(vouchValue);
paramIndex++;

// Initialize OR conditions
const orConditions = [];

// Add source filter if sources are provided
if (sources && sources.length > 0) {
conditions.push(`project.source = ANY($${paramIndex}::text[])`);
orConditions.push(`project.source = ANY($${paramIndex}::text[])`);
parameters.push(sources);
paramIndex++;
}

// Add rfRounds filter if rfRounds are provided
if (rfRounds && rfRounds.length > 0) {
conditions.push(`project.rf_rounds && $${paramIndex}::int[]`);
orConditions.push(`project.rf_rounds && $${paramIndex}::int[]`);
parameters.push(rfRounds);
paramIndex++;
}

// Add vouch/flag condition
conditions.push(`organisation_project.vouch = $${paramIndex}`);
parameters.push(vouchValue);
paramIndex++;

// Construct WHERE clause
const whereClauseParts = [];

if (conditions.length > 0) {
whereClauseParts.push(conditions.join(" AND "));
}

if (orConditions.length > 0) {
whereClauseParts.push("(" + orConditions.join(" OR ") + ")");
}

const whereClause =
conditions.length > 0 ? "WHERE " + conditions.join(" AND ") : "";
whereClauseParts.length > 0
? "WHERE " + whereClauseParts.join(" AND ")
: "";

// Add limit and offset parameters
parameters.push(limit);
Expand Down

0 comments on commit 1043814

Please sign in to comment.