Skip to content

Commit

Permalink
Merge pull request #177 from sliit-foss/fix/filter-query-object-id-pa…
Browse files Browse the repository at this point in the history
…rsing

Fix(filter-query): added automatic parsing of object ids
  • Loading branch information
Akalanka47000 authored Apr 14, 2024
2 parents 55802c4 + fad5b35 commit e948d14
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
63 changes: 33 additions & 30 deletions packages/mongoose-filter-query/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
{
"name": "@sliit-foss/mongoose-filter-query",
"version": "5.0.0",
"description": "Middleware which implements a standardized format and maps an incoming http request's query params to a format which is supported by mongoose",
"main": "dist/index.js",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/mongoose-filter-query",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "bash ../../scripts/test/test.sh"
},
"author": "SLIIT FOSS",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/sliit-foss/npm-catalogue.git"
},
"homepage": "https://github.com/sliit-foss/npm-catalogue/blob/main/packages/mongoose-filter-query/readme.md",
"keywords": [
"filterquery",
"sortquery",
"filter",
"sort"
],
"bugs": {
"url": "https://github.com/sliit-foss/npm-catalogue/issues"
}
}
{
"name": "@sliit-foss/mongoose-filter-query",
"version": "5.0.0",
"description": "Middleware which implements a standardized format and maps an incoming http request's query params to a format which is supported by mongoose",
"main": "dist/index.js",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/mongoose-filter-query",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "bash ../../scripts/test/test.sh"
},
"peerDependencies": {
"bson": ">=4"
},
"author": "SLIIT FOSS",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/sliit-foss/npm-catalogue.git"
},
"homepage": "https://github.com/sliit-foss/npm-catalogue/blob/main/packages/mongoose-filter-query/readme.md",
"keywords": [
"filterquery",
"sortquery",
"filter",
"sort"
],
"bugs": {
"url": "https://github.com/sliit-foss/npm-catalogue/issues"
}
}
3 changes: 3 additions & 0 deletions packages/mongoose-filter-query/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const replaceOperator = (value, operator) => {
if (isNaN(value)) {
if (!isNaN(Date.parse(value))) {
value = new Date(value);
} else if (/^[0-9a-fA-F]{24}$/.test(value)) {
const ObjectId = require("bson").ObjectId;
value = new ObjectId(value);
}
} else {
value = Number(value);
Expand Down
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e948d14

Please sign in to comment.