feat: Create empty trigger step when the flow is created

This commit is contained in:
Faruk AYDIN
2022-01-05 23:24:31 +03:00
committed by Ömer Faruk Aydın
parent 247b25cfc4
commit c07b377de1
6 changed files with 31 additions and 9 deletions

View File

@@ -0,0 +1,16 @@
import { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable('steps', table => {
table.string('key').nullable().alter();
table.string('app_key').nullable().alter();
})
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable('steps', table => {
table.string('key').notNullable().alter();
table.string('app_key').notNullable().alter();
})
}

View File

@@ -1,4 +1,5 @@
import Flow from '../../models/flow';
import Step from '../../models/step';
import flowType from '../types/flow';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
@@ -7,6 +8,11 @@ const createFlowResolver = async (req: RequestWithCurrentUser) => {
userId: req.currentUser.id
});
await Step.query().insert({
flowId: flow.id,
type: 'trigger'
})
return flow;
}

View File

@@ -1,4 +1,4 @@
import { GraphQLNonNull, GraphQLString } from 'graphql';
import { GraphQLNonNull, GraphQLInt } from 'graphql';
import Flow from '../../models/flow';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import flowType from '../types/flow';
@@ -19,7 +19,7 @@ const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => {
const getFlow = {
type: flowType,
args: {
id: { type: GraphQLNonNull(GraphQLString) },
id: { type: GraphQLNonNull(GraphQLInt) },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getFlowResolver(params, req)
}

View File

@@ -5,8 +5,8 @@ const stepType = new GraphQLObjectType({
name: 'Step',
fields: {
id: { type: GraphQLInt },
key: { type: GraphQLNonNull(GraphQLString) },
appKey: { type: GraphQLNonNull(GraphQLString) },
key: { type: GraphQLString },
appKey: { type: GraphQLString },
type: {
type: new GraphQLEnumType({
name: 'StepEnumType',

View File

@@ -10,8 +10,8 @@ enum StepEnumType {
class Step extends Base {
id!: number
flowId!: number
key!: string
appKey!: string
key: string
appKey: string
type!: StepEnumType
connectionId!: number
parameters: any
@@ -20,7 +20,7 @@ class Step extends Base {
static jsonSchema = {
type: 'object',
required: ['key', 'appKey', 'type', 'connectionId'],
required: ['type'],
properties: {
id: { type: 'integer' },

View File

@@ -22,7 +22,7 @@ type EditorLayoutProps = {
export default function EditorLayout(props: EditorLayoutProps) {
const { flowId } = useParams();
const formatMessage = useFormatMessage();
const { data } = useQuery(GET_FLOW, { variables: { id: flowId }});
const { data } = useQuery(GET_FLOW, { variables: { id: Number(flowId) }});
const flow: Flow = data?.getFlow;
return (
@@ -58,4 +58,4 @@ export default function EditorLayout(props: EditorLayoutProps) {
</Stack>
</>
)
}
}