advanced-results
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -13,4 +13,8 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var mongoose_1 = require("mongoose"); | ||
var isObjectIdCustom_1 = __importDefault(require("../../utils/isObjectIdCustom")); | ||
var escapeStringRegexp = require('escape-string-regexp'); | ||
var BazeQueryFormatter = /** @class */ (function () { | ||
@@ -37,5 +41,4 @@ function BazeQueryFormatter(model) { | ||
if (_this.paths[path].$embeddedSchemaType.instance === 'ObjectID') { | ||
var valueWithoutSpace_1 = value.replace(' ', ''); | ||
if (mongoose_1.isValidObjectId(valueWithoutSpace_1)) { | ||
return _a = {}, _a[path] = valueWithoutSpace_1, _a; | ||
if (isObjectIdCustom_1.default(value)) { | ||
return _a = {}, _a[path] = value, _a; | ||
} | ||
@@ -56,5 +59,5 @@ } | ||
if (typeof value === 'string' && !Number.isInteger(+value)) { | ||
console.log(Number.isInteger(value)); | ||
debugger; | ||
return _c = {}, _c[path] = { $regex: value, $options: 'i' }, _c; | ||
return _c = {}, | ||
_c[path] = { $regex: escapeStringRegexp(value), $options: 'i' }, | ||
_c; | ||
} | ||
@@ -69,5 +72,4 @@ return false; | ||
// isValidObjectId returns true for ('test t') for some reason. But when i merge them together into testt it causes no problems | ||
var valueWithoutSpace = value.replace(' ', ''); | ||
if (mongoose_1.isValidObjectId(value.replace(valueWithoutSpace))) { | ||
return _d = {}, _d[path] = valueWithoutSpace, _d; | ||
if (isObjectIdCustom_1.default(value)) { | ||
return _d = {}, _d[path] = value, _d; | ||
} | ||
@@ -74,0 +76,0 @@ return false; |
{ | ||
"name": "advanced-results", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "Advanced query middleware for expressjs and mongoose", | ||
@@ -47,3 +47,6 @@ "main": "dist/index.js", | ||
"mongoose": "5.x" | ||
}, | ||
"dependencies": { | ||
"escape-string-regexp": "^4.0.0" | ||
} | ||
} |
@@ -269,3 +269,3 @@ **Middleware** used for advanced querying Mongoose Documents for a specific Model through GET request using the queries and parameters provided by the URL . **It only works with MongoDB (mongoose) and expressjs**. Furthermore, it includes **pagination** | ||
| **select** | selects single or multiple fields from a document, example.com?select=field or multiple example.com?select=field1,field2 | | ||
| **sort** | Default field: createdAt, example.com?sort=field. **Field can be ?sort=name (ASC Order) or ?sort=-name (DSC Order)** | | ||
| **sort** | Default field: createdAt, example.com?sort=field. **Field can be ?sort=name (ASC Order) or ?sort=-name (DSC Order)** or **?sort=randomNum,-name** (sorting multiple fields) | | ||
| **limit** | **default: 6**, used for **limiting documents** affects pagination object inside res.advancedResults, example.com?limit=5 | | ||
@@ -272,0 +272,0 @@ | **page** | **default: 1**, the current page (if there are multiple pages), this goes together with ?limit, and depending on the ?page and ?limit values it calculates and displays the current pagination properties inside res.advancedResults, ex. example.com?page=2 | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63049
35
513
3
+ Addedescape-string-regexp@^4.0.0
+ Addedescape-string-regexp@4.0.0(transitive)