@thzero/library_server 0.15.24 → 0.15.27

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
3
  "type": "module",
4
- "version": "0.15.24",
4
+ "version": "0.15.27",
5
5
  "version_major": 0,
6
6
  "version_minor": 15,
7
- "version_patch": 24,
7
+ "version_patch": 27,
8
8
  "version_date": "04/16/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",
@@ -18,6 +18,14 @@ class AdminBaseRoute extends BaseRoute {
18
18
  role: role,
19
19
  serviceKey: serviceKey
20
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);
21
29
  }
22
30
 
23
31
  _allowsCreate() {
@@ -42,9 +50,10 @@ class AdminBaseRoute extends BaseRoute {
42
50
  }),
43
51
  // eslint-disable-next-line
44
52
  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);
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));
48
57
  }
49
58
  );
50
59
  }
@@ -56,9 +65,10 @@ class AdminBaseRoute extends BaseRoute {
56
65
  authorization([ `${self._options.role}.delete` ]),
57
66
  // eslint-disable-next-line
58
67
  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);
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));
62
72
  }
63
73
  );
64
74
  }
@@ -73,9 +83,10 @@ class AdminBaseRoute extends BaseRoute {
73
83
  }),
74
84
  // eslint-disable-next-line
75
85
  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);
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));
79
90
  }
80
91
  );
81
92
  }
@@ -92,9 +103,10 @@ class AdminBaseRoute extends BaseRoute {
92
103
  }),
93
104
  // eslint-disable-next-line
94
105
  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);
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.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
109
+ tthis._jsonResponse(ctx, Utility.stringify(response));
98
110
  }
99
111
  );
100
112
 
@@ -9,6 +9,14 @@ import authentication from '../middleware/authentication';
9
9
  class BaseNewsRoute extends BaseRoute {
10
10
  constructor(prefix, version) {
11
11
  super(prefix ? prefix : '/news');
12
+
13
+ // this._serviceNews = null;
14
+ }
15
+
16
+ async init(injector, config) {
17
+ const router = await super.init(injector, config);
18
+ router.serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
19
+ // this._serviceNews = injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
12
20
  }
13
21
 
14
22
  get id() {
@@ -20,9 +28,10 @@ class BaseNewsRoute extends BaseRoute {
20
28
  authentication(false),
21
29
  // eslint-disable-next-line
22
30
  async (ctx, next) => {
23
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
24
- const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
25
- ctx.body = Utility.stringify(response);
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));
26
35
  }
27
36
  );
28
37
  }
@@ -12,6 +12,14 @@ import authorization from '../middleware/authorization';
12
12
  class BaseUsersRoute extends BaseRoute {
13
13
  constructor(prefix, version) {
14
14
  super(prefix ? prefix : '/users');
15
+
16
+ // this._serviceUsers = null;
17
+ }
18
+
19
+ async init(injector, config) {
20
+ const router = await super.init(injector, config);
21
+ router.serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
22
+ // this._serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
15
23
  }
16
24
 
17
25
  get id() {
@@ -35,9 +43,10 @@ class BaseUsersRoute extends BaseRoute {
35
43
  }),
36
44
  // eslint-disable-next-line
37
45
  async (ctx, next) => {
38
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
39
- const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
40
- ctx.body = Utility.stringify(response);
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));
41
50
  }
42
51
  );
43
52
  }
@@ -51,9 +60,10 @@ class BaseUsersRoute extends BaseRoute {
51
60
  }),
52
61
  // eslint-disable-next-line
53
62
  async (ctx, next) => {
54
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
55
- const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
56
- ctx.body = Utility.stringify(response);
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));
57
67
  }
58
68
  );
59
69
  }
@@ -67,9 +77,10 @@ class BaseUsersRoute extends BaseRoute {
67
77
  }),
68
78
  // eslint-disable-next-line
69
79
  async (ctx, next) => {
70
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
80
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
71
81
  const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
72
- ctx.body = Utility.stringify(response);
82
+ // const response = (await ctx.router.serviceUsers.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
83
+ this._jsonResponse(ctx, Utility.stringify(response));
73
84
  }
74
85
  );
75
86
  }
@@ -83,9 +94,10 @@ class BaseUsersRoute extends BaseRoute {
83
94
  }),
