Make sure that Test-Webhooks use the current data not from DB

This commit is contained in:
Jan Oberhauser 2020-02-10 17:52:15 -08:00
parent 87f2e8b91c
commit 1391bf39c6

View file

@ -1,11 +1,6 @@
import * as express from 'express';
import {
In as findIn,
FindManyOptions,
} from 'typeorm';
import {
Db,
IResponseCallbackData,
IWorkflowDb,
NodeTypes,
@ -67,10 +62,9 @@ export class TestWebhooks {
throw new ResponseHelper.ResponseError('The requested webhook is not registred.', 404, 404);
}
const workflowData = await Db.collections.Workflow!.findOne(webhookData.workflowId);
if (workflowData === undefined) {
throw new ResponseHelper.ResponseError(`Could not find workflow with id "${webhookData.workflowId}"`, 404, 404);
}
const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
const workflowData = this.testWebhookData[webhookKey].workflowData;
const nodeTypes = NodeTypes();
const workflow = new Workflow(webhookData.workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings);
@ -82,8 +76,6 @@ export class TestWebhooks {
throw new ResponseHelper.ResponseError('Could not find node to process webhook.', 404, 404);
}
const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
return new Promise(async (resolve, reject) => {
try {
const executionMode = 'manual';
@ -206,19 +198,18 @@ export class TestWebhooks {
if (this.activeWebhooks === null) {
return;
}
const nodeTypes = NodeTypes();
const findQuery = {
where: {
id: findIn(this.activeWebhooks.getWorkflowIds())
},
} as FindManyOptions;
const workflowsDb = await Db.collections.Workflow!.find(findQuery);
let workflowData: IWorkflowDb;
let workflow: Workflow;
const workflows: Workflow[] = [];
for (const workflowData of workflowsDb) {
const workflow = new Workflow(workflowData.id.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings);
workflows.push(workflow);
for (const webhookKey of Object.keys(this.testWebhookData)) {
console.log('webhookKey: ' + webhookKey);
workflowData = this.testWebhookData[webhookKey].workflowData;
workflow = new Workflow(workflowData.id.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings);
workflows.push();
}
return this.activeWebhooks.removeAll(workflows);