@thzero/library_server 0.15.2 → 0.15.6

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.
Files changed (73) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +89 -89
  3. package/boot/index.js +384 -384
  4. package/boot/koa/index.js +157 -157
  5. package/boot/plugins/admin/index.js +6 -6
  6. package/boot/plugins/admin/news.js +35 -35
  7. package/boot/plugins/admin/users.js +35 -35
  8. package/boot/plugins/api.js +58 -59
  9. package/boot/plugins/apiFront.js +31 -31
  10. package/boot/plugins/index.js +71 -71
  11. package/boot/plugins/news.js +46 -46
  12. package/boot/plugins/users.js +48 -48
  13. package/boot/plugins/usersExtended.js +32 -32
  14. package/constants.js +45 -45
  15. package/data/baseNews.js +42 -42
  16. package/data/baseSettingsUser.js +9 -9
  17. package/data/baseUser.js +28 -28
  18. package/data/index.js +24 -24
  19. package/data/named.js +20 -20
  20. package/debug.log +9 -0
  21. package/errors/tokenExpired.js +7 -7
  22. package/license.md +8 -8
  23. package/middleware/authentication.js +67 -67
  24. package/middleware/authorization.js +180 -180
  25. package/ncupd.bat +1 -1
  26. package/package.json +14 -14
  27. package/push.sh +3 -0
  28. package/pushnpm.bat +1 -1
  29. package/pushversion.bat +3 -3
  30. package/repository/index.js +151 -151
  31. package/repository/usageMetrics/devnull.js +11 -11
  32. package/routes/admin/index.js +111 -111
  33. package/routes/admin/news.js +14 -14
  34. package/routes/admin/users.js +18 -18
  35. package/routes/baseNews.js +27 -27
  36. package/routes/baseUsers.js +106 -106
  37. package/routes/home.js +16 -16
  38. package/routes/index.js +31 -31
  39. package/routes/news.js +6 -6
  40. package/routes/plans.js +24 -24
  41. package/routes/users.js +6 -6
  42. package/routes/utility.js +34 -34
  43. package/routes/version.js +24 -24
  44. package/service/admin/baseNews.js +45 -45
  45. package/service/admin/index.js +130 -130
  46. package/service/admin/news.js +6 -6
  47. package/service/admin/users.js +107 -107
  48. package/service/baseSecurity.js +44 -44
  49. package/service/baseUser.js +122 -122
  50. package/service/communication.js +6 -6
  51. package/service/config.js +32 -32
  52. package/service/crypto.js +16 -16
  53. package/service/discovery/index.js +6 -6
  54. package/service/discovery/resources/index.js +101 -101
  55. package/service/external.js +19 -19
  56. package/service/externalRest.js +19 -19
  57. package/service/index.js +20 -20
  58. package/service/news/base.js +49 -49
  59. package/service/news/index.js +6 -6
  60. package/service/news/validation/index.js +6 -6
  61. package/service/plans.js +27 -27
  62. package/service/restCommunication.js +21 -21
  63. package/service/usageMetrics.js +63 -63
  64. package/service/utility.js +37 -37
  65. package/service/version.js +32 -32
  66. package/utility/injector.js +59 -59
  67. package/utility/internalIp/index.js +48 -48
  68. package/utility/list/doubleLinked.js +88 -88
  69. package/utility/list/priorityQueue.js +109 -109
  70. package/utility/list/queue.js +72 -72
  71. package/utility/os.js +22 -22
  72. package/version.bat +1 -1
  73. package/version.sh +1 -0
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
3
  "type": "module",
4
- "version": "0.15.2",
4
+ "version": "0.15.6",
5
5
  "version_major": 0,
6
6
  "version_minor": 15,
7
- "version_patch": 2,
8
- "version_date": "10/20/2021",
7
+ "version_patch": 6,
8
+ "version_date": "01/29/2022",
9
9
  "description": "An opinionated library of common functionality to bootstrap a Koa based API application using MongoDb and Firebase.",
10
10
  "author": "thZero",
11
11
  "license": "MIT",
