From 31cc24d2aad2b5017043b514185cff3a122731d2 Mon Sep 17 00:00:00 2001 From: aScharfe Date: Thu, 19 Dec 2024 15:27:56 +0100 Subject: [PATCH] fixing parameter name and add check --- processinstance-delete.html | 8 ++++---- processinstance-delete.js | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/processinstance-delete.html b/processinstance-delete.html index 6d117cc..82d8c53 100644 --- a/processinstance-delete.html +++ b/processinstance-delete.html @@ -7,7 +7,7 @@ engine: { value: '', type: 'processcube-engine-config' }, modelid: { value: '' }, duration: { value: '', type: 'number' }, - time_unit: { value: 'hours' }, + time_type: { value: 'hours' }, batch_size: { value: '100', type: 'number' }, }, inputs: 1, @@ -37,8 +37,8 @@
- - @@ -55,7 +55,7 @@ ## Inputs : payload.duration (number): The number of given time periods. -: payload.time_unit ('hours' | 'days'): The type of time period to use. +: payload.time_type ('hours' | 'days'): The type of time period to use. : payload.batch_size (number): The number of instances to be deleted simultaneously. (default 100) ## Outputs diff --git a/processinstance-delete.js b/processinstance-delete.js index 8cfa868..9b15364 100644 --- a/processinstance-delete.js +++ b/processinstance-delete.js @@ -18,14 +18,26 @@ module.exports = function (RED) { return; } - const isHours = msg.payload.time_unit - ? msg.payload.time_unit.toLowerCase() === 'hours' - : config.time_unit.toLowerCase() === 'hours'; - const multiplier = isHours ? 1 : 24; - node.log(`Multiplikator: ${multiplier}`); + // Gültige Werte für time_type + const validTimeTypes = ['days', 'hours']; + const timeType = msg.payload.time_type + ? msg.payload.time_type.toLowerCase() + : config.time_type?.toLowerCase(); + + // time_type validieren + if (!timeType || !validTimeTypes.includes(timeType)) { + node.error(`Invalid time_type provided: ${timeType}. Allowed values are 'days' or 'hours'.`); + return; + } + + // Zeitmultiplikator berechnen + const multiplier = timeType === 'hours' ? 1 : 24; + node.log(`Time type: ${timeType}, multiplier: ${multiplier}`); + const deletionDate = new Date(Date.now() - timeToUse * multiplier * 60 * 60 * 1000); node.log(`Errechnetes Datum: ${deletionDate}`); const modelId = msg.payload.processModelId?.trim() || config.modelid?.trim(); + if (!modelId) { node.error('processModelId is not defined or empty.'); return;