@thzero/library_server_fastify 0.16.9 → 0.16.10

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.
@@ -1,136 +1,136 @@
1
- import BaseRoute from '../index.js';
2
-
3
- class AdminBaseRoute extends BaseRoute {
4
- constructor(urlFragment, role, serviceKey) {
5
- if (!urlFragment)
6
- throw Error('Invalid url fragment');
7
-
8
- super(`/admin/${urlFragment}`);
9
-
10
- this._options = {
11
- role: role,
12
- serviceKey: serviceKey
13
- }
14
-
15
- // this._service = null;
16
- }
17
-
18
- async init(injector, app, config) {
19
- await super.init(injector, app, config);
20
- this._inject(app, injector, this._options.serviceKey, this._options.serviceKey);
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(this._join(''),
38
- // authentication(true),
39
- // authorization([ `${self._options.role}.create` ]),
40
- {
41
- preHandler: router.auth([
42
- router.authenticationDefault,
43
- router.authorizationDefault
44
- ],
45
- {
46
- relation: 'and',
47
- roles: [ `${self._options.role}.create` ]
48
- }),
49
- },
50
- // eslint-disable-next-line
51
- async (request, reply) => {
52
- const response = (await router[this._options.serviceKey].create(request.correlationId, request.user, request.body)).check(request);
53
- this._jsonResponse(reply, response);
54
- }
55
- );
56
- }
57
-
58
- _initializeRoutesDelete(router) {
59
- router.delete(this._join('/:id'),
60
- // authentication(true),
61
- // authorization([ `${this._options.role}.delete` ]),
62
- {
63
- preHandler: router.auth([
64
- router.authenticationDefault,
65
- router.authorizationDefault
66
- ],
67
- {
68
- relation: 'and',
69
- roles: [ `${this._options.role}.delete` ]
70
- }),
71
- },
72
- // eslint-disable-next-line
73
- async (request, reply) => {
74
- const response = (await router[this._options.serviceKey].delete(request.correlationId, request.user, request.params.id)).check(request);
75
- this._jsonResponse(reply, response);
76
- }
77
- );
78
- }
79
-
80
- _initializeRoutesUpdate(router) {
81
- router.post(this._join('/:id'),
82
- // authentication(true),
83
- // authorization([ `${this._options.role}.update` ]),
84
- {
85
- preHandler: router.auth([
86
- router.authenticationDefault,
87
- router.authorizationDefault
88
- ],
89
- {
90
- relation: 'and',
91
- roles: [ `${this._options.role}.update` ]
92
- }),
93
- },
94
- // eslint-disable-next-line
95
- async (request, reply) => {
96
- const response = (await router[this._options.serviceKey].update(request.correlationId, request.user, request.params.id, request.body)).check(request);
97
- this._jsonResponse(reply, response);
98
- }
99
- );
100
- }
101
-
102
- _initializeRoutes(router) {
103
- if (this._allowsDelete)
104
- this._initializeRoutesDelete(router);
105
-
106
- router.post(this._join('/search'),
107
- // authentication(true),
108
- // authorization([ `${this._options.role}.search` ]),
109
- {
110
- preHandler: router.auth([
111
- router.authenticationDefault,
112
- router.authorizationDefault
113
- ],
114
- {
115
- relation: 'and',
116
- roles: [ `${this._options.role}.search` ]
117
- }),
118
- },
119
- // eslint-disable-next-line
120
- async (request, reply) => {
121
- const response = (await router[this._options.serviceKey].search(request.correlationId, request.user, request.body)).check(request);
122
- this._jsonResponse(reply, response);
123
- }
124
- );
125
-
126
- if (this._allowsUpdate())
127
- this._initializeRoutesUpdate(router);
128
-
129
- if (this._allowsCreate())
130
- this._initializeRoutesCreate(router);
131
-
132
- return router;
133
- }
134
- }
135
-
136
- export default AdminBaseRoute;
1
+ import BaseRoute from '../index.js';
2
+
3
+ class AdminBaseRoute extends BaseRoute {
4
+ constructor(urlFragment, role, serviceKey) {
5
+ if (!urlFragment)
6
+ throw Error('Invalid url fragment');
7
+
8
+ super(`/admin/${urlFragment}`);
9
+
10
+ this._options = {
11
+ role: role,
12
+ serviceKey: serviceKey
13
+ }
14
+
15
+ // this._service = null;
16
+ }
17
+
18
+ async init(injector, app, config) {
19
+ await super.init(injector, app, config);
20
+ this._inject(app, injector, this._options.serviceKey, this._options.serviceKey);
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(this._join(''),
38
+ // authentication(true),
39
+ // authorization([ `${self._options.role}.create` ]),
40
+ {
41
+ preHandler: router.auth([
42
+ router.authenticationDefault,
43
+ router.authorizationDefault
44
+ ],
45
+ {
46
+ relation: 'and',
47
+ roles: [ `${self._options.role}.create` ]
48
+ }),
49
+ },
50
+ // eslint-disable-next-line
51
+ async (request, reply) => {
52
+ const response = (await router[this._options.serviceKey].create(request.correlationId, request.user, request.body)).check(request);
53
+ this._jsonResponse(reply, response);
54
+ }
55
+ );
56
+ }
57
+
58
+ _initializeRoutesDelete(router) {
59
+ router.delete(this._join('/:id'),
60
+ // authentication(true),
61
+ // authorization([ `${this._options.role}.delete` ]),
62
+ {
63
+ preHandler: router.auth([
64
+ router.authenticationDefault,
65
+ router.authorizationDefault
66
+ ],
67
+ {
68
+ relation: 'and',
69
+ roles: [ `${this._options.role}.delete` ]
70
+ }),
71
+ },
72
+ // eslint-disable-next-line
73
+ async (request, reply) => {
74
+ const response = (await router[this._options.serviceKey].delete(request.correlationId, request.user, request.params.id)).check(request);
75
+ this._jsonResponse(reply, response);
76
+ }
77
+ );
78
+ }
79
+
80
+ _initializeRoutesUpdate(router) {
81
+ router.post(this._join('/:id'),
82
+ // authentication(true),
83
+ // authorization([ `${this._options.role}.update` ]),
84
+ {
85
+ preHandler: router.auth([
86
+ router.authenticationDefault,
87
+ router.authorizationDefault
88
+ ],
89
+ {
90
+ relation: 'and',
91
+ roles: [ `${this._options.role}.update` ]
92
+ }),
93
+ },
94
+ // eslint-disable-next-line
95
+ async (request, reply) => {
96
+ const response = (await router[this._options.serviceKey].update(request.correlationId, request.user, request.params.id, request.body)).check(request);
97
+ this._jsonResponse(reply, response);
98
+ }
99
+ );
100
+ }
101
+
102
+ _initializeRoutes(router) {
103
+ if (this._allowsDelete)
104
+ this._initializeRoutesDelete(router);
105
+
106
+ router.post(this._join('/search'),
107
+ // authentication(true),
108
+ // authorization([ `${this._options.role}.search` ]),
109
+ {
110
+ preHandler: router.auth([
111
+ router.authenticationDefault,
112
+ router.authorizationDefault
113
+ ],
114
+ {
115
+ relation: 'and',
116
+ roles: [ `${this._options.role}.search` ]
117
+ }),
118
+ },
119
+ // eslint-disable-next-line
120
+ async (request, reply) => {
121
+ const response = (await router[this._options.serviceKey].search(request.correlationId, request.user, request.body)).check(request);
122
+ this._jsonResponse(reply, response);
123
+ }
124
+ );
125
+
126
+ if (this._allowsUpdate())
127
+ this._initializeRoutesUpdate(router);
128
+
129
+ if (this._allowsCreate())
130
+ this._initializeRoutesCreate(router);
131
+
132
+ return router;
133
+ }
134
+ }
135
+
136
+ export default AdminBaseRoute;
@@ -1,22 +1,22 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import AdminRoute from './index.js';
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
- get id() {
14
- return 'admin-news';
15
- }
16
-
17
- get _version() {
18
- return 'v1';
19
- }
20
- }
21
-
22
- export default NewsAdminRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import AdminRoute from './index.js';
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
+ get id() {
14
+ return 'admin-news';
15
+ }
16
+
17
+ get _version() {
18
+ return 'v1';
19
+ }
20
+ }
21
+
22
+ export default NewsAdminRoute;
@@ -1,26 +1,26 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import AdminRoute from './index.js';
4
-
5
- class UsersAdminRoute extends AdminRoute {
6
- constructor(urlFragment, role, serviceKey) {
7
- urlFragment = urlFragment ? urlFragment : 'users';
8
- role = role ? role : 'users';
9
- serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_USERS;
10
- super(urlFragment, role, serviceKey);
11
- }
12
-
13
- get id() {
14
- return 'admin-users';
15
- }
16
-
17
- _allowsCreate() {
18
- return false;
19
- }
20
-
21
- get _version() {
22
- return 'v1';
23
- }
24
- }
25
-
26
- export default UsersAdminRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import AdminRoute from './index.js';
4
+
5
+ class UsersAdminRoute extends AdminRoute {
6
+ constructor(urlFragment, role, serviceKey) {
7
+ urlFragment = urlFragment ? urlFragment : 'users';
8
+ role = role ? role : 'users';
9
+ serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_USERS;
10
+ super(urlFragment, role, serviceKey);
11
+ }
12
+
13
+ get id() {
14
+ return 'admin-users';
15
+ }
16
+
17
+ _allowsCreate() {
18
+ return false;
19
+ }
20
+
21
+ get _version() {
22
+ return 'v1';
23
+ }
24
+ }
25
+
26
+ export default UsersAdminRoute;
@@ -1,44 +1,44 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import BaseRoute from './index.js';
4
-
5
- class BaseNewsRoute extends BaseRoute {
6
- constructor(prefix, version) {
7
- super(prefix ? prefix : '/news');
8
-
9
- // this._serviceNews = null;
10
- }
11
-
12
- async init(injector, app, config) {
13
- await super.init(injector, app, config);
14
- // this._serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
15
- this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_NEWS, LibraryConstants.InjectorKeys.SERVICE_NEWS);
16
- }
17
-
18
- get id() {
19
- return 'news';
20
- }
21
-
22
- _initializeRoutes(router) {
23
- router.get(this._join('/latest/:date'),
24
- // authentication(false),
25
- {
26
- preHandler: router.auth([
27
- router.authenticationDefault,
28
- // router.authorizationDefault
29
- ],
30
- {
31
- relation: 'and',
32
- required: false,
33
- roles: [ 'news' ]
34
- }),
35
- },
36
- async (request, reply) => {
37
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
38
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_NEWS].latest(request.correlationId, request.user, parseInt(request.params.date))).check(request);
39
- this._jsonResponse(reply, response);
40
- });
41
- }
42
- }
43
-
44
- export default BaseNewsRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import BaseRoute from './index.js';
4
+
5
+ class BaseNewsRoute extends BaseRoute {
6
+ constructor(prefix, version) {
7
+ super(prefix ? prefix : '/news');
8
+
9
+ // this._serviceNews = null;
10
+ }
11
+
12
+ async init(injector, app, config) {
13
+ await super.init(injector, app, config);
14
+ // this._serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
15
+ this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_NEWS, LibraryConstants.InjectorKeys.SERVICE_NEWS);
16
+ }
17
+
18
+ get id() {
19
+ return 'news';
20
+ }
21
+
22
+ _initializeRoutes(router) {
23
+ router.get(this._join('/latest/:date'),
24
+ // authentication(false),
25
+ {
26
+ preHandler: router.auth([
27
+ router.authenticationDefault,
28
+ // router.authorizationDefault
29
+ ],
30
+ {
31
+ relation: 'and',
32
+ required: false,
33
+ roles: [ 'news' ]
34
+ }),
35
+ },
36
+ async (request, reply) => {
37
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
38
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_NEWS].latest(request.correlationId, request.user, parseInt(request.params.date))).check(request);
39
+ this._jsonResponse(reply, response);
40
+ });
41
+ }
42
+ }
43
+
44
+ export default BaseNewsRoute;