@ticatec/common-express-server 0.2.0 → 0.3.0
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/package.json +10 -10
- package/lib/AppConf.d.ts +0 -31
- package/lib/AppConf.js +0 -57
- package/lib/AppConf.js.map +0 -1
- package/lib/BaseServer.d.ts +0 -125
- package/lib/BaseServer.js +0 -155
- package/lib/BaseServer.js.map +0 -1
- package/lib/CommonRouterHelper.d.ts +0 -64
- package/lib/CommonRouterHelper.js +0 -134
- package/lib/CommonRouterHelper.js.map +0 -1
- package/lib/CommonRoutes.d.ts +0 -33
- package/lib/CommonRoutes.js +0 -57
- package/lib/CommonRoutes.js.map +0 -1
- package/lib/LoggedUser.d.ts +0 -33
- package/lib/LoggedUser.js +0 -3
- package/lib/LoggedUser.js.map +0 -1
- package/lib/common/AdminBaseController.d.ts +0 -30
- package/lib/common/AdminBaseController.js +0 -41
- package/lib/common/AdminBaseController.js.map +0 -1
- package/lib/common/AdminSearchController.d.ts +0 -13
- package/lib/common/AdminSearchController.js +0 -26
- package/lib/common/AdminSearchController.js.map +0 -1
- package/lib/common/BaseController.d.ts +0 -28
- package/lib/common/BaseController.js +0 -35
- package/lib/common/BaseController.js.map +0 -1
- package/lib/common/CommonController.d.ts +0 -96
- package/lib/common/CommonController.js +0 -129
- package/lib/common/CommonController.js.map +0 -1
- package/lib/common/TenantBaseController.d.ts +0 -30
- package/lib/common/TenantBaseController.js +0 -41
- package/lib/common/TenantBaseController.js.map +0 -1
- package/lib/common/TenantSearchController.d.ts +0 -13
- package/lib/common/TenantSearchController.js +0 -27
- package/lib/common/TenantSearchController.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.js +0 -30
- package/lib/index.js.map +0 -1
- package/lib/lib/CommonProcessor.d.ts +0 -49
- package/lib/lib/CommonProcessor.js +0 -99
- package/lib/lib/CommonProcessor.js.map +0 -1
- package/lib/lib/ProcessorManager.d.ts +0 -14
- package/lib/lib/ProcessorManager.js +0 -30
- package/lib/lib/ProcessorManager.js.map +0 -1
package/lib/CommonRoutes.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = require("express");
|
|
7
|
-
const log4js_1 = __importDefault(require("log4js"));
|
|
8
|
-
const express_exception_1 = require("@ticatec/express-exception");
|
|
9
|
-
/**
|
|
10
|
-
* 自定义校验
|
|
11
|
-
* @param checker
|
|
12
|
-
*/
|
|
13
|
-
const customCheck = (checker) => (req, res, next) => {
|
|
14
|
-
if (checker(req)) {
|
|
15
|
-
next();
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
throw new express_exception_1.UnauthenticatedError();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Abstract base class for defining common routes
|
|
23
|
-
* @template T The type of CommonRouterHelper this routes class uses
|
|
24
|
-
*/
|
|
25
|
-
class CommonRoutes {
|
|
26
|
-
/**
|
|
27
|
-
* Constructor for common routes
|
|
28
|
-
* @param helper Router helper instance
|
|
29
|
-
* @param checkUser Whether to check user authentication (default: true)
|
|
30
|
-
* @param mergeParams Whether to merge params (default: false)
|
|
31
|
-
* @protected
|
|
32
|
-
*/
|
|
33
|
-
constructor(helper, checkUser = true, mergeParams = false) {
|
|
34
|
-
this.router = (0, express_1.Router)({ mergeParams });
|
|
35
|
-
this.helper = helper;
|
|
36
|
-
this.logger = log4js_1.default.getLogger(this.constructor.name);
|
|
37
|
-
if (typeof checkUser == "boolean") {
|
|
38
|
-
if (checkUser) {
|
|
39
|
-
this.logger.debug('Checking if user is logged in');
|
|
40
|
-
this.router.use(helper.checkLoggedUser());
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (typeof checkUser == "function") {
|
|
44
|
-
this.router.use(customCheck(checkUser));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Binds this router to the Express application
|
|
49
|
-
* @param app Express application instance
|
|
50
|
-
* @param path The path prefix for this router
|
|
51
|
-
*/
|
|
52
|
-
bindRouter(app, path) {
|
|
53
|
-
app.use(path, this.router);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.default = CommonRoutes;
|
|
57
|
-
//# sourceMappingURL=CommonRoutes.js.map
|
package/lib/CommonRoutes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommonRoutes.js","sourceRoot":"src/","sources":["CommonRoutes.ts"],"names":[],"mappings":";;;;;AAAA,qCAA2D;AAE3D,oDAAsC;AAEtC,kEAAgE;AAOhE;;;GAGG;AACH,MAAM,WAAW,GAAG,CAAC,OAAoB,EAAE,EAAE,CAAC,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC9F,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACf,IAAI,EAAE,CAAC;IACX,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,wCAAoB,EAAE,CAAA;IACpC,CAAC;AACL,CAAC,CAAA;AAED;;;GAGG;AACH,MAA8B,YAAY;IAQtC;;;;;;OAMG;IACH,YAAsB,MAAS,EAAE,YAAmC,IAAI,EAAE,cAAuB,KAAK;QAClG,IAAI,CAAC,MAAM,GAAG,IAAA,gBAAM,EAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,gBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,OAAO,SAAS,IAAI,SAAS,EAAE,CAAC;YAChC,IAAI,SAAS,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;gBAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;YAC9C,CAAC;QACL,CAAC;aAAM,IAAI,OAAO,SAAS,IAAI,UAAU,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAA;QAC3C,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,GAAY,EAAE,IAAY;QACjC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACJ;AArCD,+BAqCC"}
|
package/lib/LoggedUser.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common user interface representing basic user information
|
|
3
|
-
*/
|
|
4
|
-
export interface CommonUser {
|
|
5
|
-
/**
|
|
6
|
-
* Account code
|
|
7
|
-
*/
|
|
8
|
-
accountCode: string;
|
|
9
|
-
/**
|
|
10
|
-
* User name
|
|
11
|
-
*/
|
|
12
|
-
name: string;
|
|
13
|
-
/**
|
|
14
|
-
* Additional properties
|
|
15
|
-
*/
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
/**
|
|
18
|
-
* Tenant information
|
|
19
|
-
*/
|
|
20
|
-
tenant: {
|
|
21
|
-
code: string;
|
|
22
|
-
name: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Interface for currently logged in user
|
|
27
|
-
*/
|
|
28
|
-
export default interface LoggedUser extends CommonUser {
|
|
29
|
-
/**
|
|
30
|
-
* User being acted as (for user impersonation)
|
|
31
|
-
*/
|
|
32
|
-
actAs?: CommonUser;
|
|
33
|
-
}
|
package/lib/LoggedUser.js
DELETED
package/lib/LoggedUser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoggedUser.js","sourceRoot":"src/","sources":["LoggedUser.ts"],"names":[],"mappings":""}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ValidationRules } from "@ticatec/bean-validator";
|
|
2
|
-
import CommonController from "./CommonController";
|
|
3
|
-
import { Request } from "express";
|
|
4
|
-
/**
|
|
5
|
-
* Base class for platform admin interfaces that are tenant-independent
|
|
6
|
-
* @template T The service type this controller depends on
|
|
7
|
-
*/
|
|
8
|
-
export default abstract class AdminBaseController<T> extends CommonController<T> {
|
|
9
|
-
/**
|
|
10
|
-
* Constructor for admin base controller
|
|
11
|
-
* @param service The service instance to inject
|
|
12
|
-
* @param rules Entity validation rules
|
|
13
|
-
* @protected
|
|
14
|
-
*/
|
|
15
|
-
protected constructor(service: T, rules: ValidationRules);
|
|
16
|
-
/**
|
|
17
|
-
* Gets arguments for creating new entity
|
|
18
|
-
* @param req Express request object
|
|
19
|
-
* @returns Array containing request body as the only argument
|
|
20
|
-
* @protected
|
|
21
|
-
*/
|
|
22
|
-
protected getCreateNewArguments(req: Request): Array<any>;
|
|
23
|
-
/**
|
|
24
|
-
* Gets arguments for updating entity
|
|
25
|
-
* @param req Express request object
|
|
26
|
-
* @returns Array containing request body as the only argument
|
|
27
|
-
* @protected
|
|
28
|
-
*/
|
|
29
|
-
protected getUpdateArguments(req: Request): any[];
|
|
30
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const CommonController_1 = __importDefault(require("./CommonController"));
|
|
7
|
-
/**
|
|
8
|
-
* Base class for platform admin interfaces that are tenant-independent
|
|
9
|
-
* @template T The service type this controller depends on
|
|
10
|
-
*/
|
|
11
|
-
class AdminBaseController extends CommonController_1.default {
|
|
12
|
-
/**
|
|
13
|
-
* Constructor for admin base controller
|
|
14
|
-
* @param service The service instance to inject
|
|
15
|
-
* @param rules Entity validation rules
|
|
16
|
-
* @protected
|
|
17
|
-
*/
|
|
18
|
-
constructor(service, rules) {
|
|
19
|
-
super(service, rules);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Gets arguments for creating new entity
|
|
23
|
-
* @param req Express request object
|
|
24
|
-
* @returns Array containing request body as the only argument
|
|
25
|
-
* @protected
|
|
26
|
-
*/
|
|
27
|
-
getCreateNewArguments(req) {
|
|
28
|
-
return [req.body];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Gets arguments for updating entity
|
|
32
|
-
* @param req Express request object
|
|
33
|
-
* @returns Array containing request body as the only argument
|
|
34
|
-
* @protected
|
|
35
|
-
*/
|
|
36
|
-
getUpdateArguments(req) {
|
|
37
|
-
return [req.body];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.default = AdminBaseController;
|
|
41
|
-
//# sourceMappingURL=AdminBaseController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,13 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import AdminBaseController from "./AdminBaseController";
|
|
3
|
-
/**
|
|
4
|
-
* Base class for tenant-independent search interfaces for platform admin
|
|
5
|
-
* @template T The service type this controller depends on
|
|
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
|
-
*/
|
|
12
|
-
search(): (req: Request) => Promise<any>;
|
|
13
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const AdminBaseController_1 = __importDefault(require("./AdminBaseController"));
|
|
7
|
-
const BaseController_1 = __importDefault(require("./BaseController"));
|
|
8
|
-
/**
|
|
9
|
-
* Base class for tenant-independent search interfaces for platform admin
|
|
10
|
-
* @template T The service type this controller depends on
|
|
11
|
-
*/
|
|
12
|
-
class AdminSearchController extends AdminBaseController_1.default {
|
|
13
|
-
/**
|
|
14
|
-
* Search method for querying entities
|
|
15
|
-
* @returns Function that handles search requests
|
|
16
|
-
*/
|
|
17
|
-
search() {
|
|
18
|
-
return (req) => {
|
|
19
|
-
let query = req.query;
|
|
20
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`Path: ${req.path}, query by criteria:`, query);
|
|
21
|
-
return this.invokeServiceInterface('search', [query]);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.default = AdminSearchController;
|
|
26
|
-
//# sourceMappingURL=AdminSearchController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
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
|
-
*/
|
|
8
|
-
export default abstract class BaseController<T> {
|
|
9
|
-
/** Flag to enable debug logging */
|
|
10
|
-
static debugEnabled: boolean;
|
|
11
|
-
/** The service instance this controller uses */
|
|
12
|
-
protected readonly service: T;
|
|
13
|
-
/** Logger instance for this controller */
|
|
14
|
-
protected readonly logger: Logger;
|
|
15
|
-
/**
|
|
16
|
-
* Constructor for base controller
|
|
17
|
-
* @param service The service instance to inject
|
|
18
|
-
* @protected
|
|
19
|
-
*/
|
|
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;
|
|
28
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
*/
|
|
11
|
-
class BaseController {
|
|
12
|
-
/**
|
|
13
|
-
* Constructor for base controller
|
|
14
|
-
* @param service The service instance to inject
|
|
15
|
-
* @protected
|
|
16
|
-
*/
|
|
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
|
-
};
|
|
28
|
-
this.logger = log4js_1.default.getLogger(this.constructor.name);
|
|
29
|
-
this.service = service;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Flag to enable debug logging */
|
|
33
|
-
BaseController.debugEnabled = false;
|
|
34
|
-
exports.default = BaseController;
|
|
35
|
-
//# sourceMappingURL=BaseController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,96 +0,0 @@
|
|
|
1
|
-
import BaseController from "./BaseController";
|
|
2
|
-
import { ValidationRules } from "@ticatec/bean-validator";
|
|
3
|
-
import { RestfulFunction } from "../CommonRouterHelper";
|
|
4
|
-
import { Request } from "express";
|
|
5
|
-
/**
|
|
6
|
-
* Controller class that implements Create/Read/Update/Delete operations
|
|
7
|
-
* @template T The service type this controller depends on
|
|
8
|
-
*/
|
|
9
|
-
export default abstract class CommonController<T> extends BaseController<T> {
|
|
10
|
-
/**
|
|
11
|
-
* Entity validation rules
|
|
12
|
-
* @protected
|
|
13
|
-
*/
|
|
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
|
-
*/
|
|
21
|
-
protected constructor(service: T, rules?: ValidationRules);
|
|
22
|
-
/**
|
|
23
|
-
* Validates entity data
|
|
24
|
-
* @param data The data to validate
|
|
25
|
-
* @protected
|
|
26
|
-
*/
|
|
27
|
-
protected validateEntity(data: any): void;
|
|
28
|
-
/**
|
|
29
|
-
* Creates new entity endpoint
|
|
30
|
-
* @returns RESTful function for creating new entities
|
|
31
|
-
*/
|
|
32
|
-
createNew(): RestfulFunction;
|
|
33
|
-
/**
|
|
34
|
-
* Updates entity endpoint
|
|
35
|
-
* @returns RESTful function for updating entities
|
|
36
|
-
*/
|
|
37
|
-
update(): RestfulFunction;
|
|
38
|
-
/**
|
|
39
|
-
* Deletes entity endpoint
|
|
40
|
-
* @returns RESTful function for deleting entities
|
|
41
|
-
*/
|
|
42
|
-
del(): RestfulFunction;
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a service interface method exists
|
|
45
|
-
* @param name The method name to check
|
|
46
|
-
* @protected
|
|
47
|
-
*/
|
|
48
|
-
protected checkInterface(name: string): void;
|
|
49
|
-
/**
|
|
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
|
|
54
|
-
* @protected
|
|
55
|
-
*/
|
|
56
|
-
protected invokeServiceInterface(name: string, args?: Array<any>): Promise<any>;
|
|
57
|
-
protected buildNewEntry(req: Request): any;
|
|
58
|
-
protected buildUpdatedEntry(req: Request): any;
|
|
59
|
-
/**
|
|
60
|
-
* Creates a new entity
|
|
61
|
-
* @param req Express request object
|
|
62
|
-
* @returns Promise resolving to the created entity
|
|
63
|
-
* @protected
|
|
64
|
-
*/
|
|
65
|
-
protected _createNew(req: Request): Promise<any>;
|
|
66
|
-
/**
|
|
67
|
-
* Updates an entity
|
|
68
|
-
* @param req Express request object
|
|
69
|
-
* @returns Promise resolving to the updated entity
|
|
70
|
-
* @protected
|
|
71
|
-
*/
|
|
72
|
-
protected _update(req: Request): Promise<any>;
|
|
73
|
-
/**
|
|
74
|
-
* Deletes an entity
|
|
75
|
-
* @param req Express request object
|
|
76
|
-
* @returns Promise resolving when entity is deleted
|
|
77
|
-
* @protected
|
|
78
|
-
*/
|
|
79
|
-
protected _del(req: Request): Promise<any>;
|
|
80
|
-
/**
|
|
81
|
-
* Gets arguments for creating new entity
|
|
82
|
-
* @param req Express request object
|
|
83
|
-
* @returns Array of arguments to pass to service create method
|
|
84
|
-
* @protected
|
|
85
|
-
* @abstract
|
|
86
|
-
*/
|
|
87
|
-
protected abstract getCreateNewArguments(req: Request): Array<any>;
|
|
88
|
-
/**
|
|
89
|
-
* Gets arguments for updating entity
|
|
90
|
-
* @param req Express request object
|
|
91
|
-
* @returns Array of arguments to pass to service update method
|
|
92
|
-
* @protected
|
|
93
|
-
* @abstract
|
|
94
|
-
*/
|
|
95
|
-
protected abstract getUpdateArguments(req: Request): Array<any>;
|
|
96
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_exception_1 = require("@ticatec/express-exception");
|
|
7
|
-
const BaseController_1 = __importDefault(require("./BaseController"));
|
|
8
|
-
const bean_validator_1 = __importDefault(require("@ticatec/bean-validator"));
|
|
9
|
-
/**
|
|
10
|
-
* Controller class that implements Create/Read/Update/Delete operations
|
|
11
|
-
* @template T The service type this controller depends on
|
|
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
|
-
*/
|
|
20
|
-
constructor(service, rules = null) {
|
|
21
|
-
super(service);
|
|
22
|
-
this.rules = rules;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Validates entity data
|
|
26
|
-
* @param data The data to validate
|
|
27
|
-
* @protected
|
|
28
|
-
*/
|
|
29
|
-
validateEntity(data) {
|
|
30
|
-
let result = bean_validator_1.default.validate(data, this.rules);
|
|
31
|
-
if (!result.valid) {
|
|
32
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`Invalid data: ${result.errorMessage}`);
|
|
33
|
-
throw new express_exception_1.IllegalParameterError(result.errorMessage);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Creates new entity endpoint
|
|
38
|
-
* @returns RESTful function for creating new entities
|
|
39
|
-
*/
|
|
40
|
-
createNew() {
|
|
41
|
-
return async (req) => {
|
|
42
|
-
return this._createNew(req);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Updates entity endpoint
|
|
47
|
-
* @returns RESTful function for updating entities
|
|
48
|
-
*/
|
|
49
|
-
update() {
|
|
50
|
-
return async (req) => {
|
|
51
|
-
return this._update(req);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Deletes entity endpoint
|
|
56
|
-
* @returns RESTful function for deleting entities
|
|
57
|
-
*/
|
|
58
|
-
del() {
|
|
59
|
-
return async (req) => {
|
|
60
|
-
return this._del(req);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Checks if a service interface method exists
|
|
65
|
-
* @param name The method name to check
|
|
66
|
-
* @protected
|
|
67
|
-
*/
|
|
68
|
-
checkInterface(name) {
|
|
69
|
-
if (this.service[name] == null) {
|
|
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}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
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
|
|
79
|
-
* @protected
|
|
80
|
-
*/
|
|
81
|
-
async invokeServiceInterface(name, args = []) {
|
|
82
|
-
return await this.service[name](...args);
|
|
83
|
-
}
|
|
84
|
-
buildNewEntry(req) {
|
|
85
|
-
return req.body;
|
|
86
|
-
}
|
|
87
|
-
buildUpdatedEntry(req) {
|
|
88
|
-
return req.body;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Creates a new entity
|
|
92
|
-
* @param req Express request object
|
|
93
|
-
* @returns Promise resolving to the created entity
|
|
94
|
-
* @protected
|
|
95
|
-
*/
|
|
96
|
-
_createNew(req) {
|
|
97
|
-
let data = this.buildNewEntry(req);
|
|
98
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl} Request to create an entity`, data);
|
|
99
|
-
this.checkInterface('createNew');
|
|
100
|
-
this.validateEntity(data);
|
|
101
|
-
return this.invokeServiceInterface('createNew', this.getCreateNewArguments(req));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Updates an entity
|
|
105
|
-
* @param req Express request object
|
|
106
|
-
* @returns Promise resolving to the updated entity
|
|
107
|
-
* @protected
|
|
108
|
-
*/
|
|
109
|
-
_update(req) {
|
|
110
|
-
let data = this.buildUpdatedEntry(req);
|
|
111
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`${req.method} ${req.originalUrl} Request to update an entity`, data);
|
|
112
|
-
this.checkInterface('update');
|
|
113
|
-
this.validateEntity(data);
|
|
114
|
-
return this.invokeServiceInterface('update', this.getUpdateArguments(req));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Deletes an entity
|
|
118
|
-
* @param req Express request object
|
|
119
|
-
* @returns Promise resolving when entity is deleted
|
|
120
|
-
* @protected
|
|
121
|
-
*/
|
|
122
|
-
_del(req) {
|
|
123
|
-
// Please implement delete interface in subclass, otherwise system exception will be thrown
|
|
124
|
-
this.logger.warn('Current service does not have delete interface');
|
|
125
|
-
throw new express_exception_1.ActionNotFoundError('Current service does not have delete interface');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.default = CommonController;
|
|
129
|
-
//# sourceMappingURL=CommonController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommonController.js","sourceRoot":"src/","sources":["common/CommonController.ts"],"names":[],"mappings":";;;;;AACA,kEAAsF;AACtF,sEAA8C;AAC9C,6EAAuE;AAIvE;;;GAGG;AACH,MAA8B,gBAAoB,SAAQ,wBAAiB;IAQvE;;;;;OAKG;IACH,YAAsB,OAAU,EAAE,QAAyB,IAAI;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;Q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IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;QACnE,MAAM,IAAI,uCAAmB,CAAC,gDAAgD,CAAC,CAAC;IACpF,CAAC;CAmBJ;AAtJD,mCAsJC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import CommonController from "./CommonController";
|
|
2
|
-
import { ValidationRules } from "@ticatec/bean-validator";
|
|
3
|
-
import { Request } from "express";
|
|
4
|
-
/**
|
|
5
|
-
* Base class for tenant-specific interfaces
|
|
6
|
-
* @template T The service type this controller depends on
|
|
7
|
-
*/
|
|
8
|
-
export default abstract class TenantBaseController<T> extends CommonController<T> {
|
|
9
|
-
/**
|
|
10
|
-
* Constructor for tenant base controller
|
|
11
|
-
* @param service The service instance to inject
|
|
12
|
-
* @param rules Entity validation rules
|
|
13
|
-
* @protected
|
|
14
|
-
*/
|
|
15
|
-
protected constructor(service: any, rules: ValidationRules);
|
|
16
|
-
/**
|
|
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
|
|
20
|
-
* @protected
|
|
21
|
-
*/
|
|
22
|
-
protected getCreateNewArguments(req: Request): Array<any>;
|
|
23
|
-
/**
|
|
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
|
|
27
|
-
* @protected
|
|
28
|
-
*/
|
|
29
|
-
protected getUpdateArguments(req: Request): any[];
|
|
30
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const CommonController_1 = __importDefault(require("./CommonController"));
|
|
7
|
-
/**
|
|
8
|
-
* Base class for tenant-specific interfaces
|
|
9
|
-
* @template T The service type this controller depends on
|
|
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
|
-
*/
|
|
18
|
-
constructor(service, rules) {
|
|
19
|
-
super(service, rules);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
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
|
-
* @protected
|
|
26
|
-
*/
|
|
27
|
-
getCreateNewArguments(req) {
|
|
28
|
-
return [this.getLoggedUser(req), req.body];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
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
|
|
34
|
-
* @protected
|
|
35
|
-
*/
|
|
36
|
-
getUpdateArguments(req) {
|
|
37
|
-
return [this.getLoggedUser(req), req.body];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.default = TenantBaseController;
|
|
41
|
-
//# sourceMappingURL=TenantBaseController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,13 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import TenantBaseController from "./TenantBaseController";
|
|
3
|
-
/**
|
|
4
|
-
* Interface with search capabilities for tenant use
|
|
5
|
-
* @template T The service type this controller depends on
|
|
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
|
-
*/
|
|
12
|
-
search(): (req: Request) => Promise<any>;
|
|
13
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const TenantBaseController_1 = __importDefault(require("./TenantBaseController"));
|
|
7
|
-
const BaseController_1 = __importDefault(require("./BaseController"));
|
|
8
|
-
/**
|
|
9
|
-
* Interface with search capabilities for tenant use
|
|
10
|
-
* @template T The service type this controller depends on
|
|
11
|
-
*/
|
|
12
|
-
class TenantSearchController extends TenantBaseController_1.default {
|
|
13
|
-
/**
|
|
14
|
-
* Search method for querying entities with tenant context
|
|
15
|
-
* @returns Function that handles tenant-specific search requests
|
|
16
|
-
*/
|
|
17
|
-
search() {
|
|
18
|
-
return async (req) => {
|
|
19
|
-
let query = req.query;
|
|
20
|
-
BaseController_1.default.debugEnabled && this.logger.debug(`Path: ${req.path}, query by criteria:`, query);
|
|
21
|
-
this.checkInterface('search');
|
|
22
|
-
return await this.invokeServiceInterface('search', [this.getLoggedUser(req), query]);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.default = TenantSearchController;
|
|
27
|
-
//# sourceMappingURL=TenantSearchController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TenantSearchController.js","sourceRoot":"src/","sources":["common/TenantSearchController.ts"],"names":[],"mappings":";;;;;AACA,kFAA0D;AAC1D,sEAA8C;AAE9C;;;GAGG;AACH,MAA8B,sBAA0B,SAAQ,8BAAuB;IAEnF;;;OAGG;IACH,MAAM;QACF,OAAO,KAAK,EAAE,GAAW,EAAe,EAAE;YACtC,IAAI,KAAK,GAAO,GAAG,CAAC,KAAK,CAAC;YAC1B,wBAAc,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,IAAI,sBAAsB,EAAE,KAAK,CAAC,CAAC;YACjG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC9B,OAAO,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QACzF,CAAC,CAAA;IACL,CAAC;CAEJ;AAfD,yCAeC"}
|