Skip to content

Commit

Permalink
Fix!: filter query date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 authored Feb 8, 2024
1 parent b29ee1e commit d3e50fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/mongoose-filter-query/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export const replaceOperator = (value, operator) => {
value = value.replace(`${operator}(`, "").slice(0, -1);
return isNaN(value) ? value : Number(value);
if (isNaN(value)) {
if (!isNaN(Date.parse(value))) {
value = new Date(value)
}
} else {
value = Number(value)
}
};

export const mapValue = (value) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mongoose-filter-query/test/__mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const basicFilterResult = {
address: { $in: ["address1", "address2", "address3"] },
weight: { $gte: 50 },
height: { $lt: 180 },
birthdate: { $lte: "2000-01-01" },
birthdate: { $lte: new Date("2000-01-01") },
isAlive: { $exists: true },
isVerified: { $eq: true },
isDeleted: "false"
Expand Down

0 comments on commit d3e50fa

Please sign in to comment.