Skip to content

Commit

Permalink
fixing parameter name and add check
Browse files Browse the repository at this point in the history
  • Loading branch information
aScharfe committed Dec 19, 2024
1 parent babe1e1 commit 31cc24d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions processinstance-delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,8 +37,8 @@
<input type="text" id="node-input-duration" />
</div>
<div class="form-row">
<label for="node-input-time_unit"><i class="fa fa-sliders"></i> Time Unit</label>
<select id="node-input-time_unit" style="width: 70%;">
<label for="node-input-time_type"><i class="fa fa-sliders"></i> Time Unit</label>
<select id="node-input-time_type" style="width: 70%;">
<option value="hours">Hours</option>
<option value="days">Days</option>
</select>
Expand All @@ -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
Expand Down
22 changes: 17 additions & 5 deletions processinstance-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 31cc24d

Please sign in to comment.