From e155bb528ffee2d2645c6b38cd884b78e58c9bfd Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Sat, 5 Feb 2022 19:15:37 +0300 Subject: [PATCH] feat: Add status to step model and adjust executeFlow accordingly --- .../20220205145128_add_status_to_steps.ts | 13 +++++++++++++ .../src/graphql/mutations/execute-flow.ts | 18 +++++++++++------- .../backend/src/graphql/types/execute-flow.ts | 13 +++++++++++++ packages/backend/src/graphql/types/step.ts | 1 + packages/backend/src/models/step.ts | 2 ++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 packages/backend/src/db/migrations/20220205145128_add_status_to_steps.ts create mode 100644 packages/backend/src/graphql/types/execute-flow.ts diff --git a/packages/backend/src/db/migrations/20220205145128_add_status_to_steps.ts b/packages/backend/src/db/migrations/20220205145128_add_status_to_steps.ts new file mode 100644 index 00000000..25c16e38 --- /dev/null +++ b/packages/backend/src/db/migrations/20220205145128_add_status_to_steps.ts @@ -0,0 +1,13 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.schema.table('steps', (table) => { + table.string('status').notNullable().defaultTo('incomplete'); + }); +} + +export async function down(knex: Knex): Promise { + return knex.schema.table('steps', (table) => { + table.dropColumn('status'); + }); +} diff --git a/packages/backend/src/graphql/mutations/execute-flow.ts b/packages/backend/src/graphql/mutations/execute-flow.ts index affddfcc..ca0c3542 100644 --- a/packages/backend/src/graphql/mutations/execute-flow.ts +++ b/packages/backend/src/graphql/mutations/execute-flow.ts @@ -1,12 +1,12 @@ import { GraphQLString, GraphQLNonNull } from 'graphql'; -import { GraphQLJSONObject } from 'graphql-type-json'; import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import executeFlowType from '../types/execute-flow'; type Params = { stepId: string; data: Record; }; -const executeStepResolver = async ( +const executeFlowResolver = async ( params: Params, req: RequestWithCurrentUser ): Promise => { @@ -22,16 +22,20 @@ const executeStepResolver = async ( const appInstance = new appClass(step.connection.data); const data = await appInstance.triggers[step.key].run(); - return { data }; + await step.$query().patch({ + status: 'completed', + }); + + return { data, step }; }; -const executeStep = { - type: GraphQLJSONObject, +const executeFlow = { + type: executeFlowType, args: { stepId: { type: GraphQLNonNull(GraphQLString) }, }, resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - executeStepResolver(params, req), + executeFlowResolver(params, req), }; -export default executeStep; +export default executeFlow; diff --git a/packages/backend/src/graphql/types/execute-flow.ts b/packages/backend/src/graphql/types/execute-flow.ts new file mode 100644 index 00000000..a0ee65b1 --- /dev/null +++ b/packages/backend/src/graphql/types/execute-flow.ts @@ -0,0 +1,13 @@ +import { GraphQLJSONObject } from 'graphql-type-json'; +import { GraphQLObjectType } from 'graphql'; +import stepType from './step'; + +const executeFlowType = new GraphQLObjectType({ + name: 'executeFlowType', + fields: { + data: { type: GraphQLJSONObject }, + step: { type: stepType }, + }, +}); + +export default executeFlowType; diff --git a/packages/backend/src/graphql/types/step.ts b/packages/backend/src/graphql/types/step.ts index 18ff6f17..a0800bd1 100644 --- a/packages/backend/src/graphql/types/step.ts +++ b/packages/backend/src/graphql/types/step.ts @@ -31,6 +31,7 @@ const stepType = new GraphQLObjectType({ connection: { type: ConnectionType }, flow: { type: FlowType }, position: { type: GraphQLInt }, + status: { type: GraphQLString }, }; }, }); diff --git a/packages/backend/src/models/step.ts b/packages/backend/src/models/step.ts index a5fe6055..d5cc776c 100644 --- a/packages/backend/src/models/step.ts +++ b/packages/backend/src/models/step.ts @@ -14,6 +14,7 @@ class Step extends Base { appKey: string; type!: StepEnumType; connectionId: string; + status: string; position: number; parameters: string; connection?: Connection; @@ -32,6 +33,7 @@ class Step extends Base { appKey: { type: ['string', null], minLength: 1, maxLength: 255 }, type: { type: 'string', enum: ['action', 'trigger'] }, connectionId: { type: ['string', null] }, + status: { type: 'string', enum: ['incomplete', 'completed'] }, position: { type: 'integer' }, parameters: { type: ['string', null] }, },