feat: Implement update step graphQL mutation

This commit is contained in:
Faruk AYDIN
2022-01-06 22:08:46 +03:00
committed by Ali BARIN
parent b6c7ce96c9
commit d25d327ef7
3 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
import { GraphQLInt, GraphQLString, GraphQLNonNull } from 'graphql';
import Flow from '../../models/flow';
import Step from '../../models/step';
import flowType from '../types/flow';
import stepType from '../types/step';
import availableAppsEnumType from '../types/available-apps-enum-type';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = {
id: number,
flowId: number,
key: string,
appKey: string,
connectionId: number
}
const updateStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
const flow = await Flow.query().findOne({
user_id: req.currentUser.id,
id: params.flowId
}).throwIfNotFound();
let step = await Step.query().findOne({
flow_id: flow.id,
id: params.id
}).throwIfNotFound();
step = await step.$query().patchAndFetch({
...step,
key: params.key,
appKey: params.appKey,
connectionId: params.connectionId
})
return step;
}
const updateStep = {
type: stepType,
args: {
id: { type: GraphQLNonNull(GraphQLInt) },
flowId: { type: GraphQLNonNull(GraphQLInt) },
key: { type: GraphQLString },
appKey: { type: availableAppsEnumType },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateStepResolver(params, req)
};
export default updateStep;