express-ext 0.5.14 → 0.5.16
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/resources.js +5 -1
- package/package.json +1 -1
- package/src/http.ts +3 -3
- package/src/index.ts +13 -13
- package/src/resources.ts +8 -2
package/lib/resources.js
CHANGED
|
@@ -22,9 +22,13 @@ var resources = (function () {
|
|
|
22
22
|
exports.resources = resources
|
|
23
23
|
function getView(req, view) {
|
|
24
24
|
var partial = req.query[resources.partial]
|
|
25
|
-
return partial
|
|
25
|
+
return partial === "true" ? resources.pages + "/" + view : view
|
|
26
26
|
}
|
|
27
27
|
exports.getView = getView
|
|
28
|
+
function isPartial(req) {
|
|
29
|
+
return req.query[resources.partial] === "true"
|
|
30
|
+
}
|
|
31
|
+
exports.isPartial = isPartial
|
|
28
32
|
var TypeChecker = (function () {
|
|
29
33
|
function TypeChecker(attributes, allowUndefined) {
|
|
30
34
|
this.attributes = attributes
|
package/package.json
CHANGED
package/src/http.ts
CHANGED
|
@@ -170,11 +170,11 @@ export function param(req: Request, res: Response, name: string): string | undef
|
|
|
170
170
|
res.status(400).end(`'${name}' cannot be empty`)
|
|
171
171
|
return undefined
|
|
172
172
|
}
|
|
173
|
-
return v
|
|
173
|
+
return v as string
|
|
174
174
|
}
|
|
175
175
|
export const getParam = param
|
|
176
176
|
export function params(req: Request, name: string, d?: string[], split?: string): string[] | undefined {
|
|
177
|
-
const v = req.params[name]
|
|
177
|
+
const v = req.params[name] as string
|
|
178
178
|
if (!v || v.length === 0) {
|
|
179
179
|
return d
|
|
180
180
|
}
|
|
@@ -185,7 +185,7 @@ export function params(req: Request, name: string, d?: string[], split?: string)
|
|
|
185
185
|
}
|
|
186
186
|
export const getParams = params
|
|
187
187
|
export function getRequiredParameters(req: Request, res: Response, name: string, split?: string): string[] | undefined {
|
|
188
|
-
const v = req.params[name]
|
|
188
|
+
const v = req.params[name] as string
|
|
189
189
|
if (!v || v.length === 0) {
|
|
190
190
|
res.status(400).end(`'${name}' cannot be empty`)
|
|
191
191
|
return undefined
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export {
|
|
|
20
20
|
Controller as Handler,
|
|
21
21
|
LoadSearchController as LoadSearchHandler,
|
|
22
22
|
Service as LowCodeService,
|
|
23
|
-
SearchController as SearchHandler
|
|
23
|
+
SearchController as SearchHandler,
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export * from "./access"
|
|
@@ -57,7 +57,7 @@ export class SavedController {
|
|
|
57
57
|
protected id: string
|
|
58
58
|
save(req: Request, res: Response) {
|
|
59
59
|
const userId: string = res.locals[this.userId]
|
|
60
|
-
const id = req.params[this.id]
|
|
60
|
+
const id = req.params[this.id] as string
|
|
61
61
|
if (!id || id.length === 0) {
|
|
62
62
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
63
63
|
return
|
|
@@ -76,7 +76,7 @@ export class SavedController {
|
|
|
76
76
|
}
|
|
77
77
|
remove(req: Request, res: Response) {
|
|
78
78
|
const userId: string = res.locals[this.userId]
|
|
79
|
-
const id = req.params[this.id]
|
|
79
|
+
const id = req.params[this.id] as string
|
|
80
80
|
if (!id || id.length === 0) {
|
|
81
81
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
82
82
|
return
|
|
@@ -110,7 +110,7 @@ export class FollowController {
|
|
|
110
110
|
protected id: string
|
|
111
111
|
follow(req: Request, res: Response) {
|
|
112
112
|
const userId: string = res.locals[this.userId]
|
|
113
|
-
const id = req.params[this.id]
|
|
113
|
+
const id = req.params[this.id] as string
|
|
114
114
|
if (!id || id.length === 0) {
|
|
115
115
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
116
116
|
return
|
|
@@ -129,7 +129,7 @@ export class FollowController {
|
|
|
129
129
|
}
|
|
130
130
|
unfollow(req: Request, res: Response) {
|
|
131
131
|
const userId: string = res.locals[this.userId]
|
|
132
|
-
const id = req.params[this.id]
|
|
132
|
+
const id = req.params[this.id] as string
|
|
133
133
|
if (!id || id.length === 0) {
|
|
134
134
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
135
135
|
return
|
|
@@ -162,9 +162,9 @@ export class UserReactionController {
|
|
|
162
162
|
}
|
|
163
163
|
id: string
|
|
164
164
|
react(req: Request, res: Response) {
|
|
165
|
-
const id = req.params.id
|
|
166
|
-
const author = req.params.author
|
|
167
|
-
const reaction = req.params.reaction
|
|
165
|
+
const id = req.params.id as string
|
|
166
|
+
const author = req.params.author as string
|
|
167
|
+
const reaction = req.params.reaction as string
|
|
168
168
|
if (!id || id.length === 0) {
|
|
169
169
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
170
170
|
return
|
|
@@ -185,9 +185,9 @@ export class UserReactionController {
|
|
|
185
185
|
.catch((err) => handleError(err, res, this.log))
|
|
186
186
|
}
|
|
187
187
|
unreact(req: Request, res: Response) {
|
|
188
|
-
const id = req.params.id
|
|
189
|
-
const author = req.params.author
|
|
190
|
-
const reaction = req.params.reaction
|
|
188
|
+
const id = req.params.id as string
|
|
189
|
+
const author = req.params.author as string
|
|
190
|
+
const reaction = req.params.reaction as string
|
|
191
191
|
if (!id || id.length === 0) {
|
|
192
192
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
193
193
|
return
|
|
@@ -208,8 +208,8 @@ export class UserReactionController {
|
|
|
208
208
|
.catch((err) => handleError(err, res, this.log))
|
|
209
209
|
}
|
|
210
210
|
checkReaction(req: Request, res: Response) {
|
|
211
|
-
const id = req.params.id
|
|
212
|
-
const author = req.params.author
|
|
211
|
+
const id = req.params.id as string
|
|
212
|
+
const author = req.params.author as string
|
|
213
213
|
if (!id || id.length === 0) {
|
|
214
214
|
res.status(400).end(`'${this.id}' cannot be empty`)
|
|
215
215
|
return
|
package/src/resources.ts
CHANGED
|
@@ -26,7 +26,10 @@ export class resources {
|
|
|
26
26
|
}
|
|
27
27
|
export function getView(req: Request, view: string): string {
|
|
28
28
|
const partial = req.query[resources.partial]
|
|
29
|
-
return partial
|
|
29
|
+
return partial === "true" ? resources.pages + "/" + view : view
|
|
30
|
+
}
|
|
31
|
+
export function isPartial(req: Request): boolean {
|
|
32
|
+
return req.query[resources.partial] === "true"
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export interface Validator<T> {
|
|
@@ -35,7 +38,10 @@ export interface Validator<T> {
|
|
|
35
38
|
|
|
36
39
|
// tslint:disable-next-line:max-classes-per-file
|
|
37
40
|
export class TypeChecker {
|
|
38
|
-
constructor(
|
|
41
|
+
constructor(
|
|
42
|
+
public attributes: Attributes,
|
|
43
|
+
public allowUndefined?: boolean,
|
|
44
|
+
) {
|
|
39
45
|
this.check = this.check.bind(this)
|
|
40
46
|
}
|
|
41
47
|
check(req: Request, res: Response, next: NextFunction): void {
|