mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 20:00:02 +00:00
refactor(Item Lists Node): Delete duplicate code for sorting via code (no-changelog) (#7019)
This commit is contained in:
committed by
GitHub
parent
d6e1cf232f
commit
f02f6b659a
@@ -1,6 +1,3 @@
|
||||
import type { NodeVMOptions } from 'vm2';
|
||||
import { NodeVM } from 'vm2';
|
||||
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
@@ -61,6 +58,7 @@ const shuffleArray = (array: any[]) => {
|
||||
};
|
||||
|
||||
import * as summarize from './summarize.operation';
|
||||
import { sortByCode } from '../V3/helpers/utils';
|
||||
|
||||
export class ItemListsV2 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
@@ -1409,36 +1407,7 @@ return 0;`,
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
const code = this.getNodeParameter('code', 0) as string;
|
||||
const regexCheck = /\breturn\b/g.exec(code);
|
||||
|
||||
if (regexCheck?.length) {
|
||||
const sandbox = {
|
||||
newItems,
|
||||
};
|
||||
const mode = this.getMode();
|
||||
const options = {
|
||||
console: mode === 'manual' ? 'redirect' : 'inherit',
|
||||
sandbox,
|
||||
};
|
||||
const vm = new NodeVM(options as unknown as NodeVMOptions);
|
||||
|
||||
newItems = await vm.run(
|
||||
`
|
||||
module.exports = async function() {
|
||||
newItems.sort( (a,b) => {
|
||||
${code}
|
||||
})
|
||||
return newItems;
|
||||
}()`,
|
||||
__dirname,
|
||||
);
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
"Sort code doesn't return. Please add a 'return' statement to your code",
|
||||
);
|
||||
}
|
||||
newItems = sortByCode.call(this, newItems);
|
||||
}
|
||||
return this.prepareOutputData(newItems);
|
||||
} else if (operation === 'limit') {
|
||||
|
||||
Reference in New Issue
Block a user