Skip to content

Commit

Permalink
update sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Oct 29, 2024
1 parent 5fc9b39 commit 635d5cf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/server-extension/project-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "reflect-metadata";
import { GraphQLResolveInfo } from "graphql";
import { Arg, Info, Query, Resolver } from "type-graphql";
import { Arg, Info, Int, Query, Resolver } from "type-graphql";
import type { EntityManager } from "typeorm";
import { EProjectSort, ProjectsSortedByVouchOrFlagType } from "./types";
import { getProjectSortBy } from "./helper";
Expand All @@ -16,8 +16,8 @@ export class ProjectResolver {
@Arg("sources", () => [String], { nullable: true }) sources?: string[],
@Arg("sortBy", () => String, { nullable: true })
sortBy: EProjectSort = EProjectSort.HIGHEST_VOUCH_COUNT,
@Arg("limit", () => Number, { nullable: true }) limit: number = 10,
@Arg("offset", () => Number, { nullable: true }) offset: number = 0
@Arg("limit", () => Int, { nullable: true }) limit: number = 10,
@Arg("offset", () => Int, { nullable: true }) offset: number = 0
): Promise<ProjectsSortedByVouchOrFlagType[]> {
try {
const manager = await this.tx();
Expand All @@ -32,14 +32,14 @@ export class ProjectResolver {

// Add organization filter if organizations are provided
if (organizations && organizations.length > 0) {
conditions.push(`organisation.id = ANY($${paramIndex})`);
conditions.push(`organisation.id = ANY($${paramIndex}::text[])`);
parameters.push(organizations);
paramIndex++;
}

// Add source filter if sources are provided
if (sources && sources.length > 0) {
conditions.push(`project.source = ANY($${paramIndex})`);
conditions.push(`project.source = ANY($${paramIndex}::text[])`);
parameters.push(sources);
paramIndex++;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ export class ProjectResolver {
GROUP BY
project.id
ORDER BY
SUM(organisation_project.count) ${sortInfo.order}
SUM(organisation_project.count) ${sortInfo.order === "ASC" ? "ASC" : "DESC"}
LIMIT $${limitParamIndex} OFFSET $${offsetParamIndex};
`;

Expand Down

0 comments on commit 635d5cf

Please sign in to comment.