express-query-params
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -33,2 +33,3 @@ const format = require('../lib/format') | ||
else if (format.isLesserThanOrEqual(value)) mongo[key] = { $lte: insertValue } | ||
else if (format.oneOf(value)) mongo[key] = { $in: value.split(',') } | ||
else if (format.isRange(value)) { | ||
@@ -35,0 +36,0 @@ const [ from, to ] = value.split('...') |
@@ -39,2 +39,12 @@ const format = require('../lib/format') | ||
if (format.oneOf(value)) { | ||
const oneOf = value.split(',').map(v => cast(v)) | ||
const inArguments = oneOf.map((_, i) => `$${values.length + i + 1}`).join(', ') | ||
values.push(...oneOf) | ||
clauses.push(`${key} IN (${inArguments})`) | ||
continue | ||
} | ||
let clause = '' | ||
@@ -41,0 +51,0 @@ let insertValue = cast(trimOperators(value)) |
@@ -8,2 +8,3 @@ const stringContains = raw => raw[0] === '*' || raw[raw.length - 1] === '*' | ||
const isLesserThanOrEqual = raw => raw.slice(0, 2) === '<=' | ||
const oneOf = raw => raw.indexOf(',') > -1 | ||
@@ -17,3 +18,4 @@ module.exports = { | ||
isLesserThan(raw) { return isLesserThan(String(raw)) }, | ||
isLesserThanOrEqual(raw) { return isLesserThanOrEqual(String(raw)) } | ||
isLesserThanOrEqual(raw) { return isLesserThanOrEqual(String(raw)) }, | ||
oneOf(raw) { return oneOf(String(raw)) } | ||
} |
{ | ||
"name": "express-query-params", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Express.js middleware implementing the API Query Spec, converting the params to SQL or a Mongo query", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,3 +25,4 @@ /* global test expect */ | ||
firstName: /Steve$i/, | ||
accountBalance: 25.22 | ||
accountBalance: 25.22, | ||
favouriteColours: { $in: [ 'red', 'green', 'blue' ] } | ||
} | ||
@@ -28,0 +29,0 @@ |
@@ -21,6 +21,9 @@ /* global test expect */ | ||
'Steve', | ||
25.22 | ||
25.22, | ||
'red', | ||
'green', | ||
'blue' | ||
] | ||
const correctQuery = 'username = $1 AND email LIKE $2 AND age >= $3 AND age <= $4 AND boughtSomethingOn >= $5 AND boughtSomethingOn <= $6 AND createdAt > $7 AND updatedAt < $8 AND friends >= $9 AND followers <= $10 AND banned = $11 AND activated = $12 AND firstName ILIKE $13 AND accountBalance = $14' | ||
const correctQuery = 'username = $1 AND email LIKE $2 AND age >= $3 AND age <= $4 AND boughtSomethingOn >= $5 AND boughtSomethingOn <= $6 AND createdAt > $7 AND updatedAt < $8 AND friends >= $9 AND followers <= $10 AND banned = $11 AND activated = $12 AND firstName ILIKE $13 AND accountBalance = $14 AND favouriteColours IN ($15, $16, $17)' | ||
@@ -27,0 +30,0 @@ test('req.query -> SQL', () => { |
@@ -49,1 +49,7 @@ /* global test expect */ | ||
}) | ||
test('oneOf', () => { | ||
for (const param in query) { | ||
expect(format.oneOf(query[param])).toBe(param === 'favouriteColours') | ||
} | ||
}) |
@@ -14,3 +14,4 @@ module.exports = { | ||
accountBalance: '25.22', | ||
favouriteColours: 'red,green,blue', | ||
limit: 10 | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
138564
331
0