From 68062b969b7051c9b0ce5238421183403996ec9a Mon Sep 17 00:00:00 2001 From: Junyi Date: Mon, 20 Feb 2023 23:40:15 +0800 Subject: [PATCH] fix(plugin-workflow): fix migration for calculation (#1476) --- .../20230122071831-calculation-expression.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/plugins/workflow/src/server/migrations/20230122071831-calculation-expression.ts b/packages/plugins/workflow/src/server/migrations/20230122071831-calculation-expression.ts index c6281e0ac..e3410c2e7 100644 --- a/packages/plugins/workflow/src/server/migrations/20230122071831-calculation-expression.ts +++ b/packages/plugins/workflow/src/server/migrations/20230122071831-calculation-expression.ts @@ -27,40 +27,41 @@ const calculatorsMap = { 'divide': '/', 'mod': '%', includes(a, b) { - return `SEARCH(${addQuote(b)}, ${addQuote(a)}) >= 0`; + return `SEARCH(${b}, ${a}) >= 0`; }, notIncludes(a, b) { - return `SEARCH(${addQuote(b)}, ${addQuote(a)}) < 0`; + return `SEARCH(${b}, ${a}) < 0`; }, startsWith(a, b) { - return `SEARCH(${addQuote(b)}, ${addQuote(a)}) == 0` + return `SEARCH(${b}, ${a}) == 0` }, endsWith(a, b) { - return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) == ${addQuote(b)}`; + return `RIGHT(${a}, LEN(${b})) == ${b}`; }, notStartsWith(a, b) { - return `SEARCH(${addQuote(b)}, ${addQuote(a)}) != 0`; + return `SEARCH(${b}, ${a}) != 0`; }, notEndsWith(a, b) { - return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) != ${addQuote(b)}`; + return `RIGHT(${a}, LEN(${b})) != ${b}`; }, concat(a, b) { - return `CONCATENATE(${addQuote(a)}, ${addQuote(b)})`; + return `CONCATENATE(${a}, ${b})`; } } function migrateConfig({ calculation }) { - if (!calculation?.calculator || !calculation?.operands) { + if (!calculation?.calculator || !calculation?.operands?.length) { return {}; } const calculator = calculatorsMap[calculation.calculator]; + const operands = calculator.operands.map(operand => addQuote(operand)); return { engine: 'formula.js', expression: typeof calculator === 'function' - ? calculator(...calculation.operands) - : calculation.operands.join(` ${calculator ?? calculation.calculator} `) + ? calculator(...operands) + : operands.join(` ${calculator ?? calculation.calculator} `) } }