express-ext 0.4.0 → 0.4.2

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/src/view.ts CHANGED
@@ -1,73 +1,73 @@
1
- import {Request, Response} from 'express';
2
- import {Attribute, Attributes} from './metadata';
1
+ import { Request, Response } from "express"
2
+ import { Attribute, Attributes } from "./metadata"
3
3
 
4
4
  export function buildAndCheckId<ID>(req: Request, res: Response, keys?: Attribute[]): ID | undefined {
5
- const id = buildId<ID>(req, keys);
5
+ const id = buildId<ID>(req, keys)
6
6
  if (!id) {
7
- res.status(400).end('invalid parameters');
8
- return undefined;
7
+ res.status(400).end("invalid parameters")
8
+ return undefined
9
9
  }
10
- return id;
10
+ return id
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"]
15
15
  if (id && id.length > 0) {
16
- return id as any;
16
+ return id as any
17
17
  }
18
- return undefined;
18
+ return undefined
19
19
  }
20
20
  if (attrs && attrs.length === 1) {
21
- let id = req.params['id'];
22
- const n = attrs[0].name;
21
+ let id = req.params["id"]
22
+ const 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 === 'integer' || attrs[0].type === 'number') {
27
+ if (attrs[0].type === "integer" || attrs[0].type === "number") {
28
28
  if (isNaN(id as any)) {
29
- return undefined;
29
+ return undefined
30
30
  }
31
- const v = parseFloat(id);
32
- return v as any;
31
+ const v = parseFloat(id)
32
+ return v as any
33
33
  }
34
- return id as any;
34
+ return id as any
35
35
  }
36
36
  }
37
- const ids: any = {};
37
+ const ids: any = {}
38
38
  for (const attr of attrs) {
39
39
  if (!attr.name) {
40
- return undefined;
40
+ return undefined
41
41
  }
42
- const v = req.params[attr.name];
42
+ const v = req.params[attr.name]
43
43
  if (!v) {
44
- return undefined;
44
+ return undefined
45
45
  }
46
- if (attr.type === 'integer' || attr.type === 'number') {
46
+ if (attr.type === "integer" || attr.type === "number") {
47
47
  if (isNaN(v as any)) {
48
- return undefined;
48
+ return undefined
49
49
  }
50
- ids[attr.name] = parseFloat(v);
50
+ ids[attr.name] = parseFloat(v)
51
51
  } else {
52
- ids[attr.name] = v;
52
+ ids[attr.name] = v
53
53
  }
54
- return ids;
54
+ return ids
55
55
  }
56
56
  }
57
57
  export function buildKeys(attrs: Attributes): Attribute[] | undefined {
58
58
  if (!attrs) {
59
- return undefined;
59
+ return undefined
60
60
  }
61
- const keys: string[] = Object.keys(attrs);
62
- const ats: Attribute[] = [];
61
+ const keys: string[] = Object.keys(attrs)
62
+ const ats: Attribute[] = []
63
63
  for (const key of keys) {
64
- const attr: Attribute = attrs[key];
64
+ const attr: Attribute = attrs[key]
65
65
  if (attr) {
66
66
  if (attr.key === true) {
67
- const at: Attribute = {name: key, type: attr.type};
68
- ats.push(at);
67
+ const at: Attribute = { name: key, type: attr.type }
68
+ ats.push(at)
69
69
  }
70
70
  }
71
71
  }
72
- return ats;
72
+ return ats
73
73
  }