feat: Add status to step model and adjust executeFlow accordingly
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
572ad71241
commit
e155bb528f
@@ -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');
|
||||
});
|
||||
}
|
@@ -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;
|
||||
|
13
packages/backend/src/graphql/types/execute-flow.ts
Normal file
13
packages/backend/src/graphql/types/execute-flow.ts
Normal 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;
|
@@ -31,6 +31,7 @@ const stepType = new GraphQLObjectType({
|
||||
connection: { type: ConnectionType },
|
||||
flow: { type: FlowType },
|
||||
position: { type: GraphQLInt },
|
||||
status: { type: GraphQLString },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
@@ -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] },
|
||||
},
|
||||
|
Reference in New Issue
Block a user