feat: introduce CustomAutocomplete with variables
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { IDynamicData, IJSONObject } from '@automatisch/types';
|
||||
import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
import ExecutionStep from '../../models/execution-step';
|
||||
import globalVariable from '../../helpers/global-variable';
|
||||
import computeParameters from '../../helpers/compute-parameters';
|
||||
|
||||
type Params = {
|
||||
stepId: string;
|
||||
@@ -28,18 +30,29 @@ const getDynamicData = async (
|
||||
|
||||
if (!connection || !step.appKey) return null;
|
||||
|
||||
const flow = step.flow;
|
||||
const app = await App.findOneByKey(step.appKey);
|
||||
const $ = await globalVariable({ connection, app, flow: step.flow, step });
|
||||
const $ = await globalVariable({ connection, app, flow, step });
|
||||
|
||||
const command = app.dynamicData.find(
|
||||
(data: IDynamicData) => data.key === params.key
|
||||
);
|
||||
|
||||
// apply run-time parameters that're not persisted yet
|
||||
for (const parameterKey in params.parameters) {
|
||||
const parameterValue = params.parameters[parameterKey];
|
||||
$.step.parameters[parameterKey] = parameterValue;
|
||||
}
|
||||
|
||||
const priorExecutionSteps = await ExecutionStep.query().where({
|
||||
execution_id: (await flow.$relatedQuery('lastExecution')).id,
|
||||
});
|
||||
|
||||
// compute variables in parameters
|
||||
const computedParameters = computeParameters($.step.parameters, priorExecutionSteps);
|
||||
|
||||
$.step.parameters = computedParameters;
|
||||
|
||||
const fetchedData = await command.run($);
|
||||
|
||||
if (fetchedData.error) {
|
||||
|
Reference in New Issue
Block a user