File tree 4 files changed +21
-2
lines changed
4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
History
2
2
=======
3
3
4
+ ####2020 -08-04 v0.1.20
5
+ Allow the result to be returned in the $and form even if there is only one condition by passing {forceand: true} in the options @dhendo
6
+
4
7
####2020 -08-04 v0.1.19
5
8
Dependabot upgrade of qs @dhendo
6
9
Original file line number Diff line number Diff line change @@ -156,7 +156,11 @@ module.exports = {
156
156
// Now build the final object
157
157
switch ( conditions . length ) {
158
158
case 1 :
159
- filterQuery = conditions [ 0 ] ;
159
+ if ( options . forceand ) {
160
+ filterQuery . $and = conditions ;
161
+ } else {
162
+ filterQuery = conditions [ 0 ] ;
163
+ }
160
164
break ;
161
165
case 0 :
162
166
break ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " mongo-queryfilter" ,
3
- "version" : " 0.1.19 " ,
3
+ "version" : " 0.1.20 " ,
4
4
"description" : " Safely create a simple mongo query from a querystring collection to allow filtering" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -709,6 +709,18 @@ suite('Date filtering', function () {
709
709
( out . value . $lte * 1 ) . should . be . approximately ( new Date ( ) * 1 , 1000 ) ;
710
710
done ( ) ;
711
711
} ) ;
712
+
713
+
714
+ test ( 'should allow the result to always be returned as a $and' , function ( done ) {
715
+ // define a function that returns an operator $thing, that doubles the value
716
+ // Set for the lifetime of qf
717
+ var out = qf . filter ( 'price=3' , { forceand : true } ) ;
718
+ should . exist ( out ) ;
719
+ out . should . have . property ( '$and' ) ;
720
+ out . $and . should . have . length ( 1 ) ;
721
+ out . $and [ 0 ] . should . have . property ( "price" , "3" ) ;
722
+ done ( ) ;
723
+ } ) ;
712
724
} ) ;
713
725
714
726
suite ( 'The filter values' , function ( ) {
You can’t perform that action at this time.
0 commit comments