@@ -26,15 +26,15 @@
26
26
  "test": "echo \"Error: no test specified\" && exit 1"
27
27
  },
28
28
  "dependencies": {
29
- "@godaddy/terminus": "^4.9.0",
29
+ "@godaddy/terminus": "^4.10.2",
30
30
  "@koa/cors": "^3.1.0",
31
31
  "@koa/router": "^10.1.1",
32
32
  "async-mutex": "^0.3.2",
33
- "config": "^3.3.6",
33
+ "config": "^3.3.7",
34
34
  "dayjs": "^1.10.7",
35
35
  "dayjs-plugin-utc": "^0.1.2",
36
36
  "default-gateway": "^6.0.3",
37
- "easy-rbac": "^3.1.1",
37
+ "easy-rbac": "^3.2.0",
38
38
  "esm": "^3.2.25",
39
39
  "ipaddr.js": "^2.0.1",
40
40
  "koa": "^2.13.4",
@@ -43,19 +43,19 @@
43
43
  "koa-static": "^5.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@thzero/library_cli": "^0.13.21"
46
+ "@thzero/library_cli": "^0.15.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@thzero/library_common": "^0.15",
50
50
  "@thzero/library_common_service": "^0.15",
51
- "@babel/core": "^7.15.8",
52
- "@babel/plugin-proposal-class-properties": "^7.14.5",
53
- "@babel/preset-env": "^7.15.8",
54
- "babel-loader": "^8.2.2",
55
- "eslint": "^8.0.1",
51
+ "@babel/core": "^7.16.7",
52
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
53
+ "@babel/preset-env": "^7.16.7",
54
+ "babel-loader": "^8.2.3",
55
+ "eslint": "^8.5.0",
56
56
  "eslint-plugin-node": "^11.1.0",
57
- "pino-pretty": "^7.1.0",
58
- "webpack": "^5.59.0",
57
+ "pino-pretty": "^7.3.0",
58
+ "webpack": "^5.65.0",
59
59
  "webpack-cli": "^4.9.1"
60
60
  }
61
61
  }
package/push.sh ADDED
@@ -0,0 +1,3 @@
1
+ git add .
2
+ git commit -m "$1"
3
+ git push
package/pushnpm.bat CHANGED
@@ -1,2 +1,2 @@
1
- call ncupd
1
+ call ncupd
2
2
  call pushversion "npm updates
package/pushversion.bat CHANGED
@@ -1,4 +1,4 @@
1
- call npm run cli-update-w -- --silent
2
- call git add .
3
- call git commit -m %1
1
+ call npm run cli-update-w -- --silent
2
+ call git add .
3
+ call git commit -m %1
4
4
  call git push
