feat: Introduce position to step model

This commit is contained in:
Faruk AYDIN
2022-01-27 17:32:32 +03:00
committed by Ömer Faruk Aydın
parent c09a535653
commit 4985fb422e
4 changed files with 47 additions and 24 deletions

View File

@@ -0,0 +1,13 @@
import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.table('steps', (table) => {
table.integer('position').notNullable();
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.table('steps', (table) => {
table.dropColumn('position');
});
}

View File

@@ -5,20 +5,22 @@ import RequestWithCurrentUser from '../../types/express/request-with-current-use
const createFlowResolver = async (req: RequestWithCurrentUser) => {
const flow = await Flow.query().insert({
userId: req.currentUser.id
userId: req.currentUser.id,
});
await Step.query().insert({
flowId: flow.id,
type: 'trigger'
})
type: 'trigger',
position: 1,
});
return flow;
}
};
const createFlow = {
type: flowType,
resolve: (_: any, _params: any, req: RequestWithCurrentUser) => createFlowResolver(req)
resolve: (_: any, _params: any, req: RequestWithCurrentUser) =>
createFlowResolver(req),
};
export default createFlow;

View File

@@ -1,4 +1,9 @@
import { GraphQLObjectType, GraphQLString, GraphQLEnumType, GraphQLInt } from 'graphql';
import {
GraphQLObjectType,
GraphQLString,
GraphQLEnumType,
GraphQLInt,
} from 'graphql';
import ConnectionType from './connection';
const stepType = new GraphQLObjectType({
@@ -13,11 +18,12 @@ const stepType = new GraphQLObjectType({
values: {
trigger: { value: 'trigger' },
action: { value: 'action' },
}
})
},
connection: { type: ConnectionType }
}
})
}),
},
connection: { type: ConnectionType },
position: { type: GraphQLInt },
},
});
export default stepType;

View File

@@ -8,13 +8,14 @@ enum StepEnumType {
}
class Step extends Base {
id!: number
flowId!: number
key: string
appKey: string
type!: StepEnumType
connectionId!: number
parameters: any
id!: number;
flowId!: number;
key: string;
appKey: string;
type!: StepEnumType;
connectionId!: number;
position: number;
parameters: any;
static tableName = 'steps';
@@ -27,11 +28,12 @@ class Step extends Base {
flowId: { type: 'integer' },
key: { 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'] },
connectionId: { type: 'integer' },
position: { type: 'integer' },
parameters: { type: ['object', null] },
}
}
},
};
static relationMappings = () => ({
flow: {
@@ -47,10 +49,10 @@ class Step extends Base {
modelClass: Connection,
join: {
from: 'steps.connection_id',
to: 'connections.id'
to: 'connections.id',
},
}
})
},
});
}
export default Step;