Skip to content

Commit

Permalink
Merge pull request #153 from Giveth/fix-rf-round
Browse files Browse the repository at this point in the history
handle rf sources
  • Loading branch information
MohammadPCh authored Nov 17, 2024
2 parents 1043814 + 8c663db commit f283205
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/server-extension/project-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,44 @@ export class ProjectResolver {
// Initialize OR conditions
const orConditions = [];

// Add source filter if sources are provided
// Separate sources into 'rf' and others
let sourcesWithoutRF: string[] = [];
let hasRFSource = false;

if (sources && sources.length > 0) {
hasRFSource = sources.includes("rf");
sourcesWithoutRF = sources.filter((s) => s !== "rf");
}

// Add condition for sources excluding 'rf'
if (sourcesWithoutRF.length > 0) {
orConditions.push(`project.source = ANY($${paramIndex}::text[])`);
parameters.push(sources);
parameters.push(sourcesWithoutRF);
paramIndex++;
}

// Add rfRounds filter if rfRounds are provided
if (rfRounds && rfRounds.length > 0) {
orConditions.push(`project.rf_rounds && $${paramIndex}::int[]`);
// Add condition for 'rf' source
if (hasRFSource) {
if (rfRounds && rfRounds.length > 0) {
orConditions.push(
`(project.source = 'rf' AND project.rf_rounds && $${paramIndex}::int[])`
);
parameters.push(rfRounds);
paramIndex++;
} else {
orConditions.push(`project.source = 'rf'`);
}
}

// If sources is not provided but rfRounds are provided
if (
(!sources || sources.length === 0) &&
rfRounds &&
rfRounds.length > 0
) {
orConditions.push(
`(project.source = 'rf' AND project.rf_rounds && $${paramIndex}::int[])`
);
parameters.push(rfRounds);
paramIndex++;
}
Expand Down

0 comments on commit f283205

Please sign in to comment.