fix(Google Calendar Node): Updates and fixes (#10715)

Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
This commit is contained in:
Michael Kret
2025-01-10 11:16:29 +02:00
committed by GitHub
parent 91277c44f1
commit 7227a29845
14 changed files with 1051 additions and 56 deletions

View File

@@ -427,3 +427,37 @@ export function escapeHtml(text: string): string {
}
});
}
/**
* Sorts each item json's keys by a priority list
*
* @param {INodeExecutionData[]} data The array of items which keys will be sorted
* @param {string[]} priorityList The priority list, keys of item.json will be sorted in this order first then alphabetically
*/
export function sortItemKeysByPriorityList(data: INodeExecutionData[], priorityList: string[]) {
return data.map((item) => {
const itemKeys = Object.keys(item.json);
const updatedKeysOrder = itemKeys.sort((a, b) => {
const indexA = priorityList.indexOf(a);
const indexB = priorityList.indexOf(b);
if (indexA !== -1 && indexB !== -1) {
return indexA - indexB;
} else if (indexA !== -1) {
return -1;
} else if (indexB !== -1) {
return 1;
}
return a.localeCompare(b);
});
const updatedItem: IDataObject = {};
for (const key of updatedKeysOrder) {
updatedItem[key] = item.json[key];
}
item.json = updatedItem;
return item;
});
}