@ticatec/common-express-server 0.0.8 → 0.1.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/README.md +491 -0
- package/lib/AppConf.d.ts +31 -0
- package/lib/AppConf.js +57 -0
- package/lib/AppConf.js.map +1 -0
- package/lib/BaseServer.d.ts +72 -26
- package/lib/BaseServer.js +52 -24
- package/lib/BaseServer.js.map +1 -1
- package/lib/CommonRouterHelper.d.ts +45 -22
- package/lib/CommonRouterHelper.js +52 -22
- package/lib/CommonRouterHelper.js.map +1 -1
- package/lib/CommonRoutes.d.ts +21 -3
- package/lib/CommonRoutes.js +16 -1
- package/lib/CommonRoutes.js.map +1 -1
- package/lib/LoggedUser.d.ts +11 -15
- package/lib/common/AdminBaseController.d.ts +14 -10
- package/lib/common/AdminBaseController.js +11 -8
- package/lib/common/AdminBaseController.js.map +1 -1
- package/lib/common/AdminSearchController.d.ts +6 -1
- package/lib/common/AdminSearchController.js +7 -2
- package/lib/common/AdminSearchController.js.map +1 -1
- package/lib/common/BaseController.d.ts +18 -2
- package/lib/common/BaseController.js +18 -3
- package/lib/common/BaseController.js.map +1 -1
- package/lib/common/CommonController.d.ts +49 -25
- package/lib/common/CommonController.js +42 -23
- package/lib/common/CommonController.js.map +1 -1
- package/lib/common/TenantBaseController.d.ts +16 -11
- package/lib/common/TenantBaseController.js +14 -13
- package/lib/common/TenantBaseController.js.map +1 -1
- package/lib/common/TenantSearchController.d.ts +6 -1
- package/lib/common/TenantSearchController.js +7 -2
- package/lib/common/TenantSearchController.js.map +1 -1
- package/lib/index.d.ts +14 -0
- package/lib/index.js +30 -0
- package/lib/index.js.map +1 -0
- package/package.json +54 -14
- package/.idea/common-express-server.iml +0 -9
- package/.idea/inspectionProfiles/Project_Default.xml +0 -11
- package/.idea/misc.xml +0 -5
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/tsconfig.json +0 -13
package/lib/LoggedUser.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common user interface representing basic user information
|
|
3
|
+
*/
|
|
1
4
|
export interface CommonUser {
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
id: string;
|
|
6
|
-
/**
|
|
7
|
-
* 编码
|
|
6
|
+
* Account code
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
accountCode: string;
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* User name
|
|
12
11
|
*/
|
|
13
12
|
name: string;
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* Additional properties
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
};
|
|
16
|
+
[key: string]: any;
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
18
|
+
* Tenant information
|
|
23
19
|
*/
|
|
24
20
|
tenant: {
|
|
25
21
|
code: string;
|
|
@@ -27,11 +23,11 @@ export interface CommonUser {
|
|
|
27
23
|
};
|
|
28
24
|
}
|
|
29
25
|
/**
|
|
30
|
-
*
|
|
26
|
+
* Interface for currently logged in user
|
|
31
27
|
*/
|
|
32
28
|
export default interface LoggedUser extends CommonUser {
|
|
33
29
|
/**
|
|
34
|
-
*
|
|
30
|
+
* User being acted as (for user impersonation)
|
|
35
31
|
*/
|
|
36
32
|
actAs?: CommonUser;
|
|
37
33
|
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { ValidationRules } from "@ticatec/bean-validator";
|
|
2
2
|
import CommonController from "./CommonController";
|
|
3
|
+
import { Request } from "express";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Base class for platform admin interfaces that are tenant-independent
|
|
6
|
+
* @template T The service type this controller depends on
|
|
5
7
|
*/
|
|
6
8
|
export default abstract class AdminBaseController<T> extends CommonController<T> {
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param service
|
|
10
|
-
* @param rules
|
|
10
|
+
* Constructor for admin base controller
|
|
11
|
+
* @param service The service instance to inject
|
|
12
|
+
* @param rules Entity validation rules
|
|
11
13
|
* @protected
|
|
12
14
|
*/
|
|
13
15
|
protected constructor(service: T, rules: ValidationRules);
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param req
|
|
17
|
+
* Gets arguments for creating new entity
|
|
18
|
+
* @param req Express request object
|
|
19
|
+
* @returns Array containing request body as the only argument
|
|
17
20
|
* @protected
|
|
18
21
|
*/
|
|
19
|
-
protected getCreateNewArguments(req:
|
|
22
|
+
protected getCreateNewArguments(req: Request): Array<any>;
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param req
|
|
24
|
+
* Gets arguments for updating entity
|
|
25
|
+
* @param req Express request object
|
|
26
|
+
* @returns Array containing request body as the only argument
|
|
23
27
|
* @protected
|
|
24
28
|
*/
|
|
25
|
-
protected getUpdateArguments(req:
|
|
29
|
+
protected getUpdateArguments(req: Request): any[];
|
|
26
30
|
}
|
|
@@ -5,29 +5,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const CommonController_1 = __importDefault(require("./CommonController"));
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Base class for platform admin interfaces that are tenant-independent
|
|
9
|
+
* @template T The service type this controller depends on
|
|
9
10
|
*/
|
|
10
11
|
class AdminBaseController extends CommonController_1.default {
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param service
|
|
14
|
-
* @param rules
|
|
13
|
+
* Constructor for admin base controller
|
|
14
|
+
* @param service The service instance to inject
|
|
15
|
+
* @param rules Entity validation rules
|
|
15
16
|
* @protected
|
|
16
17
|
*/
|
|
17
18
|
constructor(service, rules) {
|
|
18
19
|
super(service, rules);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param req
|
|
22
|
+
* Gets arguments for creating new entity
|
|
23
|
+
* @param req Express request object
|
|
24
|
+
* @returns Array containing request body as the only argument
|
|
23
25
|
* @protected
|
|
24
26
|
*/
|
|
25
27
|
getCreateNewArguments(req) {
|
|
26
28
|
return [req.body];
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param req
|
|
31
|
+
* Gets arguments for updating entity
|
|
32
|
+
* @param req Express request object
|
|
33
|
+
* @returns Array containing request body as the only argument
|
|
31
34
|
* @protected
|
|
32
35
|
*/
|
|
33
36
|
getUpdateArguments(req) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdminBaseController.js","sourceRoot":"src/","sources":["common/AdminBaseController.ts"],"names":[],"mappings":";;;;;AACA,0EAAkD;
|
|
1
|
+
{"version":3,"file":"AdminBaseController.js","sourceRoot":"src/","sources":["common/AdminBaseController.ts"],"names":[],"mappings":";;;;;AACA,0EAAkD;AAGlD;;;GAGG;AACH,MAA8B,mBAAuB,SAAQ,0BAAmB;IAE5E;;;;;OAKG;IACH,YAAsB,OAAU,EAAE,KAAsB;QACpD,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACO,qBAAqB,CAAC,GAAY;QACxC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;IAED;;;;;OAKG;IACO,kBAAkB,CAAC,GAAY;QACrC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;CACJ;AA/BD,sCA+BC"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
2
|
import AdminBaseController from "./AdminBaseController";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Base class for tenant-independent search interfaces for platform admin
|
|
5
|
+
* @template T The service type this controller depends on
|
|
5
6
|
*/
|
|
6
7
|
export default abstract class AdminSearchController<T> extends AdminBaseController<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Search method for querying entities
|
|
10
|
+
* @returns Function that handles search requests
|
|
11
|
+
*/
|
|
7
12
|
search(): (req: Request) => Promise<any>;
|
|
8
13
|
}
|
|
@@ -6,13 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const AdminBaseController_1 = __importDefault(require("./AdminBaseController"));
|
|
7
7
|
const BaseController_1 = __importDefault(require("./BaseController"));
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Base class for tenant-independent search interfaces for platform admin
|
|
10
|
+
* @template T The service type this controller depends on
|
|
10
11
|
*/
|
|
11
12
|
class AdminSearchController extends AdminBaseController_1.default {
|
|
13
|
+
/**
|
|
14
|
+
* Search method for querying entities
|
|
15
|
+
* @returns Function that handles search requests
|
|
16
|
+
*/
|
|
12
17
|
search() {
|
|
13
18
|
return (req) => {
|
|
14
19
|
let query = req.query;
|
|
15
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`
|
|
20
|
+
BaseController_1.default.debugEnabled && this.logger.debug(`Path: ${req.path}, query by criteria:`, query);
|
|
16
21
|
return this.invokeServiceInterface('search', [query]);
|
|
17
22
|
};
|
|
18
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdminSearchController.js","sourceRoot":"src/","sources":["common/AdminSearchController.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AACxD,sEAA8C;
|
|
1
|
+
{"version":3,"file":"AdminSearchController.js","sourceRoot":"src/","sources":["common/AdminSearchController.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AACxD,sEAA8C;AAG9C;;;GAGG;AACH,MAA8B,qBAAyB,SAAQ,6BAAsB;IAEjF;;;OAGG;IACH,MAAM;QACF,OAAO,CAAC,GAAW,EAAE,EAAE;YACnB,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;YACtB,wBAAc,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,IAAI,sBAAsB,EAAE,KAAK,CAAC,CAAC;YACjG,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAA;IACL,CAAC;CACJ;AAbD,wCAaC"}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { Logger } from "log4js";
|
|
2
|
+
import { CommonUser } from "../LoggedUser";
|
|
3
|
+
import { Request } from "express";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base controller class providing common functionality for all controllers
|
|
6
|
+
* @template T The service type this controller depends on
|
|
7
|
+
*/
|
|
2
8
|
export default abstract class BaseController<T> {
|
|
9
|
+
/** Flag to enable debug logging */
|
|
3
10
|
static debugEnabled: boolean;
|
|
11
|
+
/** The service instance this controller uses */
|
|
4
12
|
protected readonly service: T;
|
|
13
|
+
/** Logger instance for this controller */
|
|
5
14
|
protected readonly logger: Logger;
|
|
6
15
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param service
|
|
16
|
+
* Constructor for base controller
|
|
17
|
+
* @param service The service instance to inject
|
|
9
18
|
* @protected
|
|
10
19
|
*/
|
|
11
20
|
protected constructor(service: T);
|
|
21
|
+
/**
|
|
22
|
+
* Gets the current logged user, if acting as another user, returns the acted user,
|
|
23
|
+
* returns null for requests without user injection
|
|
24
|
+
* @param req Express request object
|
|
25
|
+
* @returns The current user or null if no user is logged in
|
|
26
|
+
*/
|
|
27
|
+
protected getLoggedUser: (req: Request) => CommonUser;
|
|
12
28
|
}
|
|
@@ -4,17 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const log4js_1 = __importDefault(require("log4js"));
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base controller class providing common functionality for all controllers
|
|
9
|
+
* @template T The service type this controller depends on
|
|
10
|
+
*/
|
|
7
11
|
class BaseController {
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param service
|
|
13
|
+
* Constructor for base controller
|
|
14
|
+
* @param service The service instance to inject
|
|
11
15
|
* @protected
|
|
12
16
|
*/
|
|
13
17
|
constructor(service) {
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current logged user, if acting as another user, returns the acted user,
|
|
20
|
+
* returns null for requests without user injection
|
|
21
|
+
* @param req Express request object
|
|
22
|
+
* @returns The current user or null if no user is logged in
|
|
23
|
+
*/
|
|
24
|
+
this.getLoggedUser = (req) => {
|
|
25
|
+
let user = req['user'];
|
|
26
|
+
return (user === null || user === void 0 ? void 0 : user.actAs) || user;
|
|
27
|
+
};
|
|
14
28
|
this.logger = log4js_1.default.getLogger(this.constructor.name);
|
|
15
29
|
this.service = service;
|
|
16
30
|
}
|
|
17
31
|
}
|
|
18
|
-
|
|
32
|
+
/** Flag to enable debug logging */
|
|
19
33
|
BaseController.debugEnabled = false;
|
|
34
|
+
exports.default = BaseController;
|
|
20
35
|
//# sourceMappingURL=BaseController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.js","sourceRoot":"src/","sources":["common/BaseController.ts"],"names":[],"mappings":";;;;;AACA,oDAAsC;
|
|
1
|
+
{"version":3,"file":"BaseController.js","sourceRoot":"src/","sources":["common/BaseController.ts"],"names":[],"mappings":";;;;;AACA,oDAAsC;AAItC;;;GAGG;AACH,MAA8B,cAAc;IASxC;;;;OAIG;IACH,YAAsB,OAAU;QAKhC;;;;;WAKG;QACO,kBAAa,GAAG,CAAC,GAAY,EAAc,EAAE;YACnD,IAAI,IAAI,GAAe,GAAG,CAAC,MAAM,CAAC,CAAC;YACnC,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,KAAI,IAAI,CAAC;QAC/B,CAAC,CAAA;QAbG,IAAI,CAAC,MAAM,GAAG,gBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;;AAfD,mCAAmC;AAC5B,2BAAY,GAAY,KAAK,AAAjB,CAAkB;kBAHX,cAAc"}
|
|
@@ -1,70 +1,94 @@
|
|
|
1
1
|
import BaseController from "./BaseController";
|
|
2
2
|
import { ValidationRules } from "@ticatec/bean-validator";
|
|
3
3
|
import { RestfulFunction } from "../CommonRouterHelper";
|
|
4
|
+
import { Request } from "express";
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Controller class that implements Create/Read/Update/Delete operations
|
|
7
|
+
* @template T The service type this controller depends on
|
|
6
8
|
*/
|
|
7
9
|
export default abstract class CommonController<T> extends BaseController<T> {
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
11
|
+
* Entity validation rules
|
|
10
12
|
* @protected
|
|
11
13
|
*/
|
|
12
14
|
protected readonly rules: ValidationRules;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for common controller
|
|
17
|
+
* @param service The service instance to inject
|
|
18
|
+
* @param rules Validation rules for entities (optional)
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
13
21
|
protected constructor(service: T, rules?: ValidationRules);
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param data
|
|
23
|
+
* Validates entity data
|
|
24
|
+
* @param data The data to validate
|
|
17
25
|
* @protected
|
|
18
26
|
*/
|
|
19
27
|
protected validateEntity(data: any): void;
|
|
20
28
|
/**
|
|
21
|
-
*
|
|
29
|
+
* Creates new entity endpoint
|
|
30
|
+
* @returns RESTful function for creating new entities
|
|
22
31
|
*/
|
|
23
32
|
createNew(): RestfulFunction;
|
|
24
33
|
/**
|
|
25
|
-
*
|
|
34
|
+
* Updates entity endpoint
|
|
35
|
+
* @returns RESTful function for updating entities
|
|
26
36
|
*/
|
|
27
37
|
update(): RestfulFunction;
|
|
28
38
|
/**
|
|
29
|
-
*
|
|
39
|
+
* Deletes entity endpoint
|
|
40
|
+
* @returns RESTful function for deleting entities
|
|
30
41
|
*/
|
|
31
42
|
del(): RestfulFunction;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a service interface method exists
|
|
45
|
+
* @param name The method name to check
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
32
48
|
protected checkInterface(name: string): void;
|
|
33
49
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param name
|
|
36
|
-
* @param args
|
|
50
|
+
* Invokes service interface by name
|
|
51
|
+
* @param name The method name to invoke
|
|
52
|
+
* @param args Arguments to pass to the method
|
|
53
|
+
* @returns Promise resolving to the method result
|
|
37
54
|
* @protected
|
|
38
55
|
*/
|
|
39
56
|
protected invokeServiceInterface(name: string, args?: Array<any>): Promise<any>;
|
|
40
57
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param req
|
|
58
|
+
* Creates a new entity
|
|
59
|
+
* @param req Express request object
|
|
60
|
+
* @returns Promise resolving to the created entity
|
|
43
61
|
* @protected
|
|
44
62
|
*/
|
|
45
|
-
protected _createNew(req:
|
|
63
|
+
protected _createNew(req: Request): Promise<any>;
|
|
46
64
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @param req
|
|
65
|
+
* Updates an entity
|
|
66
|
+
* @param req Express request object
|
|
67
|
+
* @returns Promise resolving to the updated entity
|
|
49
68
|
* @protected
|
|
50
69
|
*/
|
|
51
|
-
protected _update(req:
|
|
70
|
+
protected _update(req: Request): Promise<any>;
|
|
52
71
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param req
|
|
72
|
+
* Deletes an entity
|
|
73
|
+
* @param req Express request object
|
|
74
|
+
* @returns Promise resolving when entity is deleted
|
|
55
75
|
* @protected
|
|
56
76
|
*/
|
|
57
|
-
protected _del(req:
|
|
77
|
+
protected _del(req: Request): Promise<any>;
|
|
58
78
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param req
|
|
79
|
+
* Gets arguments for creating new entity
|
|
80
|
+
* @param req Express request object
|
|
81
|
+
* @returns Array of arguments to pass to service create method
|
|
61
82
|
* @protected
|
|
83
|
+
* @abstract
|
|
62
84
|
*/
|
|
63
|
-
protected abstract getCreateNewArguments(req:
|
|
85
|
+
protected abstract getCreateNewArguments(req: Request): Array<any>;
|
|
64
86
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param req
|
|
87
|
+
* Gets arguments for updating entity
|
|
88
|
+
* @param req Express request object
|
|
89
|
+
* @returns Array of arguments to pass to service update method
|
|
67
90
|
* @protected
|
|
91
|
+
* @abstract
|
|
68
92
|
*/
|
|
69
|
-
protected abstract getUpdateArguments(req:
|
|
93
|
+
protected abstract getUpdateArguments(req: Request): Array<any>;
|
|
70
94
|
}
|
|
@@ -7,27 +7,35 @@ const express_exception_1 = require("@ticatec/express-exception");
|
|
|
7
7
|
const BaseController_1 = __importDefault(require("./BaseController"));
|
|
8
8
|
const bean_validator_1 = __importDefault(require("@ticatec/bean-validator"));
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Controller class that implements Create/Read/Update/Delete operations
|
|
11
|
+
* @template T The service type this controller depends on
|
|
11
12
|
*/
|
|
12
13
|
class CommonController extends BaseController_1.default {
|
|
14
|
+
/**
|
|
15
|
+
* Constructor for common controller
|
|
16
|
+
* @param service The service instance to inject
|
|
17
|
+
* @param rules Validation rules for entities (optional)
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
13
20
|
constructor(service, rules = null) {
|
|
14
21
|
super(service);
|
|
15
22
|
this.rules = rules;
|
|
16
23
|
}
|
|
17
24
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param data
|
|
25
|
+
* Validates entity data
|
|
26
|
+
* @param data The data to validate
|
|
20
27
|
* @protected
|
|
21
28
|
*/
|
|
22
29
|
validateEntity(data) {
|
|
23
30
|
let result = bean_validator_1.default.validate(data, this.rules);
|
|
24
31
|
if (!result.valid) {
|
|
25
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`
|
|
32
|
+
BaseController_1.default.debugEnabled && this.logger.debug(`Invalid data: ${result.errorMessage}`);
|
|
26
33
|
throw new express_exception_1.IllegalParameterError(result.errorMessage);
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
|
-
*
|
|
37
|
+
* Creates new entity endpoint
|
|
38
|
+
* @returns RESTful function for creating new entities
|
|
31
39
|
*/
|
|
32
40
|
createNew() {
|
|
33
41
|
return async (req) => {
|
|
@@ -35,7 +43,8 @@ class CommonController extends BaseController_1.default {
|
|
|
35
43
|
};
|
|
36
44
|
}
|
|
37
45
|
/**
|
|
38
|
-
*
|
|
46
|
+
* Updates entity endpoint
|
|
47
|
+
* @returns RESTful function for updating entities
|
|
39
48
|
*/
|
|
40
49
|
update() {
|
|
41
50
|
return async (req) => {
|
|
@@ -43,61 +52,71 @@ class CommonController extends BaseController_1.default {
|
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
46
|
-
*
|
|
55
|
+
* Deletes entity endpoint
|
|
56
|
+
* @returns RESTful function for deleting entities
|
|
47
57
|
*/
|
|
48
58
|
del() {
|
|
49
59
|
return async (req) => {
|
|
50
60
|
return this._del(req);
|
|
51
61
|
};
|
|
52
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a service interface method exists
|
|
65
|
+
* @param name The method name to check
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
53
68
|
checkInterface(name) {
|
|
54
69
|
if (this.service[name] == null) {
|
|
55
|
-
this.logger.warn(
|
|
56
|
-
throw new express_exception_1.ActionNotFoundError(
|
|
70
|
+
this.logger.warn(`Current service does not have interface: ${name}`);
|
|
71
|
+
throw new express_exception_1.ActionNotFoundError(`Current service does not have interface: ${name}`);
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param name
|
|
62
|
-
* @param args
|
|
75
|
+
* Invokes service interface by name
|
|
76
|
+
* @param name The method name to invoke
|
|
77
|
+
* @param args Arguments to pass to the method
|
|
78
|
+
* @returns Promise resolving to the method result
|
|
63
79
|
* @protected
|
|
64
80
|
*/
|
|
65
81
|
async invokeServiceInterface(name, args = []) {
|
|
66
82
|
return await this.service[name](...args);
|
|
67
83
|
}
|
|
68
84
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @param req
|
|
85
|
+
* Creates a new entity
|
|
86
|
+
* @param req Express request object
|
|
87
|
+
* @returns Promise resolving to the created entity
|
|
71
88
|
* @protected
|
|
72
89
|
*/
|
|
73
90
|
_createNew(req) {
|
|
74
91
|
let data = req.body;
|
|
75
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl}
|
|
92
|
+
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl} Request to create an entity`, data);
|
|
76
93
|
this.checkInterface('createNew');
|
|
77
94
|
this.validateEntity(data);
|
|
78
95
|
return this.invokeServiceInterface('createNew', this.getCreateNewArguments(req));
|
|
79
96
|
}
|
|
80
97
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @param req
|
|
98
|
+
* Updates an entity
|
|
99
|
+
* @param req Express request object
|
|
100
|
+
* @returns Promise resolving to the updated entity
|
|
83
101
|
* @protected
|
|
84
102
|
*/
|
|
85
103
|
_update(req) {
|
|
86
104
|
let data = req.body;
|
|
87
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl}
|
|
105
|
+
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl} Request to update an entity`, data);
|
|
88
106
|
this.checkInterface('update');
|
|
89
107
|
this.validateEntity(data);
|
|
90
108
|
return this.invokeServiceInterface('update', this.getUpdateArguments(req));
|
|
91
109
|
}
|
|
92
110
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @param req
|
|
111
|
+
* Deletes an entity
|
|
112
|
+
* @param req Express request object
|
|
113
|
+
* @returns Promise resolving when entity is deleted
|
|
95
114
|
* @protected
|
|
96
115
|
*/
|
|
97
116
|
_del(req) {
|
|
98
|
-
|
|
99
|
-
this.logger.warn('
|
|
100
|
-
throw new express_exception_1.ActionNotFoundError('
|
|
117
|
+
// Please implement delete interface in subclass, otherwise system exception will be thrown
|
|
118
|
+
this.logger.warn('Current service does not have delete interface');
|
|
119
|
+
throw new express_exception_1.ActionNotFoundError('Current service does not have delete interface');
|
|
101
120
|
}
|
|
102
121
|
}
|
|
103
122
|
exports.default = CommonController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommonController.js","sourceRoot":"src/","sources":["common/CommonController.ts"],"names":[],"mappings":";;;;;AACA,
|
|
1
|
+
{"version":3,"file":"CommonController.js","sourceRoot":"src/","sources":["common/CommonController.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import CommonController from "./CommonController";
|
|
2
2
|
import { ValidationRules } from "@ticatec/bean-validator";
|
|
3
|
+
import { Request } from "express";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Base class for tenant-specific interfaces
|
|
6
|
+
* @template T The service type this controller depends on
|
|
5
7
|
*/
|
|
6
8
|
export default abstract class TenantBaseController<T> extends CommonController<T> {
|
|
7
|
-
protected constructor(service: any, rules: ValidationRules);
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
10
|
+
* Constructor for tenant base controller
|
|
11
|
+
* @param service The service instance to inject
|
|
12
|
+
* @param rules Entity validation rules
|
|
13
|
+
* @protected
|
|
11
14
|
*/
|
|
12
|
-
protected
|
|
15
|
+
protected constructor(service: any, rules: ValidationRules);
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param req
|
|
17
|
+
* Gets arguments for creating new entity, first parameter is logged user, second is request data
|
|
18
|
+
* @param req Express request object
|
|
19
|
+
* @returns Array containing logged user and request body
|
|
16
20
|
* @protected
|
|
17
21
|
*/
|
|
18
|
-
protected getCreateNewArguments(req:
|
|
22
|
+
protected getCreateNewArguments(req: Request): Array<any>;
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param req
|
|
24
|
+
* Gets arguments for updating entity, first parameter is logged user, second is request data
|
|
25
|
+
* @param req Express request object
|
|
26
|
+
* @returns Array containing logged user and request body
|
|
22
27
|
* @protected
|
|
23
28
|
*/
|
|
24
|
-
protected getUpdateArguments(req:
|
|
29
|
+
protected getUpdateArguments(req: Request): any[];
|
|
25
30
|
}
|
|
@@ -5,31 +5,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const CommonController_1 = __importDefault(require("./CommonController"));
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Base class for tenant-specific interfaces
|
|
9
|
+
* @template T The service type this controller depends on
|
|
9
10
|
*/
|
|
10
11
|
class TenantBaseController extends CommonController_1.default {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor for tenant base controller
|
|
14
|
+
* @param service The service instance to inject
|
|
15
|
+
* @param rules Entity validation rules
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
11
18
|
constructor(service, rules) {
|
|
12
19
|
super(service, rules);
|
|
13
|
-
/**
|
|
14
|
-
* 获取当前登录用户,如果有扮演,获取扮演用户
|
|
15
|
-
* @param req
|
|
16
|
-
*/
|
|
17
|
-
this.getLoggedUser = (req) => {
|
|
18
|
-
let user = req.user;
|
|
19
|
-
return user.actAs || user;
|
|
20
|
-
};
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param req
|
|
22
|
+
* Gets arguments for creating new entity, first parameter is logged user, second is request data
|
|
23
|
+
* @param req Express request object
|
|
24
|
+
* @returns Array containing logged user and request body
|
|
25
25
|
* @protected
|
|
26
26
|
*/
|
|
27
27
|
getCreateNewArguments(req) {
|
|
28
28
|
return [this.getLoggedUser(req), req.body];
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param req
|
|
31
|
+
* Gets arguments for updating entity, first parameter is logged user, second is request data
|
|
32
|
+
* @param req Express request object
|
|
33
|
+
* @returns Array containing logged user and request body
|
|
33
34
|
* @protected
|
|
34
35
|
*/
|
|
35
36
|
getUpdateArguments(req) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TenantBaseController.js","sourceRoot":"src/","sources":["common/TenantBaseController.ts"],"names":[],"mappings":";;;;;AACA,0EAAkD;
|
|
1
|
+
{"version":3,"file":"TenantBaseController.js","sourceRoot":"src/","sources":["common/TenantBaseController.ts"],"names":[],"mappings":";;;;;AACA,0EAAkD;AAIlD;;;GAGG;AACH,MAA8B,oBAAwB,SAAQ,0BAAmB;IAE7E;;;;;OAKG;IACH,YAAsB,OAAY,EAAE,KAAsB;QACtD,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACO,qBAAqB,CAAC,GAAY;QACxC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;OAKG;IACO,kBAAkB,CAAC,GAAY;QACrC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;CAEJ;AAhCD,uCAgCC"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
2
|
import TenantBaseController from "./TenantBaseController";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Interface with search capabilities for tenant use
|
|
5
|
+
* @template T The service type this controller depends on
|
|
5
6
|
*/
|
|
6
7
|
export default abstract class TenantSearchController<T> extends TenantBaseController<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Search method for querying entities with tenant context
|
|
10
|
+
* @returns Function that handles tenant-specific search requests
|
|
11
|
+
*/
|
|
7
12
|
search(): (req: Request) => Promise<any>;
|
|
8
13
|
}
|