File tree 4 files changed +30
-6
lines changed 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 6
6
7
7
* CLI option ` -q/--quied `
8
8
* Nested route ` POST /posts/1/comments `
9
+ * Not equal operator ` GET /posts?id_ne=1 `
9
10
10
11
## [ 0.8.2] [ 2015-10-15 ]
11
12
Original file line number Diff line number Diff line change @@ -98,14 +98,20 @@ GET /posts?_sort=views&_order=DESC
98
98
GET /posts/1/comments?_sort=votes&_order=ASC
99
99
```
100
100
101
- ### Range
101
+ ### Operators
102
102
103
- Add ` _gte ` or ` _lte `
103
+ Add ` _gte ` or ` _lte ` for getting a range
104
104
105
105
```
106
106
GET /posts?views_gte=10&views_lte=20
107
107
```
108
108
109
+ Add ` _ne ` to exclude a value
110
+
111
+ ```
112
+ GET /posts?id_ne=1
113
+ ```
114
+
109
115
### Full-text search
110
116
111
117
Add ` q `
Original file line number Diff line number Diff line change @@ -73,7 +73,8 @@ module.exports = function (db, name) {
73
73
query === 'callback' ||
74
74
query === '_' ||
75
75
query . indexOf ( '_lte' ) !== - 1 ||
76
- query . indexOf ( '_gte' ) !== - 1
76
+ query . indexOf ( '_gte' ) !== - 1 ||
77
+ query . indexOf ( '_ne' ) !== - 1
77
78
) return
78
79
}
79
80
delete req . query [ query ]
@@ -106,17 +107,23 @@ module.exports = function (db, name) {
106
107
return arr
107
108
. map ( utils . toNative )
108
109
. map ( function ( value ) {
110
+ var isDifferent = key . indexOf ( '_ne' ) !== - 1
109
111
var isRange = key . indexOf ( '_lte' ) !== - 1 || key . indexOf ( '_gte' ) !== - 1
112
+ var path = key . replace ( / ( _ l t e | _ g t e | _ n e ) $ / , '' )
113
+ var elementValue
114
+
110
115
if ( isRange ) {
111
- var path = key . replace ( / ( _ l t e | _ g t e ) $ / , '' )
112
116
var isLowerThan = key . indexOf ( '_gte' ) !== - 1
113
- var elementValue = _ . get ( element , path )
117
+ elementValue = _ . get ( element , path )
114
118
115
119
if ( isLowerThan ) {
116
120
return value <= elementValue
117
121
} else {
118
122
return value >= elementValue
119
123
}
124
+ } else if ( isDifferent ) {
125
+ elementValue = _ . get ( element , path )
126
+ return value !== elementValue
120
127
} else {
121
128
return _ . matchesProperty ( key , value ) ( element )
122
129
}
Original file line number Diff line number Diff line change @@ -224,7 +224,7 @@ describe('Server', function () {
224
224
} )
225
225
} )
226
226
227
- describe ( 'GET /:resource?attr>=&attr< =' , function ( ) {
227
+ describe ( 'GET /:resource?attr_gte=&attr_lte =' , function ( ) {
228
228
it ( 'should respond with a limited array' , function ( done ) {
229
229
request ( server )
230
230
. get ( '/comments?id_gte=2&id_lte=3' )
@@ -234,6 +234,16 @@ describe('Server', function () {
234
234
} )
235
235
} )
236
236
237
+ describe ( 'GET /:resource?attr_ne=' , function ( ) {
238
+ it ( 'should respond with a limited array' , function ( done ) {
239
+ request ( server )
240
+ . get ( '/comments?id_ne=1' )
241
+ . expect ( 'Content-Type' , / j s o n / )
242
+ . expect ( db . comments . slice ( 1 ) )
243
+ . expect ( 200 , done )
244
+ } )
245
+ } )
246
+
237
247
describe ( 'GET /:parent/:parentId/:resource' , function ( ) {
238
248
it ( 'should respond with json and corresponding nested resources' , function ( done ) {
239
249
request ( server )
You can’t perform that action at this time.
0 commit comments