Skip to content

Commit

Permalink
Merge pull request #144 from sliit-foss/fix/filter-query-d
Browse files Browse the repository at this point in the history
Fix!: filter query date parsing
  • Loading branch information
Akalanka47000 authored Feb 8, 2024
2 parents b29ee1e + 478ccd0 commit b82e4ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/mongoose-filter-query/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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);
}
return 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 b82e4ca

Please sign in to comment.