Skip to content

Commit

Permalink
fix: handling objectId in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jul 3, 2024
1 parent d9b5556 commit 58c92b2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,16 @@ async function createFilter(data, arrayObj) {
if (typeof condition[subKey] === 'object' && condition[subKey] !== null) {
newCondition[subKey] = {};
for (let subCondition in condition[subKey]) {
newCondition[subKey][subCondition] = convertIfDate(condition[subKey][subCondition]);
if (subKey == "_id")
newCondition[subKey][subCondition] = ObjectId(condition[subKey][subCondition])
else
newCondition[subKey][subCondition] = convertIfDate(condition[subKey][subCondition]);
}
} else {
newCondition[subKey] = convertIfDate(condition[subKey]);
if (subKey == "_id")
newCondition[subKey] = ObjectId(condition[subKey])
else
newCondition[subKey] = convertIfDate(condition[subKey]);
}
}
return newCondition;
Expand All @@ -664,11 +670,17 @@ async function createFilter(data, arrayObj) {
// Handle general object conditions
query[key] = {};
for (let condition in data.$filter.query[key]) {
query[key][condition] = convertIfDate(data.$filter.query[key][condition]);
if (key == "_id")
query[key][condition] = ObjectId(data.$filter.query[key][condition])
else
query[key][condition] = convertIfDate(data.$filter.query[key][condition]);
}
} else {
// Handle direct values
query[key] = convertIfDate(data.$filter.query[key]);
if (key == "_id")
query[key] = ObjectId(data.$filter.query[key])
else
query[key] = convertIfDate(data.$filter.query[key]);
}
}
}
Expand Down

0 comments on commit 58c92b2

Please sign in to comment.