feat: Introduce position to step model
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
c09a535653
commit
4985fb422e
@@ -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');
|
||||||
|
});
|
||||||
|
}
|
@@ -5,20 +5,22 @@ import RequestWithCurrentUser from '../../types/express/request-with-current-use
|
|||||||
|
|
||||||
const createFlowResolver = async (req: RequestWithCurrentUser) => {
|
const createFlowResolver = async (req: RequestWithCurrentUser) => {
|
||||||
const flow = await Flow.query().insert({
|
const flow = await Flow.query().insert({
|
||||||
userId: req.currentUser.id
|
userId: req.currentUser.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Step.query().insert({
|
await Step.query().insert({
|
||||||
flowId: flow.id,
|
flowId: flow.id,
|
||||||
type: 'trigger'
|
type: 'trigger',
|
||||||
})
|
position: 1,
|
||||||
|
});
|
||||||
|
|
||||||
return flow;
|
return flow;
|
||||||
}
|
};
|
||||||
|
|
||||||
const createFlow = {
|
const createFlow = {
|
||||||
type: flowType,
|
type: flowType,
|
||||||
resolve: (_: any, _params: any, req: RequestWithCurrentUser) => createFlowResolver(req)
|
resolve: (_: any, _params: any, req: RequestWithCurrentUser) =>
|
||||||
|
createFlowResolver(req),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createFlow;
|
export default createFlow;
|
||||||
|
@@ -1,4 +1,9 @@
|
|||||||
import { GraphQLObjectType, GraphQLString, GraphQLEnumType, GraphQLInt } from 'graphql';
|
import {
|
||||||
|
GraphQLObjectType,
|
||||||
|
GraphQLString,
|
||||||
|
GraphQLEnumType,
|
||||||
|
GraphQLInt,
|
||||||
|
} from 'graphql';
|
||||||
import ConnectionType from './connection';
|
import ConnectionType from './connection';
|
||||||
|
|
||||||
const stepType = new GraphQLObjectType({
|
const stepType = new GraphQLObjectType({
|
||||||
@@ -13,11 +18,12 @@ const stepType = new GraphQLObjectType({
|
|||||||
values: {
|
values: {
|
||||||
trigger: { value: 'trigger' },
|
trigger: { value: 'trigger' },
|
||||||
action: { value: 'action' },
|
action: { value: 'action' },
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
connection: { type: ConnectionType }
|
}),
|
||||||
}
|
},
|
||||||
})
|
connection: { type: ConnectionType },
|
||||||
|
position: { type: GraphQLInt },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default stepType;
|
export default stepType;
|
||||||
|
@@ -8,13 +8,14 @@ enum StepEnumType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Step extends Base {
|
class Step extends Base {
|
||||||
id!: number
|
id!: number;
|
||||||
flowId!: number
|
flowId!: number;
|
||||||
key: string
|
key: string;
|
||||||
appKey: string
|
appKey: string;
|
||||||
type!: StepEnumType
|
type!: StepEnumType;
|
||||||
connectionId!: number
|
connectionId!: number;
|
||||||
parameters: any
|
position: number;
|
||||||
|
parameters: any;
|
||||||
|
|
||||||
static tableName = 'steps';
|
static tableName = 'steps';
|
||||||
|
|
||||||
@@ -27,11 +28,12 @@ class Step extends Base {
|
|||||||
flowId: { 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'] },
|
||||||
connectionId: { type: 'integer' },
|
connectionId: { type: 'integer' },
|
||||||
|
position: { type: 'integer' },
|
||||||
parameters: { type: ['object', null] },
|
parameters: { type: ['object', null] },
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
static relationMappings = () => ({
|
static relationMappings = () => ({
|
||||||
flow: {
|
flow: {
|
||||||
@@ -47,10 +49,10 @@ class Step extends Base {
|
|||||||
modelClass: Connection,
|
modelClass: Connection,
|
||||||
join: {
|
join: {
|
||||||
from: 'steps.connection_id',
|
from: 'steps.connection_id',
|
||||||
to: 'connections.id'
|
to: 'connections.id',
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Step;
|
export default Step;
|
||||||
|
Reference in New Issue
Block a user