feat: make step in editor configurable
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
4985fb422e
commit
95a63affe7
@@ -1,52 +1,54 @@
|
||||
import { GraphQLString, GraphQLNonNull, GraphQLInt, GraphQLEnumType } from 'graphql';
|
||||
import { GraphQLNonNull } from 'graphql';
|
||||
import Step from '../../models/step';
|
||||
import Flow from '../../models/flow';
|
||||
import stepType from '../types/step';
|
||||
import stepType, { stepInputType } from '../types/step';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
flowId: number,
|
||||
key: string,
|
||||
appKey: string,
|
||||
type: string
|
||||
connectionId: number
|
||||
}
|
||||
input: {
|
||||
key: string;
|
||||
appKey: string;
|
||||
flow: {
|
||||
id: number;
|
||||
};
|
||||
connection: {
|
||||
id: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const createStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const flow = await Flow.query().findOne({
|
||||
id: params.flowId,
|
||||
user_id: req.currentUser.id
|
||||
}).throwIfNotFound();
|
||||
const createStepResolver = async (
|
||||
params: Params,
|
||||
req: RequestWithCurrentUser
|
||||
) => {
|
||||
const { input } = params;
|
||||
|
||||
const flow = await Flow.query()
|
||||
.findOne({
|
||||
id: input.flow.id,
|
||||
user_id: req.currentUser.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
const step = await Step.query().insertAndFetch({
|
||||
flowId: flow.id,
|
||||
key: params.key,
|
||||
appKey: params.appKey,
|
||||
type: params.type,
|
||||
connectionId: params.connectionId,
|
||||
key: input.key,
|
||||
appKey: input.appKey,
|
||||
type: 'action',
|
||||
connectionId: input.connection?.id,
|
||||
position: 1,
|
||||
});
|
||||
|
||||
return step;
|
||||
}
|
||||
};
|
||||
|
||||
const createStep = {
|
||||
type: stepType,
|
||||
args: {
|
||||
flowId: { type: GraphQLNonNull(GraphQLInt) },
|
||||
key: { type: GraphQLNonNull(GraphQLString) },
|
||||
appKey: { type: GraphQLNonNull(GraphQLString) },
|
||||
type: {
|
||||
type: new GraphQLEnumType({
|
||||
name: 'StepInputEnumType',
|
||||
values: {
|
||||
trigger: { value: 'trigger' },
|
||||
action: { value: 'action' },
|
||||
}
|
||||
})
|
||||
},
|
||||
connectionId: { type: GraphQLNonNull(GraphQLInt) }
|
||||
input: { type: new GraphQLNonNull(stepInputType) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createStepResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||
createStepResolver(params, req),
|
||||
};
|
||||
|
||||
export default createStep;
|
||||
|
@@ -1,34 +1,41 @@
|
||||
import { GraphQLInt, GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Flow from '../../models/flow';
|
||||
import Step from '../../models/step';
|
||||
import stepType from '../types/step';
|
||||
import stepType, { stepInputType } from '../types/step';
|
||||
import availableAppsEnumType from '../types/available-apps-enum-type';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
id: number,
|
||||
flowId: number,
|
||||
key: string,
|
||||
appKey: string,
|
||||
connectionId: number
|
||||
input: {
|
||||
id: number,
|
||||
key: string,
|
||||
appKey: string,
|
||||
flow: {
|
||||
id: number,
|
||||
},
|
||||
connection: {
|
||||
id: number
|
||||
},
|
||||
}
|
||||
}
|
||||
const updateStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const { input } = params;
|
||||
|
||||
const flow = await Flow.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.flowId
|
||||
id: input.flow.id
|
||||
}).throwIfNotFound();
|
||||
|
||||
let step = await Step.query().findOne({
|
||||
flow_id: flow.id,
|
||||
id: params.id
|
||||
id: input.id
|
||||
}).throwIfNotFound();
|
||||
|
||||
step = await step.$query().patchAndFetch({
|
||||
...step,
|
||||
key: params.key,
|
||||
appKey: params.appKey,
|
||||
connectionId: params.connectionId
|
||||
})
|
||||
step = await Step.query().patchAndFetchById(input.id, {
|
||||
key: input.key,
|
||||
appKey: input.appKey,
|
||||
connectionId: input.connection.id,
|
||||
});
|
||||
|
||||
return step;
|
||||
}
|
||||
@@ -36,10 +43,7 @@ const updateStepResolver = async (params: Params, req: RequestWithCurrentUser) =
|
||||
const updateStep = {
|
||||
type: stepType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLInt) },
|
||||
flowId: { type: GraphQLNonNull(GraphQLInt) },
|
||||
key: { type: GraphQLString },
|
||||
appKey: { type: availableAppsEnumType },
|
||||
input: { type: new GraphQLNonNull(stepInputType) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateStepResolver(params, req)
|
||||
};
|
||||
|
@@ -3,6 +3,7 @@ import {
|
||||
GraphQLString,
|
||||
GraphQLEnumType,
|
||||
GraphQLInt,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
import ConnectionType from './connection';
|
||||
|
||||
@@ -10,6 +11,7 @@ const stepType = new GraphQLObjectType({
|
||||
name: 'Step',
|
||||
fields: {
|
||||
id: { type: GraphQLInt },
|
||||
previousStepId: { type: GraphQLInt },
|
||||
key: { type: GraphQLString },
|
||||
appKey: { type: GraphQLString },
|
||||
type: {
|
||||
@@ -26,4 +28,30 @@ const stepType = new GraphQLObjectType({
|
||||
},
|
||||
});
|
||||
|
||||
export const stepInputType = new GraphQLInputObjectType({
|
||||
name: 'StepInput',
|
||||
fields: {
|
||||
id: { type: GraphQLInt },
|
||||
previousStepId: { type: GraphQLInt },
|
||||
key: { type: GraphQLString },
|
||||
appKey: { type: GraphQLString },
|
||||
connection: {
|
||||
type: new GraphQLInputObjectType({
|
||||
name: 'StepConnectionInput',
|
||||
fields: {
|
||||
id: { type: GraphQLInt },
|
||||
}
|
||||
})
|
||||
},
|
||||
flow: {
|
||||
type: new GraphQLInputObjectType({
|
||||
name: 'StepFlowInput',
|
||||
fields: {
|
||||
id: { type: GraphQLInt },
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default stepType;
|
||||
|
@@ -26,7 +26,7 @@ class Step extends Base {
|
||||
properties: {
|
||||
id: { type: 'integer' },
|
||||
flowId: { type: 'integer' },
|
||||
key: { type: 'string', minLength: 1, maxLength: 255 },
|
||||
key: { type: ['string', null] },
|
||||
appKey: { type: 'string', minLength: 1, maxLength: 255 },
|
||||
type: { type: 'string', enum: ['action', 'trigger'] },
|
||||
connectionId: { type: 'integer' },
|
||||
|
Reference in New Issue
Block a user