84
95
  // eslint-disable-next-line
85
96
  async (ctx, next) => {
86
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
87
- const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
88
- ctx.body = Utility.stringify(response);
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));
89
101
  }
90
102
  );
91
103
  }
@@ -99,9 +111,10 @@ class BaseUsersRoute extends BaseRoute {
99
111
  }),
100
112
  // eslint-disable-next-line
101
113
  async (ctx, next) => {
102
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
103
- const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
104
- ctx.body = Utility.stringify(response);
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));
105
118
  }
106
119
  );
107
120
  }
package/routes/plans.js CHANGED
@@ -7,6 +7,14 @@ import BaseRoute from './index';
7
7
  class PlansRoute extends BaseRoute {
8
8
  constructor(prefix) {
9
9
  super(prefix ? prefix : '/plans');
10
+
11
+ // this._servicePlans = null;
12
+ }
13
+
14
+ async init(injector, config) {
15
+ const router = await super.init(injector, config);
16
+ router.servicePlans = injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
17
+ // this._servicePlans = injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
10
18
  }
11
19
 
12
20
  get id() {
@@ -17,9 +25,10 @@ class PlansRoute extends BaseRoute {
17
25
  router.get('/',
18
26
  // eslint-disable-next-line
19
27
  async (ctx, next) => {
20
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
21
- const response = (await service.listing(ctx.correlationId)).check(ctx);
22
- ctx.body = Utility.stringify(response);
28
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
29
+ // const response = (await service.servicePlans.listing(ctx.correlationId)).check(ctx);
30
+ const response = (await ctx.router.servicePlans.listing(ctx.correlationId)).check(ctx);
31
+ this._jsonResponse(ctx, Utility.stringify(response));
23
32
  }
24
33
  );
25
34
  }
package/routes/utility.js CHANGED
@@ -12,6 +12,14 @@ import authentication from '../middleware/authentication';
12
12
  class UtilityRoute extends BaseRoute {
13
13
  constructor(prefix) {
14
14
  super(prefix ? prefix : '/utility');
15
+
16
+ // this._serviceUtility = null;
17
+ }
18
+
19
+ async init(injector, config) {
20
+ const router = await super.init(injector, config);
21
+ router.serviceUtility = injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
22
+ // this._serviceUtility = injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
15
23
  }
16
24
 
17
25
  get id() {
@@ -27,9 +35,10 @@ class UtilityRoute extends BaseRoute {
27
35
  text: false,
28
36
  }),
29
37
  async (ctx, next) => {
30
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
31
- const response = (await service.logger(ctx.correlationId, ctx.request.body)).check(ctx);
32
- ctx.body = Utility.stringify(response);
38
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
39
+ // const response = (await service.logger(ctx.correlationId, ctx.request.body)).check(ctx);
40
+ const response = (await ctx.router.serviceUtility.logger(ctx.correlationId, ctx.request.body)).check(ctx);
41
+ this._jsonResponse(ctx, Utility.stringify(response));
33
42
  }
34
43
  );
35
44
  }
package/routes/version.js CHANGED
@@ -7,6 +7,14 @@ import BaseRoute from './index';
7
7
  class VersionRoute extends BaseRoute {
8
8
  constructor(prefix) {
9
9
  super(prefix ? prefix : '');
10
+
11
+ // this._serviceVersion = null;
12
+ }
13
+
14
+ async init(injector, config) {
15
+ const router = await super.init(injector, config);
16
+ router.serviceVersion = injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
17
+ // this._serviceVersion = injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
10
18
  }
11
19
 
12
20
  get id() {
@@ -17,9 +25,10 @@ class VersionRoute extends BaseRoute {
17
25
  router.get('/version',
18
26
  // eslint-disable-next-line
19
27
  async (ctx, next) => {
20
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
21
- const response = (await service.version(ctx.correlationId)).check(ctx);
22
- ctx.body = Utility.stringify(response);
28
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
29
+ // const response = (await service.version(ctx.correlationId)).check(ctx);
30
+ const response = (await ctx.router.serviceVersion.version(ctx.correlationId)).check(ctx);
31
+ this._jsonResponse(ctx, Utility.stringify(response));
23
32
  }
24
33
  );
25
34
  }