From f8e823545a54d77aa43a8ea8902b850c5d660e5b Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Mon, 22 Nov 2021 23:26:22 +0100 Subject: [PATCH] chore: Adjust create step mutation to work with flows --- packages/backend/src/graphql/mutations/create-step.ts | 9 +++++++++ packages/backend/src/graphql/types/flow.ts | 1 + packages/backend/src/models/step.ts | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/graphql/mutations/create-step.ts b/packages/backend/src/graphql/mutations/create-step.ts index 53c3d30b..d822ac8c 100644 --- a/packages/backend/src/graphql/mutations/create-step.ts +++ b/packages/backend/src/graphql/mutations/create-step.ts @@ -1,9 +1,11 @@ import { GraphQLString, GraphQLNonNull, GraphQLInt, GraphQLEnumType } from 'graphql'; import Step from '../../models/step'; +import Flow from '../../models/flow'; import stepType from '../types/step'; import RequestWithCurrentUser from '../../types/express/request-with-current-user'; type Params = { + flowId: number, key: string, appKey: string, type: string @@ -11,7 +13,13 @@ type Params = { } const createStepResolver = async (params: Params, req: RequestWithCurrentUser) => { + const flow = await Flow.query().findOne({ + id: params.flowId, + user_id: req.currentUser.id + }) + const step = await Step.query().insertAndFetch({ + flowId: flow.id, key: params.key, appKey: params.appKey, type: params.type, @@ -24,6 +32,7 @@ const createStepResolver = async (params: Params, req: RequestWithCurrentUser) = const createStep = { type: stepType, args: { + flowId: { type: GraphQLNonNull(GraphQLString) }, key: { type: GraphQLNonNull(GraphQLString) }, appKey: { type: GraphQLNonNull(GraphQLString) }, type: { diff --git a/packages/backend/src/graphql/types/flow.ts b/packages/backend/src/graphql/types/flow.ts index 5509cf56..92e7ab2f 100644 --- a/packages/backend/src/graphql/types/flow.ts +++ b/packages/backend/src/graphql/types/flow.ts @@ -3,6 +3,7 @@ import { GraphQLObjectType, GraphQLString } from 'graphql'; const flowType = new GraphQLObjectType({ name: 'Flow', fields: { + id: { type: GraphQLString }, name: { type: GraphQLString } } }) diff --git a/packages/backend/src/models/step.ts b/packages/backend/src/models/step.ts index fad3d37c..617e1698 100644 --- a/packages/backend/src/models/step.ts +++ b/packages/backend/src/models/step.ts @@ -1,5 +1,5 @@ -import Base from './base' -import Flow from './flow' +import Base from './base'; +import Flow from './flow'; enum StepEnumType { 'trigger', @@ -8,6 +8,7 @@ enum StepEnumType { class Step extends Base { id!: number + flowId!: number key!: string appKey!: string type!: StepEnumType @@ -22,6 +23,7 @@ class Step extends Base { properties: { id: { type: 'integer' }, + flowId: { type: 'integer' }, key: { type: 'string', minLength: 1, maxLength: 255 }, appKey: { type: 'string', minLength: 1, maxLength: 255 }, type: { type: "string", enum: ["action", "trigger"] },