@cocreate/mongodb 1.17.6 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.js +37 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.18.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.6...v1.18.0) (2024-04-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* handle date queries ([7d437f2](https://github.com/CoCreate-app/CoCreate-mongodb/commit/7d437f28a98b1c89066a7be3885cba137a524d65))
|
|
7
|
+
|
|
1
8
|
## [1.17.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.5...v1.17.6) (2024-02-20)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -632,8 +632,43 @@ async function createFilter(data, arrayObj) {
|
|
|
632
632
|
let query = {}, sort = {}, index = 0, limit = 0, count
|
|
633
633
|
|
|
634
634
|
if (data.$filter) {
|
|
635
|
-
|
|
636
|
-
|
|
635
|
+
function convertIfDate(value) {
|
|
636
|
+
if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/)) {
|
|
637
|
+
return new Date(value);
|
|
638
|
+
}
|
|
639
|
+
return value;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (data.$filter.query) {
|
|
643
|
+
for (let key in data.$filter.query) {
|
|
644
|
+
if (Array.isArray(data.$filter.query[key])) {
|
|
645
|
+
// Handle $or operator with an array of conditions
|
|
646
|
+
query[key] = data.$filter.query[key].map(condition => {
|
|
647
|
+
let newCondition = {};
|
|
648
|
+
for (let subKey in condition) {
|
|
649
|
+
if (typeof condition[subKey] === 'object' && condition[subKey] !== null) {
|
|
650
|
+
newCondition[subKey] = {};
|
|
651
|
+
for (let subCondition in condition[subKey]) {
|
|
652
|
+
newCondition[subKey][subCondition] = convertIfDate(condition[subKey][subCondition]);
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
newCondition[subKey] = convertIfDate(condition[subKey]);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return newCondition;
|
|
659
|
+
});
|
|
660
|
+
} else if (typeof data.$filter.query[key] === 'object' && data.$filter.query[key] !== null) {
|
|
661
|
+
// Handle general object conditions
|
|
662
|
+
query[key] = {};
|
|
663
|
+
for (let condition in data.$filter.query[key]) {
|
|
664
|
+
query[key][condition] = convertIfDate(data.$filter.query[key][condition]);
|
|
665
|
+
}
|
|
666
|
+
} else {
|
|
667
|
+
// Handle direct values
|
|
668
|
+
query[key] = convertIfDate(data.$filter.query[key]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
637
672
|
|
|
638
673
|
if (data.$filter.sort) {
|
|
639
674
|
for (let i = 0; i < data.$filter.sort.length; i++) {
|