From e43e0e100be81b6e06e7af66ac28d2390898c1d5 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 2 Oct 2020 16:42:47 +0100 Subject: [PATCH 1/2] Some quick automation fixes. --- packages/server/src/automations/actions.js | 6 +++--- .../steps/{saveRecord.js => createRecord.js} | 8 ++++---- packages/server/src/automations/steps/filter.js | 10 +++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) rename packages/server/src/automations/steps/{saveRecord.js => createRecord.js} (92%) diff --git a/packages/server/src/automations/actions.js b/packages/server/src/automations/actions.js index b626919ff6..7d86250f56 100644 --- a/packages/server/src/automations/actions.js +++ b/packages/server/src/automations/actions.js @@ -1,5 +1,5 @@ const sendEmail = require("./steps/sendEmail") -const saveRecord = require("./steps/saveRecord") +const createRecord = require("./steps/createRecord") const updateRecord = require("./steps/updateRecord") const deleteRecord = require("./steps/deleteRecord") const createUser = require("./steps/createUser") @@ -17,14 +17,14 @@ const DEFAULT_DIRECTORY = ".budibase-automations" const AUTOMATION_MANIFEST = "manifest.json" const BUILTIN_ACTIONS = { SEND_EMAIL: sendEmail.run, - SAVE_RECORD: saveRecord.run, + CREATE_RECORD: createRecord.run, UPDATE_RECORD: updateRecord.run, DELETE_RECORD: deleteRecord.run, CREATE_USER: createUser.run, } const BUILTIN_DEFINITIONS = { SEND_EMAIL: sendEmail.definition, - SAVE_RECORD: saveRecord.definition, + CREATE_RECORD: createRecord.definition, UPDATE_RECORD: updateRecord.definition, DELETE_RECORD: deleteRecord.definition, CREATE_USER: createUser.definition, diff --git a/packages/server/src/automations/steps/saveRecord.js b/packages/server/src/automations/steps/createRecord.js similarity index 92% rename from packages/server/src/automations/steps/saveRecord.js rename to packages/server/src/automations/steps/createRecord.js index ae99511a7c..379aaa02b4 100644 --- a/packages/server/src/automations/steps/saveRecord.js +++ b/packages/server/src/automations/steps/createRecord.js @@ -2,12 +2,12 @@ const recordController = require("../../api/controllers/record") const automationUtils = require("../automationUtils") module.exports.definition = { - name: "Save Record", - tagline: "Save a {{inputs.enriched.model.name}} record", + name: "Create Record", + tagline: "Create a {{inputs.enriched.model.name}} record", icon: "ri-save-3-fill", - description: "Save a record to your database", + description: "Create a record to your database", type: "ACTION", - stepId: "SAVE_RECORD", + stepId: "CREATE_RECORD", inputs: {}, schema: { inputs: { diff --git a/packages/server/src/automations/steps/filter.js b/packages/server/src/automations/steps/filter.js index d6aa5eb522..4286cd44e8 100644 --- a/packages/server/src/automations/steps/filter.js +++ b/packages/server/src/automations/steps/filter.js @@ -55,7 +55,15 @@ module.exports.definition = { } module.exports.run = async function filter({ inputs }) { - const { field, condition, value } = inputs + let { field, condition, value } = inputs + // coerce types so that we can use them + if (!isNaN(value) && !isNaN(field)) { + value = parseFloat(value) + field = parseFloat(field) + } else if (!isNaN(Date.parse(value)) && !isNaN(Date.parse(field))) { + value = Date.parse(value) + field = Date.parse(field) + } let success if (typeof field !== "object" && typeof value !== "object") { switch (condition) { From be833d66bb41cab14d980e0025ab507e9d1bb60b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 2 Oct 2020 17:02:18 +0100 Subject: [PATCH 2/2] Fixing test case broken by automation save record -> create record. --- packages/server/src/api/routes/tests/automation.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index 804979dac9..52fe59ad29 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -128,14 +128,14 @@ describe("/automations", () => { it("should setup the automation fully", () => { let trigger = TRIGGER_DEFINITIONS["RECORD_SAVED"] trigger.id = "wadiawdo34" - let saveAction = ACTION_DEFINITIONS["SAVE_RECORD"] - saveAction.inputs.record = { + let createAction = ACTION_DEFINITIONS["CREATE_RECORD"] + createAction.inputs.record = { name: "{{trigger.name}}", description: "{{trigger.description}}" } - saveAction.id = "awde444wk" + createAction.id = "awde444wk" - TEST_AUTOMATION.definition.steps.push(saveAction) + TEST_AUTOMATION.definition.steps.push(createAction) TEST_AUTOMATION.definition.trigger = trigger })