Skip to content

Commit 86f1e74

Browse files
committed
fix: sum handling
1 parent 1276f2d commit 86f1e74

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,12 @@ async function filterData(element, data, type, key) {
480480
}
481481
let docValue = getValueFromObject(doc, property);
482482
if (docValue) {
483-
if (Array.isArray(docValue)) Data.push(...docValue);
484-
else {
483+
if (operator === "$sum" && typeof docValue === "number") {
484+
if (typeof value !== "number") value = 0;
485+
value += docValue;
486+
} else if (Array.isArray(docValue)) {
487+
Data.push(...docValue);
488+
} else {
485489
isObject = true;
486490
Data.push(docValue);
487491
}
@@ -496,11 +500,11 @@ async function filterData(element, data, type, key) {
496500
// data = { [property]: Data[0] }
497501
// } else
498502
if (!operator) data = Data;
499-
else if (operator === "$sum") {
500-
value = Data.reduce((accumulator, currentValue) => {
501-
return accumulator + currentValue;
502-
}, 0);
503-
}
503+
// else if (operator === "$sum") {
504+
// value = data[type].reduce((accumulator, currentValue) => {
505+
// return accumulator + currentValue;
506+
// }, 0);
507+
// }
504508
} else {
505509
data = { [property]: data[type][property] };
506510
}

0 commit comments

Comments
 (0)