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