File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -4,18 +4,18 @@ function pagination(query, options) {
4
4
result . limit = options . default . pagination . limit
5
5
6
6
if ( query . limit ) {
7
- result . limit = processQuery ( query . limit ) || options . default . pagination . limit
7
+ result . limit = processQuery ( query . limit )
8
8
}
9
9
10
10
if ( options . use_page ) {
11
11
result . page = options . default . pagination . page
12
12
if ( query . page ) {
13
- result . page = processQuery ( query . page ) || options . default . pagination . page
13
+ result . page = processQuery ( query . page )
14
14
}
15
15
} else {
16
16
result . skip = options . default . pagination . skip
17
17
if ( query . skip ) {
18
- result . skip = processQuery ( query . skip ) || options . default . pagination . skip
18
+ result . skip = processQuery ( query . skip )
19
19
}
20
20
}
21
21
@@ -26,9 +26,7 @@ function processQuery(query) {
26
26
if ( query instanceof Array ) {
27
27
query = query [ 0 ]
28
28
}
29
- query = query . replace ( / ( [ ^ \d \s ] ) | ( \s { 1 , } ) / gi, '' )
30
- if ( parseInt ( query ) ) return ( parseInt ( query ) )
31
- return undefined
29
+ return parseInt ( query . replace ( / ( [ ^ \d \s ] ) | ( \s { 1 , } ) / gi, '' ) )
32
30
}
33
31
34
32
exports = module . exports = {
Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ describe('QueryString: Pagination', function () {
164
164
} )
165
165
} )
166
166
167
- context ( 'when use custom options without query with limit and page params' , function ( ) {
167
+ context ( 'when use custom params' , function ( ) {
168
168
it ( 'should return a JSON with custom params' , function ( done ) {
169
169
const custom_options = {
170
170
default : {
@@ -175,12 +175,29 @@ describe('QueryString: Pagination', function () {
175
175
} ,
176
176
use_page : true
177
177
}
178
- const result = pagination . pagination ( { page : 'one' } , custom_options )
178
+ const result = pagination . pagination ( { } , custom_options )
179
179
verifyPage ( result )
180
180
expect ( result . limit ) . to . eql ( 15 )
181
181
expect ( result . page ) . to . eql ( 2 )
182
182
done ( )
183
183
} )
184
+
185
+ it ( 'should return a JSON with custom parameters and those of the query' , function ( done ) {
186
+ const custom_options = {
187
+ default : {
188
+ pagination : {
189
+ limit : 50 ,
190
+ page : 5
191
+ }
192
+ } ,
193
+ use_page : true
194
+ }
195
+ const result = pagination . pagination ( { page : '3' , limit : '10' } , custom_options )
196
+ verifyPage ( result )
197
+ expect ( result . limit ) . to . eql ( 10 )
198
+ expect ( result . page ) . to . eql ( 3 )
199
+ done ( )
200
+ } )
184
201
} )
185
202
} )
186
203
You can’t perform that action at this time.
0 commit comments