@@ -1,151 +1,151 @@
1
- import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
2
-
3
- import Response from '@thzero/library_common/response';
4
- import ExtractResponse from '@thzero/library_common/response/extract';
5
-
6
- class Repository {
7
- async init(injector) {
8
- this._injector = injector;
9
- }
10
-
11
- get _config() {
12
- return this._injector.getService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG)
13
- }
14
-
15
- _enforce(clazz, method, value, name, correlationId) {
16
- if (!value) {
17
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
18
- const error = Error(`Invalid ${name}`, true);
19
- error.correlationId = correlationId;
20
- throw error;
21
- }
22
- }
23
-
24
- _enforceNotEmpty(clazz, method, value, name, correlationId) {
25
- if (String.isNullOrEmpty(value)) {
26
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
27
- const error = Error(`Invalid ${name}`, true);
28
- error.correlationId = correlationId;
29
- throw error;
30
- }
31
- }
32
-
33
- _enforceNotNull(clazz, method, value, name, correlationId) {
34
- if (!value) {
35
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
36
- const error = Error(`Invalid ${name}`, true);
37
- error.correlationId = correlationId;
38
- throw error;
39
- }
40
- }
41
-
42
- _enforce(clazz, method, value, name, correlationId) {
43
- if (!value) {
44
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
45
- return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
46
- }
47
-
48
- return this._success(correlationId);
49
- }
50
-
51
- _enforceNotEmptyResponse(clazz, method, value, name, correlationId) {
52
- if (String.isNullOrEmpty(value)) {
53
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
54
- return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
55
- }
56
-
57
- return this._success(correlationId);
58
- }
59
-
60
- _enforceNotNullResponse(clazz, method, value, name, correlationId) {
61
- if (!value) {
62
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
63
- return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
64
- }
65
-
66
- return this._success(correlationId);
67
- }
68
-
69
- _enforceNotEmptyAsResponse(clazz, method, value, name, correlationId) {
70
- if (String.isNullOrEmpty(value)) {
71
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
72
- return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
73
- }
74
-
75
- return this._successResponse(null, correlationId);
76
- }
77
-
78
- _enforceNotNullAsResponse(clazz, method, value, name, correlationId) {
79
- if (!value) {
80
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
81
- return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
82
- }
83
-
84
- return this._successResponse(null, correlationId);
85
- }
86
-
87
- _enforceResponse(clazz, method, response, name, correlationId) {
88
- if (!response || (response && !response.success)) {
89
- this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
90
- const error = Error(`Unsuccessful response for ${name}`, true);
91
- error.correlationId = correlationId;
92
- throw error;
93
- }
94
- }
95
-
96
- _error(clazz, method, message, err, code, errors, correlationId) {
97
- if (message)
98
- this._logger.error(clazz, method, message, null, correlationId);
99
- if (err)
100
- this._logger.exception(clazz, method, err, correlationId);
101
- if (code)
102
- this._logger.error(clazz, method, 'code', code, correlationId);
103
- if (errors) {
104
- for (const error of errors)
105
- this._logger.exception(clazz, method, error, correlationId);
106
- }
107
- return Response.error(clazz, method, message, err, code, errors, correlationId);
108
- }
109
-
110
- _hasFailed(response) {
111
- return Response.hasFailed(response);
112
- }
113
-
114
- _hasSucceeded(response) {
115
- return Response.hasSucceeded(response);
116
- }
117
-
118
- _initResponse(correlationId) {
119
- return new Response(correlationId);
120
- }
121
-
122
- _initResponseExtract(correlationId) {
123
- return new ExtractResponse(correlationId);
124
- }
125
-
126
- get _logger() {
127
- return this._injector.getService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER)
128
- }
129
-
130
- _success(correlationId) {
131
- return Response.success(correlationId);
132
- }
133
-
134
- _successResponse(value, correlationId) {
135
- return Response.success(correlationId, value);
136
- }
137
-
138
- _warn(clazz, method, message, err, code, errors, correlationId) {
139
- if (message)
140
- this._logger.warn(clazz, method, message, null, correlationId);
141
- if (err)
142
- this._logger.warn(clazz, method, err.message, null, correlationId);
143
- if (code)
144
- this._logger.warn(clazz, method, 'code', code, correlationId);
145
- if (errors)
146
- this._logger.warn(clazz, method, null, errors, correlationId);
147
- return Response.error(clazz, method, message, err, code, errors, correlationId);
148
- }
149
- }
150
-
151
- export default Repository;
1
+ import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
2
+
3
+ import Response from '@thzero/library_common/response';
4
+ import ExtractResponse from '@thzero/library_common/response/extract';
5
+
6
+ class Repository {
7
+ async init(injector) {
8
+ this._injector = injector;
9
+ }
10
+
11
+ get _config() {
12
+ return this._injector.getService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG)
13
+ }
14
+
15
+ _enforce(clazz, method, value, name, correlationId) {
16
+ if (!value) {
17
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
18
+ const error = Error(`Invalid ${name}`, true);
19
+ error.correlationId = correlationId;
20
+ throw error;
21
+ }
22
+ }
23
+
24
+ _enforceNotEmpty(clazz, method, value, name, correlationId) {
25
+ if (String.isNullOrEmpty(value)) {
26
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
27
+ const error = Error(`Invalid ${name}`, true);
28
+ error.correlationId = correlationId;
29
+ throw error;
30
+ }
31
+ }
32
+
33
+ _enforceNotNull(clazz, method, value, name, correlationId) {
34
+ if (!value) {
35
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
36
+ const error = Error(`Invalid ${name}`, true);
37
+ error.correlationId = correlationId;
38
+ throw error;
39
+ }
40
+ }
41
+
42
+ _enforce(clazz, method, value, name, correlationId) {
43
+ if (!value) {
44
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
45
+ return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
46
+ }
47
+
48
+ return this._success(correlationId);
49
+ }
50
+
51
+ _enforceNotEmptyResponse(clazz, method, value, name, correlationId) {
52
+ if (String.isNullOrEmpty(value)) {
53
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
54
+ return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
55
+ }
56
+
57
+ return this._success(correlationId);
58
+ }
59
+
60
+ _enforceNotNullResponse(clazz, method, value, name, correlationId) {
61
+ if (!value) {
62
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
63
+ return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
64
+ }
65
+
66
+ return this._success(correlationId);
67
+ }
68
+
69
+ _enforceNotEmptyAsResponse(clazz, method, value, name, correlationId) {
70
+ if (String.isNullOrEmpty(value)) {
71
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
72
+ return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
73
+ }
74
+
75
+ return this._successResponse(null, correlationId);
76
+ }
77
+
78
+ _enforceNotNullAsResponse(clazz, method, value, name, correlationId) {
79
+ if (!value) {
80
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
81
+ return Response.error(clazz, method, `Invalid ${name}`, null, null, null, correlationId);
82
+ }
83
+
84
+ return this._successResponse(null, correlationId);
85
+ }
86
+
87
+ _enforceResponse(clazz, method, response, name, correlationId) {
88
+ if (!response || (response && !response.success)) {
89
+ this._logger.error(clazz, method, `Invalid ${name}`, null, correlationId);
90
+ const error = Error(`Unsuccessful response for ${name}`, true);
91
+ error.correlationId = correlationId;
92
+ throw error;
93
+ }
94
+ }
95
+
96
+ _error(clazz, method, message, err, code, errors, correlationId) {
97
+ if (message)
98
+ this._logger.error(clazz, method, message, null, correlationId);
99
+ if (err)
100
+ this._logger.exception(clazz, method, err, correlationId);
101
+ if (code)
102
+ this._logger.error(clazz, method, 'code', code, correlationId);
103
+ if (errors) {
104
+ for (const error of errors)
105
+ this._logger.exception(clazz, method, error, correlationId);
106
+ }
107
+ return Response.error(clazz, method, message, err, code, errors, correlationId);
108
+ }
109
+
110
+ _hasFailed(response) {
111
+ return Response.hasFailed(response);
112
+ }
113
+
114
+ _hasSucceeded(response) {
115
+ return Response.hasSucceeded(response);
116
+ }
117
+
118
+ _initResponse(correlationId) {
119
+ return new Response(correlationId);
120
+ }
121
+
122
+ _initResponseExtract(correlationId) {
123
+ return new ExtractResponse(correlationId);
124
+ }
125
+
126
+ get _logger() {
127
+ return this._injector.getService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER)
128
+ }
129
+
130
+ _success(correlationId) {
131
+ return Response.success(correlationId);
132
+ }
133
+
134
+ _successResponse(value, correlationId) {
135
+ return Response.success(correlationId, value);
136
+ }
137
+
138
+ _warn(clazz, method, message, err, code, errors, correlationId) {
139
+ if (message)
140
+ this._logger.warn(clazz, method, message, null, correlationId);
141
+ if (err)
142
+ this._logger.warn(clazz, method, err.message, null, correlationId);
143
+ if (code)
144
+ this._logger.warn(clazz, method, 'code', code, correlationId);
145
+ if (errors)
146
+ this._logger.warn(clazz, method, null, errors, correlationId);
147
+ return Response.error(clazz, method, message, err, code, errors, correlationId);
148
+ }
149
+ }
150
+
151
+ export default Repository;
@@ -1,11 +1,11 @@
1
- import Repository from '../index';
2
-
3
- class DevNullUsageMetricsRepository extends Repository {
4
- async register(usageMetrics) {
5
- const correlationId = usageMetrics ? usageMetrics.correlationId : null;
6
- // Do nothing here.
7
- return this._success(correlationId);
8
- }
9
- }
10
-
11
- export default DevNullUsageMetricsRepository;
1
+ import Repository from '../index';
2
+
3
+ class DevNullUsageMetricsRepository extends Repository {
4
+ async register(usageMetrics) {
5
+ const correlationId = usageMetrics ? usageMetrics.correlationId : null;
6
+ // Do nothing here.
7
+ return this._success(correlationId);
8
+ }
9
+ }
10
+
11
+ export default DevNullUsageMetricsRepository;
@@ -1,111 +1,111 @@
1
- import koaBody from 'koa-body';
2
-
3
- import Utility from '@thzero/library_common/utility';
4
-
5
- import BaseRoute from '../index';
6
-
7
- import authentication from '../../middleware/authentication';
8
- import authorization from '../../middleware/authorization';
9
-
10
- class AdminBaseRoute extends BaseRoute {
11
- constructor(urlFragment, role, serviceKey) {
12
- if (!urlFragment)
13
- throw Error('Invalid url fragment');
14
-
15
- super(`/api/admin/${urlFragment}`);
16
-
17
- this._options = {
18
- role: role,
19
- serviceKey: serviceKey
20
- }
21
- }
22
-
23
- _allowsCreate() {
24
- return true;
25
- }
26
-
27
- _allowsDelete() {
28
- return true;
29
- }
30
-
31
- _allowsUpdate() {
32
- return true;
33
- }
34
-
35
- _initializeRoutesCreate(router) {
36
- const self = this;
37
- router.post('/',
38
- authentication(true),
39
- authorization([ `${self._options.role}.create` ]),
40
- koaBody({
41
- text: false,
42
- }),
43
- // eslint-disable-next-line
44
- async (ctx, next) => {
45
- const service = this._injector.getService(self._options.serviceKey);
46
- const response = (await service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
47
- ctx.body = Utility.stringify(response);
48
- }
49
- );
50
- }
51
-
52
- _initializeRoutesDelete(router) {
53
- const self = this;
54
- router.delete('/:id',
55
- authentication(true),
56
- authorization([ `${self._options.role}.delete` ]),
57
- // eslint-disable-next-line
58
- async (ctx, next) => {
59
- const service = this._injector.getService(self._options.serviceKey);
60
- const response = (await service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
61
- ctx.body = Utility.stringify(response);
62
- }
63
- );
64
- }
65
-
66
- _initializeRoutesUpdate(router) {
67
- const self = this;
68
- router.post('/:id',
69
- authentication(true),
70
- authorization([ `${self._options.role}.update` ]),
71
- koaBody({
72
- text: false,
73
- }),
74
- // eslint-disable-next-line
75
- async (ctx, next) => {
76
- const service = this._injector.getService(self._options.serviceKey);
77
- const response = (await service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
78
- ctx.body = Utility.stringify(response);
79
- }
80
- );
81
- }
82
-
83
- _initializeRoutes(router) {
84
- if (this._allowsDelete)
85
- this._initializeRoutesDelete(router);
86
-
87
- router.post('/search',
88
- authentication(true),
89
- authorization([ `${this._options.role}.search` ]),
90
- koaBody({
91
- text: false,
92
- }),
93
- // eslint-disable-next-line
94
- async (ctx, next) => {
95
- const service = this._injector.getService(this._options.serviceKey);
96
- const response = (await service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
97
- ctx.body = Utility.stringify(response);
98
- }
99
- );
100
-
101
- if (this._allowsUpdate())
102
- this._initializeRoutesUpdate(router);
103
-
104
- if (this._allowsCreate())
105
- this._initializeRoutesCreate(router);
106
-
107
- return router;
108
- }
109
- }
110
-
111
- export default AdminBaseRoute;
1
+ import koaBody from 'koa-body';
2
+
3
+ import Utility from '@thzero/library_common/utility';
4
+
5
+ import BaseRoute from '../index';
6
+
7
+ import authentication from '../../middleware/authentication';
8
+ import authorization from '../../middleware/authorization';
9
+
10
+ class AdminBaseRoute extends BaseRoute {
11
+ constructor(urlFragment, role, serviceKey) {
12
+ if (!urlFragment)
13
+ throw Error('Invalid url fragment');
14
+
15
+ super(`/api/admin/${urlFragment}`);
16
+
17
+ this._options = {
18
+ role: role,
19
+ serviceKey: serviceKey
20
+ }
21
+ }
22
+
23
+ _allowsCreate() {
24
+ return true;
25
+ }
26
+
27
+ _allowsDelete() {
28
+ return true;
29
+ }
30
+
31
+ _allowsUpdate() {
32
+ return true;
33
+ }
34
+
35
+ _initializeRoutesCreate(router) {
36
+ const self = this;
37
+ router.post('/',
38
+ authentication(true),
39
+ authorization([ `${self._options.role}.create` ]),
40
+ koaBody({
41
+ text: false,
42
+ }),
43
+ // eslint-disable-next-line
44
+ async (ctx, next) => {
45
+ const service = this._injector.getService(self._options.serviceKey);
46
+ const response = (await service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
47
+ ctx.body = Utility.stringify(response);
48
+ }
49
+ );
50
+ }
51
+
52
+ _initializeRoutesDelete(router) {
53
+ const self = this;
54
+ router.delete('/:id',
55
+ authentication(true),
56
+ authorization([ `${self._options.role}.delete` ]),
57
+ // eslint-disable-next-line
58
+ async (ctx, next) => {
59
+ const service = this._injector.getService(self._options.serviceKey);
60
+ const response = (await service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
61
+ ctx.body = Utility.stringify(response);
62
+ }
63
+ );
64
+ }
65
+
66
+ _initializeRoutesUpdate(router) {
67
+ const self = this;
68
+ router.post('/:id',
69
+ authentication(true),
70
+ authorization([ `${self._options.role}.update` ]),
71
+ koaBody({
72
+ text: false,
73
+ }),
74
+ // eslint-disable-next-line
75
+ async (ctx, next) => {
76
+ const service = this._injector.getService(self._options.serviceKey);
77
+ const response = (await service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
78
+ ctx.body = Utility.stringify(response);
79
+ }
80
+ );
81
+ }
82
+
83
+ _initializeRoutes(router) {
84
+ if (this._allowsDelete)
85
+ this._initializeRoutesDelete(router);
86
+
87
+ router.post('/search',
88
+ authentication(true),
89
+ authorization([ `${this._options.role}.search` ]),
90
+ koaBody({
91
+ text: false,
92
+ }),
93
+ // eslint-disable-next-line
94
+ async (ctx, next) => {
95
+ const service = this._injector.getService(this._options.serviceKey);
96
+ const response = (await service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
97
+ ctx.body = Utility.stringify(response);
98
+ }
99
+ );
100
+
101
+ if (this._allowsUpdate())
102
+ this._initializeRoutesUpdate(router);
103
+
104
+ if (this._allowsCreate())
105
+ this._initializeRoutesCreate(router);
106
+
107
+ return router;
108
+ }
109
+ }
110
+
111
+ export default AdminBaseRoute;
@@ -1,14 +1,14 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import AdminRoute from './index'
4
-
5
- class NewsAdminRoute extends AdminRoute {
6
- constructor(urlFragment, role, serviceKey) {
7
- urlFragment = urlFragment ? urlFragment : 'news';
8
- role = role ? role : 'news';
9
- serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
10
- super(urlFragment, role, serviceKey);
11
- }
12
- }
13
-
14
- export default NewsAdminRoute;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import AdminRoute from './index'
4
+
5
+ class NewsAdminRoute extends AdminRoute {
6
+ constructor(urlFragment, role, serviceKey) {
7
+ urlFragment = urlFragment ? urlFragment : 'news';
8
+ role = role ? role : 'news';
9
+ serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
10
+ super(urlFragment, role, serviceKey);
11
+ }
12
+ }
13
+
14
+ export default NewsAdminRoute;