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

committed by
Ömer Faruk Aydın

parent
212523aec6
commit
bb36748764
@@ -2,7 +2,9 @@ import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const createAuthData = async (
|
||||
@@ -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 = {
|
||||
key: string;
|
||||
formattedData: IJSONObject;
|
||||
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,7 +1,9 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteConnection = async (
|
||||
@@ -13,7 +15,7 @@ const deleteConnection = async (
|
||||
.$relatedQuery('connections')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteFlow = async (
|
||||
@@ -13,7 +15,7 @@ const deleteFlow = async (
|
||||
.$relatedQuery('flows')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const deleteStep = async (
|
||||
@@ -13,7 +15,7 @@ const deleteStep = async (
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched('flow')
|
||||
.findOne({
|
||||
'steps.id': params.id,
|
||||
'steps.id': params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -4,7 +4,9 @@ import Processor from '../../services/processor';
|
||||
import processorQueue from '../../queues/processor';
|
||||
|
||||
type Params = {
|
||||
stepId: string;
|
||||
input: {
|
||||
stepId: string;
|
||||
};
|
||||
};
|
||||
|
||||
const executeFlow = async (
|
||||
@@ -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 = {
|
||||
email: string;
|
||||
password: string;
|
||||
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,7 +1,9 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const resetConnection = async (
|
||||
@@ -12,7 +14,7 @@ const resetConnection = async (
|
||||
let connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
@@ -2,8 +2,10 @@ import Context from '../../types/express/context';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
formattedData: IJSONObject;
|
||||
input: {
|
||||
id: string;
|
||||
formattedData: IJSONObject;
|
||||
};
|
||||
};
|
||||
|
||||
const updateConnection = async (
|
||||
@@ -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,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
active: boolean;
|
||||
input: {
|
||||
id: string;
|
||||
active: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
const updateFlowStatus = async (
|
||||
@@ -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,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
name: string;
|
||||
input: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
|
||||
const updateFlow = async (
|
||||
@@ -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,8 +1,10 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
email: string;
|
||||
password: string;
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
};
|
||||
|
||||
const updateUser = async (
|
||||
@@ -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,7 +2,9 @@ import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
input: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
const verifyConnection = async (
|
||||
@@ -13,7 +15,7 @@ const verifyConnection = async (
|
||||
let connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
id: params.input.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
|
Reference in New Issue
Block a user