@pxp-nd/core 1.2.1 → 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
- if (!(route.methodName in readonly)) {
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
- if (route.methodName in authentication &&
143
- authentication[route.methodName] === false) {
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, readonly[route.methodName], false, log[route.methodName], logConfig[route.methodName]));
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, readonly[route.methodName], permission[route.methodName], log[route.methodName], logConfig[route.methodName]));
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();
@@ -21,10 +21,10 @@ const setProperty = (target, propertyKey) => (value, name, overwrite = true) =>
21
21
  Reflect.defineMetadata(name, {}, target.constructor);
22
22
  }
23
23
  const valueName = Reflect.getMetadata(name, target.constructor);
24
- if (overwrite && valueName[propertyKey]) {
24
+ if (!overwrite && !valueName[propertyKey]) {
25
25
  valueName[propertyKey] = value;
26
26
  }
27
- else if (!valueName[propertyKey]) {
27
+ else if (overwrite) {
28
28
  valueName[propertyKey] = value;
29
29
  }
30
30
  Reflect.defineMetadata(name, valueName, target.constructor);
@@ -34,13 +34,24 @@ const createOptions = (options = {
34
34
  dbSettings: 'Orm',
35
35
  authentication: true,
36
36
  }) => (target, propertyKey) => {
37
- const newProperty = setProperty(target, propertyKey);
38
- // ReadOnly
39
- newProperty(options.readOnly, 'readonly', false);
40
- // DbSettings
41
- newProperty(options.dbSettings, 'dbsettings', false);
42
- // Authentication
43
- newProperty(options.authentication, 'authentication', false);
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);
44
55
  };
45
56
  const setRoute = (path = '', method, options) => (target, propertyKey) => {
46
57
  if (!Reflect.hasMetadata('routes', target.constructor)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/core",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Contains main files for pxp-nd",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",