chore: Adjust create step mutation to work with flows

This commit is contained in:
Faruk AYDIN
2021-11-22 23:26:22 +01:00
committed by Ömer Faruk Aydın
parent 8a7d54bb25
commit f8e823545a
3 changed files with 14 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
import { GraphQLString, GraphQLNonNull, GraphQLInt, GraphQLEnumType } from 'graphql'; import { GraphQLString, GraphQLNonNull, GraphQLInt, GraphQLEnumType } from 'graphql';
import Step from '../../models/step'; import Step from '../../models/step';
import Flow from '../../models/flow';
import stepType from '../types/step'; import stepType from '../types/step';
import RequestWithCurrentUser from '../../types/express/request-with-current-user'; import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = { type Params = {
flowId: number,
key: string, key: string,
appKey: string, appKey: string,
type: string type: string
@@ -11,7 +13,13 @@ type Params = {
} }
const createStepResolver = async (params: Params, req: RequestWithCurrentUser) => { 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({ const step = await Step.query().insertAndFetch({
flowId: flow.id,
key: params.key, key: params.key,
appKey: params.appKey, appKey: params.appKey,
type: params.type, type: params.type,
@@ -24,6 +32,7 @@ const createStepResolver = async (params: Params, req: RequestWithCurrentUser) =
const createStep = { const createStep = {
type: stepType, type: stepType,
args: { args: {
flowId: { type: GraphQLNonNull(GraphQLString) },
key: { type: GraphQLNonNull(GraphQLString) }, key: { type: GraphQLNonNull(GraphQLString) },
appKey: { type: GraphQLNonNull(GraphQLString) }, appKey: { type: GraphQLNonNull(GraphQLString) },
type: { type: {

View File

@@ -3,6 +3,7 @@ import { GraphQLObjectType, GraphQLString } from 'graphql';
const flowType = new GraphQLObjectType({ const flowType = new GraphQLObjectType({
name: 'Flow', name: 'Flow',
fields: { fields: {
id: { type: GraphQLString },
name: { type: GraphQLString } name: { type: GraphQLString }
} }
}) })

View File

@@ -1,5 +1,5 @@
import Base from './base' import Base from './base';
import Flow from './flow' import Flow from './flow';
enum StepEnumType { enum StepEnumType {
'trigger', 'trigger',
@@ -8,6 +8,7 @@ enum StepEnumType {
class Step extends Base { class Step extends Base {
id!: number id!: number
flowId!: number
key!: string key!: string
appKey!: string appKey!: string
type!: StepEnumType type!: StepEnumType
@@ -22,6 +23,7 @@ class Step extends Base {
properties: { properties: {
id: { type: 'integer' }, id: { type: 'integer' },
flowId: { type: 'integer' },
key: { type: 'string', minLength: 1, maxLength: 255 }, key: { type: 'string', minLength: 1, maxLength: 255 },
appKey: { type: 'string', minLength: 1, maxLength: 255 }, appKey: { type: 'string', minLength: 1, maxLength: 255 },
type: { type: "string", enum: ["action", "trigger"] }, type: { type: "string", enum: ["action", "trigger"] },