diff --git a/packages/backend/src/graphql/queries/get-executions.ts b/packages/backend/src/graphql/queries/get-executions.ts index 9497543b..109c1481 100644 --- a/packages/backend/src/graphql/queries/get-executions.ts +++ b/packages/backend/src/graphql/queries/get-executions.ts @@ -1,3 +1,4 @@ +import { raw } from 'objection'; import Context from '../../types/express/context'; import paginate from '../../helpers/pagination'; @@ -11,14 +12,26 @@ const getExecutions = async ( params: Params, context: Context ) => { + const selectStatusStatement = ` + case + when count(*) filter (where execution_steps.status = 'failure') > 0 + then 'failure' + else 'success' + end + as status + `; + const executions = context.currentUser .$relatedQuery('executions') + .joinRelated('executionSteps as execution_steps') + .select('executions.*', raw(selectStatusStatement)) .withSoftDeleted() .withGraphFetched({ flow: { steps: true, }, }) + .groupBy('executions.id') .orderBy('created_at', 'desc'); return paginate(executions, params.limit, params.offset); diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 98c7ef73..6ffc0438 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -233,6 +233,7 @@ type Execution { testRun: Boolean createdAt: String updatedAt: String + status: String flow: Flow }