From d3e50fab14ea21c69bddf445bfdba73e248d28f5 Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Thu, 8 Feb 2024 12:21:08 +0530 Subject: [PATCH] Fix!: filter query date parsing --- packages/mongoose-filter-query/src/utils.js | 8 +++++++- packages/mongoose-filter-query/test/__mocks.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/mongoose-filter-query/src/utils.js b/packages/mongoose-filter-query/src/utils.js index 162b4d4..6abd741 100644 --- a/packages/mongoose-filter-query/src/utils.js +++ b/packages/mongoose-filter-query/src/utils.js @@ -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) => { diff --git a/packages/mongoose-filter-query/test/__mocks.js b/packages/mongoose-filter-query/test/__mocks.js index 89cc3c7..8e2f0c0 100644 --- a/packages/mongoose-filter-query/test/__mocks.js +++ b/packages/mongoose-filter-query/test/__mocks.js @@ -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"