refactor: use functional app implementation

This commit is contained in:
Ali BARIN
2022-10-06 23:27:37 +02:00
committed by Faruk AYDIN
parent 89d7359060
commit e7b47f5c98
9 changed files with 72 additions and 50 deletions

View File

@@ -1,5 +1,7 @@
import { IJSONObject } from '@automatisch/types';
import Context from '../../types/express/context';
import App from '../../models/app';
import globalVariable from '../../helpers/global-variable';
type Params = {
stepId: string;
@@ -22,11 +24,11 @@ const getData = async (_parent: unknown, params: Params, context: Context) => {
if (!connection || !step.appKey) return null;
const AppClass = (await import(`../../apps/${step.appKey}`)).default;
const appInstance = new AppClass(connection, step.flow, step);
const app = await App.findOneByKey(step.appKey);
const $ = await globalVariable(connection, app, step.flow, step)
const command = appInstance.data[params.key];
const fetchedData = await command.run();
const command = app.data[params.key];
const fetchedData = await command.run($);
return fetchedData;
};

View File

@@ -1,4 +1,6 @@
import Context from '../../types/express/context';
import App from '../../models/app';
import globalVariable from '../../helpers/global-variable';
type Params = {
id: string;
@@ -17,11 +19,11 @@ const testConnection = async (
})
.throwIfNotFound();
const appClass = (await import(`../../apps/${connection.key}`)).default;
const appInstance = new appClass(connection);
const app = await App.findOneByKey(connection.key, false);
const $ = await globalVariable(connection, app);
const isStillVerified =
await appInstance.authenticationClient.isStillVerified();
await app.auth.isStillVerified($);
connection = await connection.$query().patchAndFetch({
formattedData: connection.formattedData,