mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Summarize Node): Preserves original field data type (#13069)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { isNaN } from 'lodash';
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
type IDataObject,
|
||||
@@ -287,3 +288,38 @@ export function aggregationToArray(
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
|
||||
const getOriginalFieldValue = (field: string | number) =>
|
||||
field === 'null' ? null : isNaN(Number(field)) ? field : Number(field);
|
||||
|
||||
export function aggregationToArrayWithOriginalTypes(
|
||||
aggregationResult: IDataObject,
|
||||
fieldsToSplitBy: string[],
|
||||
previousStage: IDataObject = {},
|
||||
) {
|
||||
const returnData: IDataObject[] = [];
|
||||
fieldsToSplitBy = parseFieldName(fieldsToSplitBy);
|
||||
const splitFieldName = fieldsToSplitBy[0];
|
||||
const isNext = fieldsToSplitBy[1];
|
||||
|
||||
if (isNext === undefined) {
|
||||
for (const fieldName of Object.keys(aggregationResult)) {
|
||||
returnData.push({
|
||||
...previousStage,
|
||||
[splitFieldName]: getOriginalFieldValue(fieldName),
|
||||
...(aggregationResult[fieldName] as IDataObject),
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
} else {
|
||||
for (const key of Object.keys(aggregationResult)) {
|
||||
returnData.push(
|
||||
...aggregationToArray(aggregationResult[key] as IDataObject, fieldsToSplitBy.slice(1), {
|
||||
...previousStage,
|
||||
[splitFieldName]: getOriginalFieldValue(key),
|
||||
}),
|
||||
);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user