chore: Introduce has many steps through flows for user model
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
700d0bfd32
commit
3429784309
@@ -10,8 +10,8 @@ const deleteStepResolver = async (
|
||||
params: Params,
|
||||
req: RequestWithCurrentUser
|
||||
) => {
|
||||
// TODO: This logic should be revised by using current user
|
||||
await Step.query()
|
||||
await req.currentUser
|
||||
.$relatedQuery('steps')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
|
@@ -1,27 +1,25 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import Step from '../../models/step';
|
||||
import stepType from '../types/step';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
data: Record<string, unknown>;
|
||||
};
|
||||
const executeStepResolver = async (params: Params): Promise<any> => {
|
||||
const step = await Step.query()
|
||||
const executeStepResolver = async (
|
||||
params: Params,
|
||||
req: RequestWithCurrentUser
|
||||
): Promise<any> => {
|
||||
const step = await req.currentUser
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched('connection')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
const connection = await Connection.query()
|
||||
.findOne({
|
||||
id: step.connectionId,
|
||||
'steps.id': params.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
const appClass = (await import(`../../apps/${step.appKey}`)).default;
|
||||
const appInstance = new appClass(connection.data);
|
||||
const appInstance = new appClass(step.connection.data);
|
||||
await appInstance.triggers[step.key].run();
|
||||
|
||||
return step;
|
||||
@@ -32,7 +30,8 @@ const executeStep = {
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: (_: any, params: Params) => executeStepResolver(params),
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||
executeStepResolver(params, req),
|
||||
};
|
||||
|
||||
export default executeStep;
|
||||
|
@@ -23,17 +23,11 @@ const updateStepResolver = async (
|
||||
) => {
|
||||
const { input } = params;
|
||||
|
||||
const flow = await req.currentUser
|
||||
.$relatedQuery('flows')
|
||||
.findOne({
|
||||
id: input.flow.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
let step = await flow
|
||||
let step = await req.currentUser
|
||||
.$relatedQuery('steps')
|
||||
.findOne({
|
||||
id: input.id,
|
||||
'steps.id': input.id,
|
||||
flow_id: input.flow.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
Reference in New Issue
Block a user