refactor: Use input params for all mutations
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
212523aec6
commit
bb36748764
@@ -2,8 +2,10 @@ import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const createAuthData = async (
|
||||
_parent: unknown,
|
||||
@@ -13,7 +15,7 @@ const createAuthData = async (
|
||||
const connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -3,21 +3,23 @@ import Context from '../../types/express/context';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
key: string;
|
||||
formattedData: IJSONObject;
|
||||
};
|
||||
};
|
||||
const createConnection = async (
|
||||
_parent: unknown,
|
||||
params: Params,
|
||||
context: Context
|
||||
) => {
|
||||
const app = App.findOneByKey(params.key);
|
||||
const app = App.findOneByKey(params.input.key);
|
||||
|
||||
const connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.insert({
|
||||
key: params.key,
|
||||
formattedData: params.formattedData,
|
||||
key: params.input.key,
|
||||
formattedData: params.input.formattedData,
|
||||
});
|
||||
|
||||
return {
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteConnection = async (
|
||||
_parent: unknown,
|
||||
@@ -13,7 +15,7 @@ const deleteConnection = async (
|
||||
.$relatedQuery('connections')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteFlow = async (
|
||||
_parent: unknown,
|
||||
@@ -13,7 +15,7 @@ const deleteFlow = async (
|
||||
.$relatedQuery('flows')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteStep = async (
|
||||
_parent: unknown,
|
||||
@@ -13,7 +15,7 @@ const deleteStep = async (
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched('flow')
|
||||
.findOne({
|
||||
'steps.id': params.id,
|
||||
'steps.id': params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -4,8 +4,10 @@ import Processor from '../../services/processor';
|
||||
import processorQueue from '../../queues/processor';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
stepId: string;
|
||||
};
|
||||
};
|
||||
|
||||
const executeFlow = async (
|
||||
_parent: unknown,
|
||||
@@ -16,7 +18,7 @@ const executeFlow = async (
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched('connection')
|
||||
.findOne({
|
||||
'steps.id': params.stepId,
|
||||
'steps.id': params.input.stepId,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -3,18 +3,20 @@ import jwt from 'jsonwebtoken';
|
||||
import appConfig from '../../config/app';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
};
|
||||
|
||||
const TOKEN_EXPIRES_IN = '14d';
|
||||
|
||||
const login = async (_parent: unknown, params: Params) => {
|
||||
const user = await User.query().findOne({
|
||||
email: params.email,
|
||||
email: params.input.email,
|
||||
});
|
||||
|
||||
if (user && (await user.login(params.password))) {
|
||||
if (user && (await user.login(params.input.password))) {
|
||||
const token = jwt.sign({ userId: user.id }, appConfig.appSecretKey, {
|
||||
expiresIn: TOKEN_EXPIRES_IN,
|
||||
});
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const resetConnection = async (
|
||||
_parent: unknown,
|
||||
@@ -12,7 +14,7 @@ const resetConnection = async (
|
||||
let connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -2,9 +2,11 @@ import Context from '../../types/express/context';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
formattedData: IJSONObject;
|
||||
};
|
||||
};
|
||||
|
||||
const updateConnection = async (
|
||||
_parent: unknown,
|
||||
@@ -14,14 +16,14 @@ const updateConnection = async (
|
||||
let connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
formattedData: {
|
||||
...connection.formattedData,
|
||||
...params.formattedData,
|
||||
...params.input.formattedData,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
active: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
const updateFlowStatus = async (
|
||||
_parent: unknown,
|
||||
@@ -13,16 +15,16 @@ const updateFlowStatus = async (
|
||||
let flow = await context.currentUser
|
||||
.$relatedQuery('flows')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
if (flow.active === params.active) {
|
||||
if (flow.active === params.input.active) {
|
||||
return flow;
|
||||
}
|
||||
|
||||
flow = await flow.$query().patchAndFetch({
|
||||
active: params.active,
|
||||
active: params.input.active,
|
||||
});
|
||||
|
||||
return flow;
|
||||
|
@@ -1,9 +1,11 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
|
||||
const updateFlow = async (
|
||||
_parent: unknown,
|
||||
@@ -13,12 +15,12 @@ const updateFlow = async (
|
||||
let flow = await context.currentUser
|
||||
.$relatedQuery('flows')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
flow = await flow.$query().patchAndFetch({
|
||||
name: params.name,
|
||||
name: params.input.name,
|
||||
});
|
||||
|
||||
return flow;
|
||||
|
@@ -1,9 +1,11 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
};
|
||||
|
||||
const updateUser = async (
|
||||
_parent: unknown,
|
||||
@@ -11,8 +13,8 @@ const updateUser = async (
|
||||
context: Context
|
||||
) => {
|
||||
const user = await context.currentUser.$query().patchAndFetch({
|
||||
email: params.email,
|
||||
password: params.password,
|
||||
email: params.input.email,
|
||||
password: params.input.password,
|
||||
});
|
||||
|
||||
return user;
|
||||
|
@@ -2,8 +2,10 @@ import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const verifyConnection = async (
|
||||
_parent: unknown,
|
||||
@@ -13,7 +15,7 @@ const verifyConnection = async (
|
||||
let connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -10,25 +10,22 @@ type Query {
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createConnection(
|
||||
key: AvailableAppsEnumType!
|
||||
formattedData: JSONObject!
|
||||
): Connection
|
||||
createAuthData(id: String!): AuthLink
|
||||
updateConnection(id: String!, formattedData: JSONObject!): Connection
|
||||
resetConnection(id: String!): Connection
|
||||
verifyConnection(id: String!): Connection
|
||||
deleteConnection(id: String!): Boolean
|
||||
createFlow(input: FlowInput): Flow
|
||||
updateFlow(id: String!, name: String!): Flow
|
||||
updateFlowStatus(id: String!, active: Boolean!): Flow
|
||||
executeFlow(stepId: String!): executeFlowType
|
||||
deleteFlow(id: String!): Boolean
|
||||
createStep(input: StepInput!): Step
|
||||
updateStep(input: StepInput!): Step
|
||||
deleteStep(id: String!): Step
|
||||
updateUser(email: String, password: String): User
|
||||
login(email: String!, password: String!): Auth
|
||||
createConnection(input: CreateConnectionInput): Connection
|
||||
createAuthData(input: CreateAuthDataInput): AuthLink
|
||||
updateConnection(input: UpdateConnectionInput): Connection
|
||||
resetConnection(input: ResetConnectionInput): Connection
|
||||
verifyConnection(input: VerifyConnectionInput): Connection
|
||||
deleteConnection(input: DeleteConnectionInput): Boolean
|
||||
createFlow(input: CreateFlowInput): Flow
|
||||
updateFlow(input: UpdateFlowInput): Flow
|
||||
updateFlowStatus(input: UpdateFlowStatusInput): Flow
|
||||
executeFlow(input: ExecuteFlowInput): executeFlowType
|
||||
deleteFlow(input: DeleteFlowInput): Boolean
|
||||
createStep(input: CreateStepInput): Step
|
||||
updateStep(input: UpdateStepInput): Step
|
||||
deleteStep(input: DeleteStepInput): Step
|
||||
updateUser(input: UpdateUserInput): User
|
||||
login(input: LoginInput): Auth
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -171,10 +168,76 @@ type Flow {
|
||||
steps: [Step]
|
||||
}
|
||||
|
||||
input FlowInput {
|
||||
input CreateConnectionInput {
|
||||
key: AvailableAppsEnumType!
|
||||
formattedData: JSONObject!
|
||||
}
|
||||
|
||||
input CreateAuthDataInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input UpdateConnectionInput {
|
||||
id: String!
|
||||
formattedData: JSONObject!
|
||||
}
|
||||
|
||||
input ResetConnectionInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input VerifyConnectionInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input DeleteConnectionInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input CreateFlowInput {
|
||||
triggerAppKey: String
|
||||
}
|
||||
|
||||
input UpdateFlowInput {
|
||||
id: String!
|
||||
name: String!
|
||||
}
|
||||
|
||||
input UpdateFlowStatusInput {
|
||||
id: String!
|
||||
active: Boolean!
|
||||
}
|
||||
|
||||
input ExecuteFlowInput {
|
||||
stepId: String!
|
||||
}
|
||||
|
||||
input DeleteFlowInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input CreateStepInput {
|
||||
input: StepInput!
|
||||
}
|
||||
|
||||
input UpdateStepInput {
|
||||
input: StepInput!
|
||||
}
|
||||
|
||||
input DeleteStepInput {
|
||||
id: String!
|
||||
}
|
||||
|
||||
input UpdateUserInput {
|
||||
email: String
|
||||
password: String
|
||||
}
|
||||
|
||||
input LoginInput {
|
||||
email: String!
|
||||
password: String!
|
||||
}
|
||||
|
||||
"""
|
||||
The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
|
||||
"""
|
||||
|
Reference in New Issue
Block a user