@thzero/library_server 0.13.33 → 0.14.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.
- package/middleware/authentication.js +0 -1
- package/package.json +9 -9
- package/repository/index.js +9 -3
- package/service/admin/index.js +9 -9
- package/service/admin/users.js +9 -9
- package/service/baseUser.js +10 -10
- package/service/news/base.js +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import LibraryConstants from '../constants';
|
|
2
|
-
import LibraryCommonConstants from '@thzero/library_common/constants';
|
|
3
2
|
import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
|
|
4
3
|
|
|
5
4
|
import injector from '@thzero/library_common/utility/injector';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"version_major": 0,
|
|
5
|
-
"version_minor":
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "
|
|
5
|
+
"version_minor": 14,
|
|
6
|
+
"version_patch": 2,
|
|
7
|
+
"version_date": "10/02/2021",
|
|
8
8
|
"description": "An opinionated library of common functionality to bootstrap a Koa based API application using MongoDb and Firebase.",
|
|
9
9
|
"author": "thZero",
|
|
10
10
|
"license": "MIT",
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"easy-rbac": "^3.1.1",
|
|
36
36
|
"esm": "^3.2.25",
|
|
37
37
|
"internal-ip": "^6.2.0",
|
|
38
|
-
"koa": "^2.13.
|
|
38
|
+
"koa": "^2.13.3",
|
|
39
39
|
"koa-body": "^4.2.0",
|
|
40
40
|
"koa-helmet": "^6.1.0",
|
|
41
41
|
"koa-static": "^5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@thzero/library_cli": "^0.13.
|
|
44
|
+
"@thzero/library_cli": "^0.13.19"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@thzero/library_common": "^0.
|
|
48
|
-
"@thzero/library_common_service": "^0.
|
|
47
|
+
"@thzero/library_common": "^0.14",
|
|
48
|
+
"@thzero/library_common_service": "^0.14",
|
|
49
49
|
"@babel/core": "^7.15.5",
|
|
50
50
|
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
51
51
|
"@babel/preset-env": "^7.15.6",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"eslint": "^7.32.0",
|
|
54
54
|
"eslint-plugin-node": "^11.1.0",
|
|
55
55
|
"pino-pretty": "^7.0.1",
|
|
56
|
-
"webpack": "^5.
|
|
56
|
+
"webpack": "^5.56.0",
|
|
57
57
|
"webpack-cli": "^4.8.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/repository/index.js
CHANGED
|
@@ -107,6 +107,14 @@ class Repository {
|
|
|
107
107
|
return Response.error(clazz, method, message, err, code, errors, correlationId);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
_hasFailed(response) {
|
|
111
|
+
return Response.hasFailed(response);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_hasSucceeded(response) {
|
|
115
|
+
return Response.hasSucceeded(response);
|
|
116
|
+
}
|
|
117
|
+
|
|
110
118
|
_initResponse(correlationId) {
|
|
111
119
|
return new Response(correlationId);
|
|
112
120
|
}
|
|
@@ -124,9 +132,7 @@ class Repository {
|
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
_successResponse(value, correlationId) {
|
|
127
|
-
|
|
128
|
-
response.results = value;
|
|
129
|
-
return response;
|
|
135
|
+
return Response.success(correlationId, value);
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
_warn(clazz, method, message, err, code, errors, correlationId) {
|
package/service/admin/index.js
CHANGED
|
@@ -10,12 +10,12 @@ class BaseAdminService extends Service {
|
|
|
10
10
|
return this._error('BaseAdminService', 'create', null, null, null, null, correlationId);
|
|
11
11
|
|
|
12
12
|
const validationResponse = this._validateUser(correlationId, user);
|
|
13
|
-
if (
|
|
13
|
+
if (this._hasFailed(validationResponse))
|
|
14
14
|
return validationResponse;
|
|
15
15
|
|
|
16
16
|
this._logger.debug('BaseAdminService', 'create', 'requestedValue', requestedValue, correlationId);
|
|
17
17
|
const validationCheckValueResponse = this._validateCreate(correlationId, requestedValue);
|
|
18
|
-
if (
|
|
18
|
+
if (this._hasFailed(validationCheckValueResponse))
|
|
19
19
|
return validationCheckValueResponse;
|
|
20
20
|
|
|
21
21
|
const respositoryResponse = await this._repository.create(correlationId, user.id, requestedValue);
|
|
@@ -27,7 +27,7 @@ class BaseAdminService extends Service {
|
|
|
27
27
|
return this._error('BaseAdminService', 'delete', null, null, null, null, correlationId);
|
|
28
28
|
|
|
29
29
|
const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
|
|
30
|
-
if (
|
|
30
|
+
if (this._hasFailed(validationCheckIdResponse))
|
|
31
31
|
return validationCheckIdResponse;
|
|
32
32
|
|
|
33
33
|
const respositoryResponse = await this._repository.delete(correlationId, id);
|
|
@@ -36,7 +36,7 @@ class BaseAdminService extends Service {
|
|
|
36
36
|
|
|
37
37
|
async search(correlationId, user, params) {
|
|
38
38
|
const validationCheckParamsResponse = this._validateSearch(correlationId, params);
|
|
39
|
-
if (
|
|
39
|
+
if (this._hasFailed(validationCheckParamsResponse))
|
|
40
40
|
return validationCheckParamsResponse;
|
|
41
41
|
|
|
42
42
|
const respositoryResponse = await this._repository.search(correlationId, params);
|
|
@@ -48,25 +48,25 @@ class BaseAdminService extends Service {
|
|
|
48
48
|
return this._error('BaseAdminService', 'update', 'requestedValue', null, null, null, correlationId);
|
|
49
49
|
|
|
50
50
|
const validationResponse = this._validateUser(correlationId, user);
|
|
51
|
-
if (
|
|
51
|
+
if (this._hasFailed(validationResponse))
|
|
52
52
|
return validationResponse;
|
|
53
53
|
|
|
54
54
|
const validationIdResponse = this._validateId(correlationId, id, this._validationCheckKey);
|
|
55
|
-
if (
|
|
55
|
+
if (this._hasFailed(validationIdResponse))
|
|
56
56
|
return validationIdResponse;
|
|
57
57
|
|
|
58
58
|
this._logger.debug('BaseAdminService', 'update', 'requestedValue', requestedValue, correlationId);
|
|
59
59
|
const validationCheckValueUpdateResponse = this._validateUpdate(correlationId, requestedValue);
|
|
60
|
-
if (
|
|
60
|
+
if (this._hasFailed(validationCheckValueUpdateResponse))
|
|
61
61
|
return validationCheckValueUpdateResponse;
|
|
62
62
|
|
|
63
63
|
let value = this._initializeData();
|
|
64
64
|
const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
|
|
65
|
-
if (fetchRespositoryResponse
|
|
65
|
+
if (this._hasSucceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
|
|
66
66
|
value = Utility.map(this._initializeData(), fetchRespositoryResponse.results, true);
|
|
67
67
|
|
|
68
68
|
const validResponse = this._checkUpdatedTimestamp(correlationId, value, requestedValue, 'value');
|
|
69
|
-
if (
|
|
69
|
+
if (this._hasFailed(validResponse))
|
|
70
70
|
return validResponse;
|
|
71
71
|
|
|
72
72
|
value.map(requestedValue);
|
package/service/admin/users.js
CHANGED
|
@@ -28,15 +28,15 @@ class BaseUsersAdminService extends BaseAdminService {
|
|
|
28
28
|
return this._error('BaseUsersAdminService', 'delete', null, null, null, null, correlationId);
|
|
29
29
|
|
|
30
30
|
const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
|
|
31
|
-
if (
|
|
31
|
+
if (this._hasFailed(validationCheckIdResponse))
|
|
32
32
|
return validationCheckIdResponse;
|
|
33
33
|
|
|
34
34
|
const fetchResponse = await this._serviceUser.fetch(correlationId, id);
|
|
35
|
-
if (
|
|
35
|
+
if (this._hasFailed(fetchResponse))
|
|
36
36
|
return fetchResponse;
|
|
37
37
|
|
|
38
38
|
const response = await this._serviceAuth.deleteUser(correlationId, id);
|
|
39
|
-
if (
|
|
39
|
+
if (this._hasFailed(response))
|
|
40
40
|
return response;
|
|
41
41
|
|
|
42
42
|
const respositoryResponse = await this._repository.delete(correlationId, id);
|
|
@@ -45,31 +45,31 @@ class BaseUsersAdminService extends BaseAdminService {
|
|
|
45
45
|
|
|
46
46
|
async update(correlationId, user, id, requestedUser) {
|
|
47
47
|
const validationResponse = this._validateUser(correlationId, user);
|
|
48
|
-
if (
|
|
48
|
+
if (this._hasFailed(validationResponse))
|
|
49
49
|
return validationResponse;
|
|
50
50
|
|
|
51
51
|
const validationIdResponse = this._validateId(correlationId, id, 'adminUsers');
|
|
52
|
-
if (
|
|
52
|
+
if (this._hasFailed(validationIdResponse))
|
|
53
53
|
return validationIdResponse;
|
|
54
54
|
|
|
55
55
|
this._logger.debug('BaseUsersAdminService', 'update', 'requestedUser', requestedUser, correlationId);
|
|
56
56
|
const validationCheckUsersUpdateResponse = this._serviceValidation.check(correlationId, this._serviceValidation.userUpdateSchema, requestedUser, null, this._validationCheckKey);
|
|
57
|
-
if (
|
|
57
|
+
if (this._hasFailed(validationCheckUsersUpdateResponse))
|
|
58
58
|
return validationCheckUsersUpdateResponse;
|
|
59
59
|
|
|
60
60
|
let userExisting = this._initializeData();
|
|
61
61
|
const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
|
|
62
|
-
if (fetchRespositoryResponse
|
|
62
|
+
if (this._hasSuceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
|
|
63
63
|
userExisting = Utility.map(this._initializeData(), fetchRespositoryResponse.results, true);
|
|
64
64
|
|
|
65
65
|
const validResponse = this._checkUpdatedTimestamp(correlationId, userExisting, requestedUser, 'users');
|
|
66
|
-
if (
|
|
66
|
+
if (this._hasFailed(validResponse))
|
|
67
67
|
return validResponse;
|
|
68
68
|
|
|
69
69
|
userExisting.map(requestedUser);
|
|
70
70
|
|
|
71
71
|
const respositoryResponse = await this._repository.update(correlationId, user.id, userExisting);
|
|
72
|
-
if (
|
|
72
|
+
if (this._hasFailed(respositoryResponse))
|
|
73
73
|
return respositoryResponse;
|
|
74
74
|
|
|
75
75
|
if (!user.external && !user.external.id)
|
package/service/baseUser.js
CHANGED
|
@@ -5,7 +5,7 @@ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
|
|
|
5
5
|
class BaseUserService extends Service {
|
|
6
6
|
async fetch(correlationId, userId) {
|
|
7
7
|
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, userId);
|
|
8
|
-
if (
|
|
8
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
9
9
|
return validationCheckExternalIdResponse;
|
|
10
10
|
|
|
11
11
|
const respositoryResponse = await this._repositoryUser.fetch(correlationId, userId);
|
|
@@ -14,7 +14,7 @@ class BaseUserService extends Service {
|
|
|
14
14
|
|
|
15
15
|
async fetchByExternalId(correlationId, externalUserId) {
|
|
16
16
|
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, externalUserId);
|
|
17
|
-
if (
|
|
17
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
18
18
|
return validationCheckExternalIdResponse;
|
|
19
19
|
|
|
20
20
|
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUserId);
|
|
@@ -23,7 +23,7 @@ class BaseUserService extends Service {
|
|
|
23
23
|
|
|
24
24
|
async fetchByGamerId(correlationId, requestedGamerId) {
|
|
25
25
|
const validationRequestedGamerIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerIdSchema, requestedGamerId);
|
|
26
|
-
if (
|
|
26
|
+
if (this._hasFailed(validationRequestedGamerIdResponse))
|
|
27
27
|
return validationRequestedGamerIdResponse;
|
|
28
28
|
|
|
29
29
|
const respositoryResponse = await this._repositoryUser.fetchByGamerId(correlationId, requestedGamerId);
|
|
@@ -32,7 +32,7 @@ class BaseUserService extends Service {
|
|
|
32
32
|
|
|
33
33
|
async fetchByGamerTag(correlationId, requestedUserGamerTag) {
|
|
34
34
|
const validationRequestedGamerTagResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerTagSchema, requestedUserGamerTag);
|
|
35
|
-
if (
|
|
35
|
+
if (this._hasFailed(validationRequestedGamerTagResponse))
|
|
36
36
|
return validationRequestedGamerTagResponse;
|
|
37
37
|
|
|
38
38
|
const respositoryResponse = await this._repositoryUser.fetchByGamerTag(correlationId, requestedUserGamerTag);
|
|
@@ -41,7 +41,7 @@ class BaseUserService extends Service {
|
|
|
41
41
|
|
|
42
42
|
async refreshSettings(correlationId, params) {
|
|
43
43
|
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingsRefreshSchema, params);
|
|
44
|
-
if (
|
|
44
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
45
45
|
return validationCheckExternalIdResponse;
|
|
46
46
|
|
|
47
47
|
const respositoryResponse = await this._repositoryUser.refreshSettings(correlationId, params.userId);
|
|
@@ -50,11 +50,11 @@ class BaseUserService extends Service {
|
|
|
50
50
|
|
|
51
51
|
async update(correlationId, externalUser) {
|
|
52
52
|
const validationCheckExternalUserResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalUserSchema, externalUser);
|
|
53
|
-
if (
|
|
53
|
+
if (this._hasFailed(validationCheckExternalUserResponse))
|
|
54
54
|
return validationCheckExternalUserResponse;
|
|
55
55
|
|
|
56
56
|
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUser.id, true);
|
|
57
|
-
if (
|
|
57
|
+
if (this._hasFailed(respositoryResponse))
|
|
58
58
|
return respositoryResponse;
|
|
59
59
|
|
|
60
60
|
let user = respositoryResponse.results;
|
|
@@ -80,15 +80,15 @@ class BaseUserService extends Service {
|
|
|
80
80
|
|
|
81
81
|
async updateSettings(correlationId, requestedSettings) {
|
|
82
82
|
const validationCheckSettingsResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingRequestSchema(), requestedSettings);
|
|
83
|
-
if (
|
|
83
|
+
if (this._hasFailed(validationCheckSettingsResponse))
|
|
84
84
|
return validationCheckSettingsResponse;
|
|
85
85
|
|
|
86
86
|
const validationSettingsResponse = await this._updateSettingsValidation(correlationId, requestedSettings);
|
|
87
|
-
if (
|
|
87
|
+
if (this._hasFailed(validationSettingsResponse))
|
|
88
88
|
return validationSettingsResponse;
|
|
89
89
|
|
|
90
90
|
const updateSettingsResponse = await this._updateSettings(correlationId, requestedSettings);
|
|
91
|
-
if (
|
|
91
|
+
if (this._hasFailed(updateSettingsResponse))
|
|
92
92
|
return updateSettingsResponse;
|
|
93
93
|
|
|
94
94
|
const respositoryResponse = await this._repositoryUser.updateSettings(correlationId, requestedSettings.userId, requestedSettings.settings);
|
package/service/news/base.js
CHANGED
|
@@ -29,7 +29,7 @@ class BaseNewsService extends Service {
|
|
|
29
29
|
return validationCheckNewsTiemstampResponse;
|
|
30
30
|
|
|
31
31
|
const respositoryResponse = await this._repositoryNews.latest(correlationId, timestamp);
|
|
32
|
-
if (
|
|
32
|
+
if (this._hasFailed(respositoryResponse))
|
|
33
33
|
return respositoryResponse;
|
|
34
34
|
|
|
35
35
|
let data = respositoryResponse.results.data;
|