express-ext 0.4.1 → 0.4.3
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/GenericController.js +125 -129
- package/lib/LoadSearchController.js +1 -1
- package/lib/SearchController.js +1 -1
- package/lib/edit.js +61 -53
- package/lib/index.js +278 -242
- package/lib/resources.js +2 -0
- package/package.json +1 -1
- package/src/GenericController.ts +2 -4
- package/src/LoadSearchController.ts +1 -1
- package/src/SearchController.ts +1 -1
- package/src/edit.ts +6 -0
- package/src/index.ts +34 -2
- package/src/resources.ts +2 -0
package/lib/resources.js
CHANGED
|
@@ -5,6 +5,8 @@ var http = require("http")
|
|
|
5
5
|
var https = require("https")
|
|
6
6
|
var resources = (function () {
|
|
7
7
|
function resources() {}
|
|
8
|
+
resources.languageParam = "lang"
|
|
9
|
+
resources.defaultLanguage = "en"
|
|
8
10
|
resources.limits = [12, 24, 60, 100, 120, 180, 300, 600]
|
|
9
11
|
resources.pages = "pages"
|
|
10
12
|
resources.page = "page"
|
package/package.json
CHANGED
package/src/GenericController.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from "express"
|
|
2
|
-
import { checkId, create,
|
|
2
|
+
import { checkId, create, getStatusCode, update } from "./edit"
|
|
3
3
|
import { handleError, Log } from "./http"
|
|
4
4
|
import { LoadController } from "./LoadController"
|
|
5
5
|
import { Attribute, Attributes, ErrorMessage } from "./metadata"
|
|
@@ -165,9 +165,7 @@ export function getDeleteStatus(count: number): number {
|
|
|
165
165
|
return 409
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
return isTypeError(errs) ? 400 : 422
|
|
170
|
-
}
|
|
168
|
+
|
|
171
169
|
export interface ModelConfig {
|
|
172
170
|
id?: string
|
|
173
171
|
payload?: string
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response } from "express"
|
|
2
|
-
import { resources } from "resources"
|
|
3
2
|
import { handleError, Log } from "./http"
|
|
4
3
|
import { LoadController, ViewService } from "./LoadController"
|
|
5
4
|
import { Attribute, Attributes } from "./metadata"
|
|
5
|
+
import { resources } from "./resources"
|
|
6
6
|
import { buildArray, Filter, format, fromRequest, getMetadataFunc, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from "./search"
|
|
7
7
|
|
|
8
8
|
export interface Search {
|
package/src/SearchController.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response } from "express"
|
|
2
|
-
import { resources } from "resources"
|
|
3
2
|
import { handleError, Log } from "./http"
|
|
3
|
+
import { resources } from "./resources"
|
|
4
4
|
import { buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from "./search"
|
|
5
5
|
|
|
6
6
|
export class SearchController<T, S extends Filter> {
|
package/src/edit.ts
CHANGED
|
@@ -140,3 +140,9 @@ export function isTypeError(errs: ErrorMessage[]): boolean {
|
|
|
140
140
|
}
|
|
141
141
|
return false
|
|
142
142
|
}
|
|
143
|
+
export function getStatusCode(errs: ErrorMessage[]): number {
|
|
144
|
+
return isTypeError(errs) ? 400 : 422
|
|
145
|
+
}
|
|
146
|
+
export function respondError(res: Response, errors: ErrorMessage[]) {
|
|
147
|
+
res.status(getStatusCode(errors)).json(errors).end()
|
|
148
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { NextFunction, Request, Response } from "express"
|
|
|
2
2
|
import { GenericController } from "./GenericController"
|
|
3
3
|
import { GenericSearchController } from "./GenericSearchController"
|
|
4
4
|
import { HealthController } from "./HealthController"
|
|
5
|
-
import { handleError, Log } from "./http"
|
|
5
|
+
import { handleError, Log, query } from "./http"
|
|
6
6
|
import { LoadController } from "./LoadController"
|
|
7
7
|
import { LoadSearchController } from "./LoadSearchController"
|
|
8
8
|
import { LogController } from "./LogController"
|
|
9
9
|
import { Controller, Service } from "./LowCodeController"
|
|
10
10
|
import { ErrorMessage } from "./metadata"
|
|
11
|
-
import { StringMap } from "./resources"
|
|
11
|
+
import { resources, StringMap } from "./resources"
|
|
12
12
|
import { SearchController } from "./SearchController"
|
|
13
13
|
|
|
14
14
|
export { HealthController as HealthHandler, LoadController as LoadHandler, LogController as LogHandler, LoadController as ViewHandler }
|
|
@@ -381,3 +381,35 @@ export function escapeArray<T>(arrs: T[]): T[] {
|
|
|
381
381
|
}
|
|
382
382
|
return arrs
|
|
383
383
|
}
|
|
384
|
+
|
|
385
|
+
export function buildError404(resource: StringMap, res: Response): any {
|
|
386
|
+
return {
|
|
387
|
+
message: {
|
|
388
|
+
title: resource.error_404_title,
|
|
389
|
+
description: resource.error_404_message,
|
|
390
|
+
},
|
|
391
|
+
menu: res.locals.menu,
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
export function buildError500(resource: StringMap, res: Response): any {
|
|
395
|
+
return {
|
|
396
|
+
message: {
|
|
397
|
+
title: resource.error_500_title,
|
|
398
|
+
description: resource.error_500_message,
|
|
399
|
+
},
|
|
400
|
+
menu: res.locals.menu,
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
export function buildError(res: Response, title: string, description: string): any {
|
|
404
|
+
return {
|
|
405
|
+
message: {
|
|
406
|
+
title,
|
|
407
|
+
description,
|
|
408
|
+
},
|
|
409
|
+
menu: res.locals.menu,
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
export function queryLang(req: Request): string {
|
|
413
|
+
const lang = query(req, resources.languageParam)
|
|
414
|
+
return lang && lang.length > 0 ? lang : resources.defaultLanguage
|
|
415
|
+
}
|
package/src/resources.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface StringMap {
|
|
|
9
9
|
}
|
|
10
10
|
// tslint:disable-next-line:class-name
|
|
11
11
|
export class resources {
|
|
12
|
+
static languageParam = "lang"
|
|
13
|
+
static defaultLanguage = "en"
|
|
12
14
|
static limits = [12, 24, 60, 100, 120, 180, 300, 600]
|
|
13
15
|
static pages = "pages"
|
|
14
16
|
static page = "page"
|