Skip to content

Commit

Permalink
🐛 Fix errors and remove overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
pemontto committed Jul 3, 2022
1 parent 5172c86 commit ac4d37d
Showing 1 changed file with 10 additions and 41 deletions.
51 changes: 10 additions & 41 deletions packages/nodes-base/nodes/Redis/Redis.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,7 @@ export class Redis implements INodeType {
},
},
default: false,
description: 'Whether to operate on data at the tail of the list',
},
{
displayName: 'Overwrite',
name: 'overwrite',
type: 'boolean',
displayOptions: {
show: {
operation: [
'pop',
],
},
},
default: false,
description: 'Whether to overwrite item data with returned data',
description: 'Whether to push or pop data from the end of the list',
},
{
displayName: 'Name',
Expand All @@ -509,9 +495,6 @@ export class Redis implements INodeType {
operation: [
'pop',
],
overwrite: [
false,
],
},
},
default: 'data',
Expand All @@ -526,9 +509,6 @@ export class Redis implements INodeType {
operation: [
'pop',
],
overwrite: [
false,
],
},
},
placeholder: 'Add Option',
Expand Down Expand Up @@ -773,42 +753,31 @@ export class Redis implements INodeType {
const redisList = this.getNodeParameter('list', itemIndex) as string;
const messageData = this.getNodeParameter('messageData', itemIndex) as string;
const tail = this.getNodeParameter('tail', itemIndex, false) as boolean;

const action = tail ? client.rpushx : client.lpushx;
const action = tail ? client.RPUSH : client.LPUSH;
const clientPush = util.promisify(action).bind(client);

// @ts-ignore: typescript not understanding generic function signatures
await clientPush(redisList, messageData);
throw Error;
returnItems.push(items[itemIndex]);
} else if (operation === 'pop'){
const redisList = this.getNodeParameter('list', itemIndex) as string;
const tail = this.getNodeParameter('tail', itemIndex, false) as boolean;
const overwrite = this.getNodeParameter('overwrite', itemIndex, false) as boolean;
const propertyName = this.getNodeParameter('propertyName', itemIndex, 'data') as string;

const action = tail ? client.rpop : client.lpop;
const clientPush = util.promisify(action).bind(client);
const value = await clientPush(redisList);

let valueJSON;
let outputValue;
try {
valueJSON = JSON.parse(value);
outputValue = JSON.parse(value);
} catch {
valueJSON = undefined;
outputValue = value;
}
if (overwrite) {
if (valueJSON) {
item = {json: valueJSON};
} else {
item = {json: {data: value}};
}
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
if (options.dotNotation === false) {
item.json[propertyName] = outputValue;
} else {
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
if (options.dotNotation === false) {
item.json[propertyName] = valueJSON ? valueJSON : value;
} else {
set(item.json, propertyName, valueJSON ? valueJSON : value);
}
set(item.json, propertyName, outputValue);
}
returnItems.push(item);
}
Expand Down

0 comments on commit ac4d37d

Please sign in to comment.