Skip to content

Commit

Permalink
Merge pull request #2992 from uselagoon/feature/facts-query-adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Jan 31, 2022
2 parents 5a91654 + ac20b04 commit 1198564
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions services/api/src/resources/fact/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export const getFactFilteredEnvironmentIds = async (filterDetails: any, projectI

const getFactFilteredProjects = async (filterDetails: any, projectIdSubset: number[], sqlClientPool, isAdmin: boolean) => {
let factQuery = knex('project').distinct('project.*').innerJoin('environment', 'environment.project', 'project.id');
factQuery = buildContitionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = buildConditionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = setQueryLimit(filterDetails, factQuery);
factQuery = factQuery.orderBy('project.name', 'asc');

Expand All @@ -396,7 +396,7 @@ const getFactFilteredProjects = async (filterDetails: any, projectIdSubset: numb

const getFactFilteredProjectsCount = async (filterDetails: any, projectIdSubset: number[], sqlClientPool, isAdmin: boolean) => {
let factQuery = knex('project').countDistinct({ count: 'project.id'}).innerJoin('environment', 'environment.project', 'project.id');
factQuery = buildContitionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = buildConditionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);

const rows = await query(sqlClientPool, factQuery.toString());
return rows[0].count;
Expand All @@ -405,7 +405,7 @@ const getFactFilteredProjectsCount = async (filterDetails: any, projectIdSubset:

const getFactFilteredEnvironments = async (filterDetails: any, projectIdSubset: number[], sqlClientPool, isAdmin: boolean) => {
let factQuery = knex('environment').distinct('environment.*').innerJoin('project', 'environment.project', 'project.id');
factQuery = buildContitionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = buildConditionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = setQueryLimit(filterDetails, factQuery);
factQuery = factQuery.orderBy('project.name', 'asc');

Expand All @@ -415,13 +415,13 @@ const getFactFilteredEnvironments = async (filterDetails: any, projectIdSubset:

const getFactFilteredEnvironmentsCount = async (filterDetails: any, projectIdSubset: number[], sqlClientPool, isAdmin: boolean) => {
let factQuery = knex('environment').countDistinct({ count: 'environment.id'}).innerJoin('project', 'environment.project', 'project.id');
factQuery = buildContitionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);
factQuery = buildConditionsForFactSearchQuery(filterDetails, factQuery, projectIdSubset, isAdmin);

const rows = await query(sqlClientPool, factQuery.toString());
return rows[0].count;
}

const buildContitionsForFactSearchQuery = (filterDetails: any, factQuery: any, projectIdSubset: number[], isAdmin: boolean = false, byPassLimits: boolean = false) => {
const buildConditionsForFactSearchQuery = (filterDetails: any, factQuery: any, projectIdSubset: number[], isAdmin: boolean = false, byPassLimits: boolean = false) => {
if (filterDetails.filters && filterDetails.filters.length > 0) {
filterDetails.filters.forEach((filter, i) => {

Expand Down

0 comments on commit 1198564

Please sign in to comment.