express-ext 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/search.js +35 -4
- package/package.json +1 -1
- package/src/search.ts +34 -2
package/lib/search.js
CHANGED
|
@@ -61,8 +61,8 @@ function getLimit(req, filter) {
|
|
|
61
61
|
if (filter) {
|
|
62
62
|
var v0 = filter[resources_1.resources.limit]
|
|
63
63
|
if (v0 == undefined) {
|
|
64
|
-
var
|
|
65
|
-
var v_2 =
|
|
64
|
+
var field_2 = req.query[resources_1.resources.limit]
|
|
65
|
+
var v_2 = field_2 ? field_2.toString() : undefined
|
|
66
66
|
if (!v_2 || v_2.length === 0) {
|
|
67
67
|
filter[resources_1.resources.limit] = resources_1.resources.defaultLimit
|
|
68
68
|
return resources_1.resources.defaultLimit
|
|
@@ -87,8 +87,8 @@ function getLimit(req, filter) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
var
|
|
91
|
-
var v =
|
|
90
|
+
var field = req.query[resources_1.resources.limit]
|
|
91
|
+
var v = field ? field.toString() : undefined
|
|
92
92
|
if (!v || v.length === 0) {
|
|
93
93
|
if (filter) {
|
|
94
94
|
filter[resources_1.resources.limit] = resources_1.resources.defaultLimit
|
|
@@ -437,6 +437,37 @@ function initializeConfig(conf) {
|
|
|
437
437
|
exports.initializeConfig = initializeConfig
|
|
438
438
|
function fromRequest(req, arr) {
|
|
439
439
|
var s = req.method === "GET" ? fromUrl(req, arr) : req.body
|
|
440
|
+
var page = s[resources_1.resources.page]
|
|
441
|
+
if (page) {
|
|
442
|
+
if (isNaN(page)) {
|
|
443
|
+
s[resources_1.resources.page] = 1
|
|
444
|
+
} else {
|
|
445
|
+
var n = parseFloat(page)
|
|
446
|
+
if (n < 1) {
|
|
447
|
+
n = 1
|
|
448
|
+
}
|
|
449
|
+
s[resources_1.resources.page] = n
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
s[resources_1.resources.page] = 1
|
|
453
|
+
}
|
|
454
|
+
var limit = s[resources_1.resources.limit]
|
|
455
|
+
if (limit) {
|
|
456
|
+
if (isNaN(page)) {
|
|
457
|
+
s[resources_1.resources.limit] = resources_1.resources.defaultLimit
|
|
458
|
+
} else {
|
|
459
|
+
var n = parseFloat(limit)
|
|
460
|
+
if (n < 1) {
|
|
461
|
+
n = resources_1.resources.defaultLimit
|
|
462
|
+
}
|
|
463
|
+
s[resources_1.resources.page] = n
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
s[resources_1.resources.limit] = resources_1.resources.defaultLimit
|
|
467
|
+
}
|
|
468
|
+
if (resources_1.resources.partial.length > 0) {
|
|
469
|
+
delete s[resources_1.resources.partial]
|
|
470
|
+
}
|
|
440
471
|
return s
|
|
441
472
|
}
|
|
442
473
|
exports.fromRequest = fromRequest
|
package/package.json
CHANGED
package/src/search.ts
CHANGED
|
@@ -120,8 +120,8 @@ export function getLimit<F extends Filter>(req: Request, filter?: F): number {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
const v =
|
|
123
|
+
const field = req.query[resources.limit]
|
|
124
|
+
const v = field ? field.toString() : undefined
|
|
125
125
|
if (!v || v.length === 0) {
|
|
126
126
|
if (filter) {
|
|
127
127
|
;(filter as any)[resources.limit] = resources.defaultLimit
|
|
@@ -450,6 +450,38 @@ export function initializeConfig(conf?: SearchConfig): SearchConfig | undefined
|
|
|
450
450
|
}
|
|
451
451
|
export function fromRequest<S>(req: Request, arr?: string[]): S {
|
|
452
452
|
const s: any = req.method === "GET" ? fromUrl(req, arr) : req.body
|
|
453
|
+
const page = s[resources.page]
|
|
454
|
+
if (page) {
|
|
455
|
+
if (isNaN(page as any)) {
|
|
456
|
+
s[resources.page] = 1
|
|
457
|
+
} else {
|
|
458
|
+
let n = parseFloat(page)
|
|
459
|
+
if (n < 1) {
|
|
460
|
+
n = 1
|
|
461
|
+
}
|
|
462
|
+
s[resources.page] = n
|
|
463
|
+
}
|
|
464
|
+
} else {
|
|
465
|
+
s[resources.page] = 1
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const limit = s[resources.limit]
|
|
469
|
+
if (limit) {
|
|
470
|
+
if (isNaN(page as any)) {
|
|
471
|
+
s[resources.limit] = resources.defaultLimit
|
|
472
|
+
} else {
|
|
473
|
+
let n = parseFloat(limit)
|
|
474
|
+
if (n < 1) {
|
|
475
|
+
n = resources.defaultLimit
|
|
476
|
+
}
|
|
477
|
+
s[resources.page] = n
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
s[resources.limit] = resources.defaultLimit
|
|
481
|
+
}
|
|
482
|
+
if (resources.partial.length > 0) {
|
|
483
|
+
delete s[resources.partial]
|
|
484
|
+
}
|
|
453
485
|
return s
|
|
454
486
|
}
|
|
455
487
|
export function buildArray(arr?: string[], s0?: string, s1?: string, s2?: string): string[] {
|