@pxp-nd/core 1.1.19 → 1.2.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.
|
@@ -125,6 +125,7 @@ class Controller {
|
|
|
125
125
|
const dbsettings = Reflect.getMetadata('dbsettings', this.constructor) || {};
|
|
126
126
|
// get logConfig
|
|
127
127
|
const logConfig = Reflect.getMetadata('logConfig', this.constructor) || {};
|
|
128
|
+
const defaultConfig = Reflect.getMetadata('optionsRoute', this.constructor) || {};
|
|
128
129
|
// define basic routes
|
|
129
130
|
if (this.modelString !== '') {
|
|
130
131
|
routes = lodash_1.default.union(this.basicRoutes, routes);
|
|
@@ -132,15 +133,18 @@ class Controller {
|
|
|
132
133
|
}
|
|
133
134
|
routes.forEach((route) => {
|
|
134
135
|
const methodDbSettings = dbsettings[route.methodName] || this.config.defaultDbSettings;
|
|
135
|
-
|
|
136
|
+
// readOnly
|
|
137
|
+
const readOnlyMethod = readonly[route.methodName] !== undefined ? readonly[route.methodName] : defaultConfig[route.methodName].readOnly;
|
|
138
|
+
if (readOnlyMethod === null || readOnlyMethod === undefined) {
|
|
136
139
|
throw new index_1.PxpError(500, 'ReadOnly decorator was not defined for ' +
|
|
137
140
|
route.methodName +
|
|
138
141
|
' in ' +
|
|
139
142
|
this.constructor.name +
|
|
140
143
|
' controller.');
|
|
141
144
|
}
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
// auth
|
|
146
|
+
const auth = authentication[route.methodName] !== undefined ? authentication[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].authentication : true);
|
|
147
|
+
if (!auth) {
|
|
144
148
|
this.router[route.requestMethod](this.config.apiPrefix + '/' + this.module + this.path + route.path,
|
|
145
149
|
// MIDDLEWARES AREA
|
|
146
150
|
[
|
|
@@ -156,7 +160,7 @@ class Controller {
|
|
|
156
160
|
.toLowerCase();
|
|
157
161
|
this.validated = false;
|
|
158
162
|
try {
|
|
159
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings,
|
|
163
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, log[route.methodName], logConfig[route.methodName]));
|
|
160
164
|
}
|
|
161
165
|
catch (ex) {
|
|
162
166
|
const now = new Date();
|
|
@@ -189,7 +193,7 @@ class Controller {
|
|
|
189
193
|
.toLowerCase();
|
|
190
194
|
this.validated = false;
|
|
191
195
|
try {
|
|
192
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings,
|
|
196
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], log[route.methodName], logConfig[route.methodName]));
|
|
193
197
|
}
|
|
194
198
|
catch (ex) {
|
|
195
199
|
const now = new Date();
|
|
@@ -16,12 +16,17 @@ exports.StoredProcedure = exports.Model = exports.ReadOnly = exports.DbSettings
|
|
|
16
16
|
*/
|
|
17
17
|
const RouteDefinition_1 = require("./RouteDefinition");
|
|
18
18
|
;
|
|
19
|
-
const setProperty = (target, propertyKey) => (value, name) => {
|
|
19
|
+
const setProperty = (target, propertyKey) => (value, name, overwrite = true) => {
|
|
20
20
|
if (!Reflect.hasMetadata(name, target.constructor)) {
|
|
21
|
-
Reflect.defineMetadata(name,
|
|
21
|
+
Reflect.defineMetadata(name, {}, target.constructor);
|
|
22
22
|
}
|
|
23
23
|
const valueName = Reflect.getMetadata(name, target.constructor);
|
|
24
|
-
valueName[propertyKey]
|
|
24
|
+
if (!overwrite && !valueName[propertyKey]) {
|
|
25
|
+
valueName[propertyKey] = value;
|
|
26
|
+
}
|
|
27
|
+
else if (overwrite) {
|
|
28
|
+
valueName[propertyKey] = value;
|
|
29
|
+
}
|
|
25
30
|
Reflect.defineMetadata(name, valueName, target.constructor);
|
|
26
31
|
};
|
|
27
32
|
const createOptions = (options = {
|
|
@@ -29,13 +34,24 @@ const createOptions = (options = {
|
|
|
29
34
|
dbSettings: 'Orm',
|
|
30
35
|
authentication: true,
|
|
31
36
|
}) => (target, propertyKey) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
37
|
+
options = Object.assign({
|
|
38
|
+
readOnly: true,
|
|
39
|
+
dbSettings: 'Orm',
|
|
40
|
+
authentication: true,
|
|
41
|
+
}, options);
|
|
42
|
+
// const newProperty = setProperty(target, propertyKey);
|
|
43
|
+
// // ReadOnly
|
|
44
|
+
// newProperty(options.readOnly, 'readonly', false);
|
|
45
|
+
// // DbSettings
|
|
46
|
+
// newProperty(options.dbSettings, 'dbsettings', false);
|
|
47
|
+
// // Authentication
|
|
48
|
+
// newProperty(options.authentication, 'authentication', false);
|
|
49
|
+
if (!Reflect.hasMetadata('optionsRoute', target.constructor)) {
|
|
50
|
+
Reflect.defineMetadata('optionsRoute', {}, target.constructor);
|
|
51
|
+
}
|
|
52
|
+
const optionsRoute = Reflect.getMetadata('optionsRoute', target.constructor);
|
|
53
|
+
optionsRoute[propertyKey] = options;
|
|
54
|
+
Reflect.defineMetadata('optionsRoute', optionsRoute, target.constructor);
|
|
39
55
|
};
|
|
40
56
|
const setRoute = (path = '', method, options) => (target, propertyKey) => {
|
|
41
57
|
if (!Reflect.hasMetadata('routes', target.constructor)) {
|
|
@@ -23,7 +23,9 @@ const socket_io_1 = require("socket.io");
|
|
|
23
23
|
const mainSockets = __importStar(require("./basic-sockets"));
|
|
24
24
|
class PxpIOServer {
|
|
25
25
|
constructor(server, sockets) {
|
|
26
|
-
this.io = new socket_io_1.Server(server
|
|
26
|
+
this.io = new socket_io_1.Server(server, { cors: {
|
|
27
|
+
origin: '*',
|
|
28
|
+
} });
|
|
27
29
|
this.listenSockets(sockets);
|
|
28
30
|
}
|
|
29
31
|
listenSockets(sockets = {}) {
|