express-ext 0.5.8 → 0.5.9
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/view.js +39 -40
- package/package.json +1 -1
- package/src/view.ts +2 -2
package/lib/view.js
CHANGED
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
3
|
function buildAndCheckId(req, res, keys) {
|
|
4
|
-
var id = buildId(req, keys)
|
|
4
|
+
var id = buildId(req, keys)
|
|
5
5
|
if (!id) {
|
|
6
|
-
res.status(400).end(
|
|
7
|
-
return undefined
|
|
6
|
+
res.status(400).end("invalid parameters")
|
|
7
|
+
return undefined
|
|
8
8
|
}
|
|
9
|
-
return id
|
|
9
|
+
return id
|
|
10
10
|
}
|
|
11
|
-
exports.buildAndCheckId = buildAndCheckId
|
|
11
|
+
exports.buildAndCheckId = buildAndCheckId
|
|
12
12
|
function buildId(req, attrs) {
|
|
13
13
|
if (!attrs || attrs.length === 0) {
|
|
14
|
-
var id = req.params[
|
|
14
|
+
var id = req.params["id"]
|
|
15
15
|
if (id && id.length > 0) {
|
|
16
|
-
return id
|
|
16
|
+
return id
|
|
17
17
|
}
|
|
18
|
-
return undefined
|
|
18
|
+
return undefined
|
|
19
19
|
}
|
|
20
20
|
if (attrs && attrs.length === 1) {
|
|
21
|
-
var id = req.params[
|
|
22
|
-
var n = attrs[0].name
|
|
21
|
+
var id = req.params["id"]
|
|
22
|
+
var n = attrs[0].name
|
|
23
23
|
if ((!id || id.length === 0) && n && n.length > 0) {
|
|
24
|
-
id = req.params[n]
|
|
24
|
+
id = req.params[n]
|
|
25
25
|
}
|
|
26
26
|
if (id && id.length > 0) {
|
|
27
|
-
if (attrs[0].type ===
|
|
27
|
+
if (attrs[0].type === "integer" || attrs[0].type === "number") {
|
|
28
28
|
if (isNaN(id)) {
|
|
29
|
-
return undefined
|
|
29
|
+
return undefined
|
|
30
30
|
}
|
|
31
|
-
var v = parseFloat(id)
|
|
32
|
-
return v
|
|
31
|
+
var v = parseFloat(id)
|
|
32
|
+
return v
|
|
33
33
|
}
|
|
34
|
-
return id
|
|
34
|
+
return id
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
var ids = {}
|
|
37
|
+
var ids = {}
|
|
38
38
|
for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
|
|
39
|
-
var attr = attrs_1[_i]
|
|
39
|
+
var attr = attrs_1[_i]
|
|
40
40
|
if (!attr.name) {
|
|
41
|
-
return undefined
|
|
41
|
+
return undefined
|
|
42
42
|
}
|
|
43
|
-
var v = req.params[attr.name]
|
|
43
|
+
var v = req.params[attr.name]
|
|
44
44
|
if (!v) {
|
|
45
|
-
return undefined
|
|
45
|
+
return undefined
|
|
46
46
|
}
|
|
47
|
-
if (attr.type ===
|
|
47
|
+
if (attr.type === "integer" || attr.type === "number") {
|
|
48
48
|
if (isNaN(v)) {
|
|
49
|
-
return undefined
|
|
49
|
+
return undefined
|
|
50
50
|
}
|
|
51
|
-
ids[attr.name] = parseFloat(v)
|
|
51
|
+
ids[attr.name] = parseFloat(v)
|
|
52
|
+
} else {
|
|
53
|
+
ids[attr.name] = v
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
ids[attr.name] = v;
|
|
55
|
-
}
|
|
56
|
-
return ids;
|
|
55
|
+
return ids
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
exports.buildId = buildId
|
|
58
|
+
exports.buildId = buildId
|
|
60
59
|
function buildKeys(attrs) {
|
|
61
60
|
if (!attrs) {
|
|
62
|
-
return undefined
|
|
61
|
+
return undefined
|
|
63
62
|
}
|
|
64
|
-
var keys = Object.keys(attrs)
|
|
65
|
-
var ats = []
|
|
63
|
+
var keys = Object.keys(attrs)
|
|
64
|
+
var ats = []
|
|
66
65
|
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
67
|
-
var key = keys_1[_i]
|
|
68
|
-
var attr = attrs[key]
|
|
66
|
+
var key = keys_1[_i]
|
|
67
|
+
var attr = attrs[key]
|
|
69
68
|
if (attr) {
|
|
70
69
|
if (attr.key === true) {
|
|
71
|
-
var at = { name: key, type: attr.type }
|
|
72
|
-
ats.push(at)
|
|
70
|
+
var at = { name: key, type: attr.type }
|
|
71
|
+
ats.push(at)
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
return ats
|
|
75
|
+
return ats
|
|
77
76
|
}
|
|
78
|
-
exports.buildKeys = buildKeys
|
|
77
|
+
exports.buildKeys = buildKeys
|
package/package.json
CHANGED
package/src/view.ts
CHANGED
|
@@ -11,14 +11,14 @@ export function buildAndCheckId<ID>(req: Request, res: Response, keys?: Attribut
|
|
|
11
11
|
}
|
|
12
12
|
export function buildId<T>(req: Request, attrs?: Attribute[]): T | undefined {
|
|
13
13
|
if (!attrs || attrs.length === 0) {
|
|
14
|
-
const id = req.params["id"]
|
|
14
|
+
const id = req.params["id"] as string
|
|
15
15
|
if (id && id.length > 0) {
|
|
16
16
|
return id as any
|
|
17
17
|
}
|
|
18
18
|
return undefined
|
|
19
19
|
}
|
|
20
20
|
if (attrs && attrs.length === 1) {
|
|
21
|
-
let id = req.params["id"]
|
|
21
|
+
let id = req.params["id"] as string
|
|
22
22
|
const n = attrs[0].name
|
|
23
23
|
if ((!id || id.length === 0) && n && n.length > 0) {
|
|
24
24
|
id = req.params[n]
|