Skip to content

Commit

Permalink
Merge pull request #3866 from uselagoon/deployment-by-filter-dates
Browse files Browse the repository at this point in the history
feat: more filters for deploymentsByFilter
  • Loading branch information
tobybellwood authored Feb 14, 2025
2 parents d593e38 + 4c153f2 commit 22bd950
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const getDeploymentsByFilter: ResolverFn = async (
{ sqlClientPool, hasPermission, models, keycloakGrant, keycloakUsersGroups, adminScopes }
) => {

const { openshifts, deploymentStatus = ["NEW", "PENDING", "RUNNING", "QUEUED"] } = input;
const { openshifts, deploymentStatus = ["NEW", "PENDING", "RUNNING", "QUEUED"], startDate, endDate, includeDeleted } = input;

/*
use the same mechanism for viewing all projects
Expand Down Expand Up @@ -181,13 +181,28 @@ export const getDeploymentsByFilter: ResolverFn = async (
queryBuilder = queryBuilder.whereIn('environment.project', userProjectIds);
}

// collect builds for a specific date range
if (startDate) {
queryBuilder = queryBuilder.where('deployment.created', '>=', input.startDate);
}

if (endDate) {
queryBuilder = queryBuilder.where('deployment.created', '<=', input.endDate);
}

if(openshifts) {
queryBuilder = queryBuilder.whereIn('environment.openshift', openshifts);
}

queryBuilder = queryBuilder.whereIn('deployment.status', deploymentStatus);

queryBuilder = queryBuilder.where('environment.deleted', '=', '0000-00-00 00:00:00');
// if includeDeleted is false, exclude deleted environments in the results (default)
if (!includeDeleted) {
queryBuilder = queryBuilder.where('environment.deleted', '=', '0000-00-00 00:00:00');
}

// exclude results where a project doesn't exist
queryBuilder = queryBuilder.whereRaw('environment.project IN (SELECT id FROM project)')

const queryBuilderString = queryBuilder.toString();

Expand Down
2 changes: 1 addition & 1 deletion services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ const typeDefs = gql`
deploymentByRemoteId(id: String): Deployment
deploymentByName(input: DeploymentByNameInput): Deployment
deploymentsByBulkId(bulkId: String): [Deployment]
deploymentsByFilter(openshifts: [Int], deploymentStatus: [DeploymentStatusType]): [Deployment]
deploymentsByFilter(openshifts: [Int], deploymentStatus: [DeploymentStatusType], startDate: Date, endDate: Date, includeDeleted: Boolean): [Deployment]
taskByTaskName(taskName: String): Task
taskByRemoteId(id: String): Task
taskById(id: Int): Task
Expand Down

0 comments on commit 22bd950

Please sign in to comment.