feat: Add status to step model and adjust executeFlow accordingly

This commit is contained in:
Faruk AYDIN
2022-02-05 19:15:37 +03:00
committed by Ömer Faruk Aydın
parent 572ad71241
commit e155bb528f
5 changed files with 40 additions and 7 deletions

View File

@@ -0,0 +1,13 @@
import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.table('steps', (table) => {
table.string('status').notNullable().defaultTo('incomplete');
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.table('steps', (table) => {
table.dropColumn('status');
});
}

View File

@@ -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<string, unknown>;
};
const executeStepResolver = async (
const executeFlowResolver = async (
params: Params,
req: RequestWithCurrentUser
): Promise<any> => {
@@ -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;

View File

@@ -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;

View File

@@ -31,6 +31,7 @@ const stepType = new GraphQLObjectType({
connection: { type: ConnectionType },
flow: { type: FlowType },
position: { type: GraphQLInt },
status: { type: GraphQLString },
};
},
});

View File

@@ -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] },
},