refactor: Restructure apps with new data pushing logic

This commit is contained in:
Faruk AYDIN
2022-10-22 19:29:02 +02:00
parent bcff9f5a9e
commit a56135ca57
19 changed files with 115 additions and 136 deletions

View File

@@ -39,16 +39,29 @@ export const processAction = async (options: ProcessActionOptions) => {
const actionCommand = await step.getActionCommand();
$.step.parameters = computedParameters;
const actionOutput = await actionCommand.run($);
try {
await actionCommand.run($);
} catch (error) {
if (error?.response?.httpError) {
$.actionOutput.error = error.response.httpError;
} else {
try {
$.actionOutput.error = JSON.parse(error.message);
} catch {
$.actionOutput.error = { error: error.message };
}
}
}
const executionStep = await execution
.$relatedQuery('executionSteps')
.insertAndFetch({
stepId: $.step.id,
status: actionOutput.error ? 'failure' : 'success',
status: $.actionOutput.error ? 'failure' : 'success',
dataIn: computedParameters,
dataOut: actionOutput.error ? null : actionOutput.data?.raw,
errorDetails: actionOutput.error ? actionOutput.error : null,
dataOut: $.actionOutput.error ? null : $.actionOutput.data?.raw,
errorDetails: $.actionOutput.error ? $.actionOutput.error : null,
});
return { flowId, stepId, executionId, executionStep };

View File

@@ -35,7 +35,7 @@ export const processFlow = async (options: ProcessFlowOptions) => {
}
if (triggerCommand?.sort) {
triggerCommand.sort($);
$.triggerOutput.data.sort(triggerCommand.sort);
}
return $.triggerOutput;

View File

@@ -35,13 +35,13 @@ const testRun = async (options: TestRunOptions) => {
return { executionStep: triggerExecutionStepWithError };
}
const firstTriggerDataItem = data[0];
const firstTriggerItem = data[0];
const { executionId, executionStep: triggerExecutionStep } =
await processTrigger({
flowId: flow.id,
stepId: triggerStep.id,
triggerDataItem: firstTriggerDataItem,
triggerItem: firstTriggerItem,
testRun: true,
});

View File

@@ -1,4 +1,4 @@
import { IJSONObject, ITriggerDataItem } from '@automatisch/types';
import { IJSONObject, ITriggerItem } from '@automatisch/types';
import Step from '../models/step';
import Flow from '../models/flow';
import Execution from '../models/execution';
@@ -7,13 +7,13 @@ import globalVariable from '../helpers/global-variable';
type ProcessTriggerOptions = {
flowId: string;
stepId: string;
triggerDataItem?: ITriggerDataItem;
triggerItem?: ITriggerItem;
error?: IJSONObject;
testRun?: boolean;
};
export const processTrigger = async (options: ProcessTriggerOptions) => {
const { flowId, stepId, triggerDataItem, error, testRun } = options;
const { flowId, stepId, triggerItem, error, testRun } = options;
const step = await Step.query().findById(stepId).throwIfNotFound();
@@ -29,7 +29,7 @@ export const processTrigger = async (options: ProcessTriggerOptions) => {
const execution = await Execution.query().insert({
flowId: $.flow.id,
testRun,
internalId: triggerDataItem?.meta.internalId,
internalId: triggerItem?.meta.internalId,
});
const executionStep = await execution
@@ -38,7 +38,7 @@ export const processTrigger = async (options: ProcessTriggerOptions) => {
stepId: $.step.id,
status: error ? 'failure' : 'success',
dataIn: $.step.parameters,
dataOut: !error ? triggerDataItem?.raw : null,
dataOut: !error ? triggerItem?.raw : null,
errorDetails: error,
});