@thzero/library_server_koa 0.15.38 → 0.15.39
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/README.md +17 -17
- package/boot/index.js +182 -182
- package/boot/plugins/admin/news.js +11 -11
- package/boot/plugins/admin/users.js +11 -11
- package/boot/plugins/api.js +16 -16
- package/boot/plugins/apiFront.js +11 -11
- package/boot/plugins/news.js +11 -11
- package/boot/plugins/users.js +11 -11
- package/boot/plugins/usersExtended.js +11 -11
- package/license.md +8 -8
- package/middleware/authentication.js +83 -83
- package/middleware/authorization.js +191 -191
- package/package.json +39 -39
- package/routes/admin/index.js +123 -123
- package/routes/admin/news.js +22 -22
- package/routes/admin/users.js +26 -26
- package/routes/baseNews.js +40 -40
- package/routes/baseUsers.js +123 -123
- package/routes/home.js +28 -28
- package/routes/index.js +21 -21
- package/routes/news.js +6 -6
- package/routes/plans.js +41 -41
- package/routes/users.js +6 -6
- package/routes/utility.js +51 -51
- package/routes/version.js +41 -41
package/routes/admin/index.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import koaBody from 'koa-body';
|
|
2
|
-
|
|
3
|
-
import Utility from '@thzero/library_common/utility';
|
|
4
|
-
|
|
5
|
-
import BaseRoute from '@thzero/library_server/routes/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(`/admin/${urlFragment}`);
|
|
16
|
-
|
|
17
|
-
this._options = {
|
|
18
|
-
role: role,
|
|
19
|
-
serviceKey: serviceKey
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// this._service = null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async init(injector, config) {
|
|
26
|
-
const router = await super.init(injector, config);
|
|
27
|
-
router.service = injector.getService(this._options.serviceKey);
|
|
28
|
-
// this._service = injector.getService(this._options.serviceKey);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_allowsCreate() {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_allowsDelete() {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_allowsUpdate() {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_initializeRoutesCreate(router) {
|
|
44
|
-
const self = this;
|
|
45
|
-
router.post('/',
|
|
46
|
-
authentication(true),
|
|
47
|
-
authorization([ `${self._options.role}.create` ]),
|
|
48
|
-
koaBody({
|
|
49
|
-
text: false,
|
|
50
|
-
}),
|
|
51
|
-
// eslint-disable-next-line
|
|
52
|
-
async (ctx, next) => {
|
|
53
|
-
// const service = this._injector.getService(this._options.serviceKey);
|
|
54
|
-
// const response = (await router.service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
55
|
-
const response = (await ctx.router.service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
56
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_initializeRoutesDelete(router) {
|
|
62
|
-
const self = this;
|
|
63
|
-
router.delete('/:id',
|
|
64
|
-
authentication(true),
|
|
65
|
-
authorization([ `${self._options.role}.delete` ]),
|
|
66
|
-
// eslint-disable-next-line
|
|
67
|
-
async (ctx, next) => {
|
|
68
|
-
// const service = this._injector.getService(this._options.serviceKey);
|
|
69
|
-
// const response = (await service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
|
|
70
|
-
const response = (await ctx.router.service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
|
|
71
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_initializeRoutesUpdate(router) {
|
|
77
|
-
const self = this;
|
|
78
|
-
router.post('/:id',
|
|
79
|
-
authentication(true),
|
|
80
|
-
authorization([ `${self._options.role}.update` ]),
|
|
81
|
-
koaBody({
|
|
82
|
-
text: false,
|
|
83
|
-
}),
|
|
84
|
-
// eslint-disable-next-line
|
|
85
|
-
async (ctx, next) => {
|
|
86
|
-
// const service = this._injector.getService(this._options.serviceKey);
|
|
87
|
-
// const response = (await service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
|
|
88
|
-
const response = (await ctx.router.service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
|
|
89
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_initializeRoutes(router) {
|
|
95
|
-
if (this._allowsDelete)
|
|
96
|
-
this._initializeRoutesDelete(router);
|
|
97
|
-
|
|
98
|
-
router.post('/search',
|
|
99
|
-
authentication(true),
|
|
100
|
-
authorization([ `${this._options.role}.search` ]),
|
|
101
|
-
koaBody({
|
|
102
|
-
text: false,
|
|
103
|
-
}),
|
|
104
|
-
// eslint-disable-next-line
|
|
105
|
-
async (ctx, next) => {
|
|
106
|
-
// const service = this._injector.getService(this._options.serviceKey);
|
|
107
|
-
// const response = (await service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
108
|
-
const response = (await ctx.router.service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
109
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
if (this._allowsUpdate())
|
|
114
|
-
this._initializeRoutesUpdate(router);
|
|
115
|
-
|
|
116
|
-
if (this._allowsCreate())
|
|
117
|
-
this._initializeRoutesCreate(router);
|
|
118
|
-
|
|
119
|
-
return router;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default AdminBaseRoute;
|
|
1
|
+
import koaBody from 'koa-body';
|
|
2
|
+
|
|
3
|
+
import Utility from '@thzero/library_common/utility';
|
|
4
|
+
|
|
5
|
+
import BaseRoute from '@thzero/library_server/routes/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(`/admin/${urlFragment}`);
|
|
16
|
+
|
|
17
|
+
this._options = {
|
|
18
|
+
role: role,
|
|
19
|
+
serviceKey: serviceKey
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// this._service = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async init(injector, config) {
|
|
26
|
+
const router = await super.init(injector, config);
|
|
27
|
+
router.service = injector.getService(this._options.serviceKey);
|
|
28
|
+
// this._service = injector.getService(this._options.serviceKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_allowsCreate() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_allowsDelete() {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_allowsUpdate() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_initializeRoutesCreate(router) {
|
|
44
|
+
const self = this;
|
|
45
|
+
router.post('/',
|
|
46
|
+
authentication(true),
|
|
47
|
+
authorization([ `${self._options.role}.create` ]),
|
|
48
|
+
koaBody({
|
|
49
|
+
text: false,
|
|
50
|
+
}),
|
|
51
|
+
// eslint-disable-next-line
|
|
52
|
+
async (ctx, next) => {
|
|
53
|
+
// const service = this._injector.getService(this._options.serviceKey);
|
|
54
|
+
// const response = (await router.service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
55
|
+
const response = (await ctx.router.service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
56
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_initializeRoutesDelete(router) {
|
|
62
|
+
const self = this;
|
|
63
|
+
router.delete('/:id',
|
|
64
|
+
authentication(true),
|
|
65
|
+
authorization([ `${self._options.role}.delete` ]),
|
|
66
|
+
// eslint-disable-next-line
|
|
67
|
+
async (ctx, next) => {
|
|
68
|
+
// const service = this._injector.getService(this._options.serviceKey);
|
|
69
|
+
// const response = (await service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
|
|
70
|
+
const response = (await ctx.router.service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
|
|
71
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_initializeRoutesUpdate(router) {
|
|
77
|
+
const self = this;
|
|
78
|
+
router.post('/:id',
|
|
79
|
+
authentication(true),
|
|
80
|
+
authorization([ `${self._options.role}.update` ]),
|
|
81
|
+
koaBody({
|
|
82
|
+
text: false,
|
|
83
|
+
}),
|
|
84
|
+
// eslint-disable-next-line
|
|
85
|
+
async (ctx, next) => {
|
|
86
|
+
// const service = this._injector.getService(this._options.serviceKey);
|
|
87
|
+
// const response = (await service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
|
|
88
|
+
const response = (await ctx.router.service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
|
|
89
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_initializeRoutes(router) {
|
|
95
|
+
if (this._allowsDelete)
|
|
96
|
+
this._initializeRoutesDelete(router);
|
|
97
|
+
|
|
98
|
+
router.post('/search',
|
|
99
|
+
authentication(true),
|
|
100
|
+
authorization([ `${this._options.role}.search` ]),
|
|
101
|
+
koaBody({
|
|
102
|
+
text: false,
|
|
103
|
+
}),
|
|
104
|
+
// eslint-disable-next-line
|
|
105
|
+
async (ctx, next) => {
|
|
106
|
+
// const service = this._injector.getService(this._options.serviceKey);
|
|
107
|
+
// const response = (await service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
108
|
+
const response = (await ctx.router.service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
|
|
109
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (this._allowsUpdate())
|
|
114
|
+
this._initializeRoutesUpdate(router);
|
|
115
|
+
|
|
116
|
+
if (this._allowsCreate())
|
|
117
|
+
this._initializeRoutesCreate(router);
|
|
118
|
+
|
|
119
|
+
return router;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default AdminBaseRoute;
|
package/routes/admin/news.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import LibraryConstants from '@thzero/library_server/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
|
-
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';
|
|
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
|
+
get id() {
|
|
14
|
+
return 'admin-news';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get _version() {
|
|
18
|
+
return 'v1';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default NewsAdminRoute;
|
package/routes/admin/users.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import LibraryConstants from '@thzero/library_server/constants';
|
|
2
|
-
|
|
3
|
-
import AdminRoute from './index'
|
|
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';
|
|
2
|
+
|
|
3
|
+
import AdminRoute from './index'
|
|
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;
|
package/routes/baseNews.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import LibraryConstants from '@thzero/library_server/constants';
|
|
2
|
-
|
|
3
|
-
import Utility from '@thzero/library_common/utility';
|
|
4
|
-
|
|
5
|
-
import BaseRoute from './index';
|
|
6
|
-
|
|
7
|
-
import authentication from '../middleware/authentication';
|
|
8
|
-
|
|
9
|
-
class BaseNewsRoute extends BaseRoute {
|
|
10
|
-
constructor(prefix, version) {
|
|
11
|
-
super(prefix ? prefix : '/news');
|
|
12
|
-
|
|
13
|
-
// this._serviceNews = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async init(injector, config) {
|
|
17
|
-
const router = await super.init(injector, app, config);
|
|
18
|
-
router.serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
19
|
-
// this._serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get id() {
|
|
23
|
-
return 'news';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_initializeRoutes(router) {
|
|
27
|
-
router.get('/latest/:date',
|
|
28
|
-
authentication(false),
|
|
29
|
-
// eslint-disable-next-line
|
|
30
|
-
async (ctx, next) => {
|
|
31
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
32
|
-
// const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
|
|
33
|
-
const response = (await ctx.router.serviceNews.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
|
|
34
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default BaseNewsRoute;
|
|
1
|
+
import LibraryConstants from '@thzero/library_server/constants';
|
|
2
|
+
|
|
3
|
+
import Utility from '@thzero/library_common/utility';
|
|
4
|
+
|
|
5
|
+
import BaseRoute from './index';
|
|
6
|
+
|
|
7
|
+
import authentication from '../middleware/authentication';
|
|
8
|
+
|
|
9
|
+
class BaseNewsRoute extends BaseRoute {
|
|
10
|
+
constructor(prefix, version) {
|
|
11
|
+
super(prefix ? prefix : '/news');
|
|
12
|
+
|
|
13
|
+
// this._serviceNews = null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async init(injector, config) {
|
|
17
|
+
const router = await super.init(injector, app, config);
|
|
18
|
+
router.serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
19
|
+
// this._serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get id() {
|
|
23
|
+
return 'news';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_initializeRoutes(router) {
|
|
27
|
+
router.get('/latest/:date',
|
|
28
|
+
authentication(false),
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
async (ctx, next) => {
|
|
31
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
|
|
32
|
+
// const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
|
|
33
|
+
const response = (await ctx.router.serviceNews.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
|
|
34
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default BaseNewsRoute;
|
package/routes/baseUsers.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import koaBody from 'koa-body';
|
|
2
|
-
|
|
3
|
-
import LibraryConstants from '@thzero/library_server/constants';
|
|
4
|
-
|
|
5
|
-
import Utility from '@thzero/library_common/utility';
|
|
6
|
-
|
|
7
|
-
import BaseRoute from './index';
|
|
8
|
-
|
|
9
|
-
import authentication from '../middleware/authentication';
|
|
10
|
-
import authorization from '../middleware/authorization';
|
|
11
|
-
|
|
12
|
-
class BaseUsersRoute extends BaseRoute {
|
|
13
|
-
constructor(prefix, version) {
|
|
14
|
-
super(prefix ? prefix : '/users');
|
|
15
|
-
|
|
16
|
-
// this._serviceUsers = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async init(injector, app, config) {
|
|
20
|
-
const router = await super.init(injector, app, config);
|
|
21
|
-
router.serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
22
|
-
// this._serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get id() {
|
|
26
|
-
return 'users';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_initializeRoutes(router) {
|
|
30
|
-
this._initializeRoutesGamerById(router);
|
|
31
|
-
this._initializeRoutesGamerByTag(router);
|
|
32
|
-
this._initializeRoutesRefreshSettings(router);
|
|
33
|
-
this._initializeRoutesUpdate(router);
|
|
34
|
-
this._initializeRoutesUpdateSettings(router);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_initializeRoutesGamerById(router) {
|
|
38
|
-
return router.get('/gamerId/:gamerId',
|
|
39
|
-
authentication(false),
|
|
40
|
-
// authorization('user'),
|
|
41
|
-
koaBody({
|
|
42
|
-
text: false,
|
|
43
|
-
}),
|
|
44
|
-
// eslint-disable-next-line
|
|
45
|
-
async (ctx, next) => {
|
|
46
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
47
|
-
// const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
|
|
48
|
-
const response = (await ctx.router.serviceUsers.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
|
|
49
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
_initializeRoutesGamerByTag(router) {
|
|
55
|
-
return router.get('/gamerTag/:gamerTag',
|
|
56
|
-
authentication(false),
|
|
57
|
-
// authorization('user'),
|
|
58
|
-
koaBody({
|
|
59
|
-
text: false,
|
|
60
|
-
}),
|
|
61
|
-
// eslint-disable-next-line
|
|
62
|
-
async (ctx, next) => {
|
|
63
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
64
|
-
// const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
|
|
65
|
-
const response = (await ctx.router.serviceUsers.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
|
|
66
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
_initializeRoutesRefreshSettings(router) {
|
|
72
|
-
return router.post('/refresh/settings',
|
|
73
|
-
authentication(true),
|
|
74
|
-
authorization('user'),
|
|
75
|
-
koaBody({
|
|
76
|
-
text: false,
|
|
77
|
-
}),
|
|
78
|
-
// eslint-disable-next-line
|
|
79
|
-
async (ctx, next) => {
|
|
80
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
81
|
-
// const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
82
|
-
const response = (await ctx.router.serviceUsers.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
83
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_initializeRoutesUpdate(router) {
|
|
89
|
-
return router.post('/update',
|
|
90
|
-
authentication(true),
|
|
91
|
-
authorization('user'),
|
|
92
|
-
koaBody({
|
|
93
|
-
text: false,
|
|
94
|
-
}),
|
|
95
|
-
// eslint-disable-next-line
|
|
96
|
-
async (ctx, next) => {
|
|
97
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
98
|
-
// const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
99
|
-
const response = (await ctx.router.serviceUsers.update(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
100
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_initializeRoutesUpdateSettings(router) {
|
|
106
|
-
return router.post('/update/settings',
|
|
107
|
-
authentication(true),
|
|
108
|
-
authorization('user'),
|
|
109
|
-
koaBody({
|
|
110
|
-
text: false,
|
|
111
|
-
}),
|
|
112
|
-
// eslint-disable-next-line
|
|
113
|
-
async (ctx, next) => {
|
|
114
|
-
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
115
|
-
// const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
116
|
-
const response = (await ctx.router.serviceUsers.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
117
|
-
this._jsonResponse(ctx, Utility.stringify(response));
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default BaseUsersRoute;
|
|
1
|
+
import koaBody from 'koa-body';
|
|
2
|
+
|
|
3
|
+
import LibraryConstants from '@thzero/library_server/constants';
|
|
4
|
+
|
|
5
|
+
import Utility from '@thzero/library_common/utility';
|
|
6
|
+
|
|
7
|
+
import BaseRoute from './index';
|
|
8
|
+
|
|
9
|
+
import authentication from '../middleware/authentication';
|
|
10
|
+
import authorization from '../middleware/authorization';
|
|
11
|
+
|
|
12
|
+
class BaseUsersRoute extends BaseRoute {
|
|
13
|
+
constructor(prefix, version) {
|
|
14
|
+
super(prefix ? prefix : '/users');
|
|
15
|
+
|
|
16
|
+
// this._serviceUsers = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async init(injector, app, config) {
|
|
20
|
+
const router = await super.init(injector, app, config);
|
|
21
|
+
router.serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
22
|
+
// this._serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get id() {
|
|
26
|
+
return 'users';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_initializeRoutes(router) {
|
|
30
|
+
this._initializeRoutesGamerById(router);
|
|
31
|
+
this._initializeRoutesGamerByTag(router);
|
|
32
|
+
this._initializeRoutesRefreshSettings(router);
|
|
33
|
+
this._initializeRoutesUpdate(router);
|
|
34
|
+
this._initializeRoutesUpdateSettings(router);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_initializeRoutesGamerById(router) {
|
|
38
|
+
return router.get('/gamerId/:gamerId',
|
|
39
|
+
authentication(false),
|
|
40
|
+
// authorization('user'),
|
|
41
|
+
koaBody({
|
|
42
|
+
text: false,
|
|
43
|
+
}),
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
async (ctx, next) => {
|
|
46
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
47
|
+
// const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
|
|
48
|
+
const response = (await ctx.router.serviceUsers.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
|
|
49
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_initializeRoutesGamerByTag(router) {
|
|
55
|
+
return router.get('/gamerTag/:gamerTag',
|
|
56
|
+
authentication(false),
|
|
57
|
+
// authorization('user'),
|
|
58
|
+
koaBody({
|
|
59
|
+
text: false,
|
|
60
|
+
}),
|
|
61
|
+
// eslint-disable-next-line
|
|
62
|
+
async (ctx, next) => {
|
|
63
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
64
|
+
// const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
|
|
65
|
+
const response = (await ctx.router.serviceUsers.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
|
|
66
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_initializeRoutesRefreshSettings(router) {
|
|
72
|
+
return router.post('/refresh/settings',
|
|
73
|
+
authentication(true),
|
|
74
|
+
authorization('user'),
|
|
75
|
+
koaBody({
|
|
76
|
+
text: false,
|
|
77
|
+
}),
|
|
78
|
+
// eslint-disable-next-line
|
|
79
|
+
async (ctx, next) => {
|
|
80
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
81
|
+
// const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
82
|
+
const response = (await ctx.router.serviceUsers.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
83
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
_initializeRoutesUpdate(router) {
|
|
89
|
+
return router.post('/update',
|
|
90
|
+
authentication(true),
|
|
91
|
+
authorization('user'),
|
|
92
|
+
koaBody({
|
|
93
|
+
text: false,
|
|
94
|
+
}),
|
|
95
|
+
// eslint-disable-next-line
|
|
96
|
+
async (ctx, next) => {
|
|
97
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
98
|
+
// const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
99
|
+
const response = (await ctx.router.serviceUsers.update(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
100
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_initializeRoutesUpdateSettings(router) {
|
|
106
|
+
return router.post('/update/settings',
|
|
107
|
+
authentication(true),
|
|
108
|
+
authorization('user'),
|
|
109
|
+
koaBody({
|
|
110
|
+
text: false,
|
|
111
|
+
}),
|
|
112
|
+
// eslint-disable-next-line
|
|
113
|
+
async (ctx, next) => {
|
|
114
|
+
// const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
|
|
115
|
+
// const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
116
|
+
const response = (await ctx.router.serviceUsers.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
|
|
117
|
+
this._jsonResponse(ctx, Utility.stringify(response));
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default BaseUsersRoute;
|