@futdevpro/nts-dynamo 1.7.17 → 1.7.21

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 (129) hide show
  1. package/.eslintrc.json +171 -0
  2. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
  3. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
  4. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  5. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  6. package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -1
  7. package/lib/_constants/mocks/data-model.mock.js.map +1 -1
  8. package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -1
  9. package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
  10. package/lib/_constants/mocks/email-service.mock.js +3 -3
  11. package/lib/_constants/mocks/email-service.mock.js.map +1 -1
  12. package/lib/_constants/mocks/endpoint.mock.d.ts.map +1 -1
  13. package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
  14. package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
  15. package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
  16. package/lib/_enums/index.js +1 -1
  17. package/lib/_enums/index.js.map +1 -1
  18. package/lib/_models/control-models/api-call-params.control-model.d.ts +2 -2
  19. package/lib/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
  20. package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
  21. package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -1
  22. package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
  23. package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -1
  24. package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
  25. package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  26. package/lib/_models/control-models/endpoint-params.control-model.js +15 -9
  27. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  28. package/lib/_models/control-models/http-settings.control-model.d.ts +1 -1
  29. package/lib/_models/control-models/http-settings.control-model.d.ts.map +1 -1
  30. package/lib/_models/control-models/http-settings.control-model.js +3 -1
  31. package/lib/_models/control-models/http-settings.control-model.js.map +1 -1
  32. package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
  33. package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
  34. package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
  35. package/lib/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
  36. package/lib/_modules/custom-data/custom-data.controller.js +2 -1
  37. package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
  38. package/lib/_modules/custom-data/get-custom-data-routing-module.util.d.ts.map +1 -1
  39. package/lib/_modules/custom-data/get-custom-data-routing-module.util.js.map +1 -1
  40. package/lib/_modules/test/get-test-routing-module.util.d.ts.map +1 -1
  41. package/lib/_modules/test/get-test-routing-module.util.js.map +1 -1
  42. package/lib/_modules/test/test.controller.d.ts.map +1 -1
  43. package/lib/_modules/test/test.controller.js.map +1 -1
  44. package/lib/_modules/usage/get-usage-routing-module.util.d.ts.map +1 -1
  45. package/lib/_modules/usage/get-usage-routing-module.util.js +1 -1
  46. package/lib/_modules/usage/get-usage-routing-module.util.js.map +1 -1
  47. package/lib/_modules/usage/usage.controller.d.ts.map +1 -1
  48. package/lib/_modules/usage/usage.controller.js +15 -14
  49. package/lib/_modules/usage/usage.controller.js.map +1 -1
  50. package/lib/_modules/usage/usage.data-service.d.ts +3 -1
  51. package/lib/_modules/usage/usage.data-service.d.ts.map +1 -1
  52. package/lib/_modules/usage/usage.data-service.js +24 -16
  53. package/lib/_modules/usage/usage.data-service.js.map +1 -1
  54. package/lib/_services/base/data.service.d.ts.map +1 -1
  55. package/lib/_services/base/data.service.js +45 -23
  56. package/lib/_services/base/data.service.js.map +1 -1
  57. package/lib/_services/base/db.service.d.ts.map +1 -1
  58. package/lib/_services/base/db.service.js +82 -53
  59. package/lib/_services/base/db.service.js.map +1 -1
  60. package/lib/_services/base/singleton.service.d.ts.map +1 -1
  61. package/lib/_services/base/singleton.service.js.map +1 -1
  62. package/lib/_services/core/api.service.d.ts +21 -13
  63. package/lib/_services/core/api.service.d.ts.map +1 -1
  64. package/lib/_services/core/api.service.js +192 -143
  65. package/lib/_services/core/api.service.js.map +1 -1
  66. package/lib/_services/core/auth.service.d.ts.map +1 -1
  67. package/lib/_services/core/auth.service.js.map +1 -1
  68. package/lib/_services/core/email.service.d.ts +50 -36
  69. package/lib/_services/core/email.service.d.ts.map +1 -1
  70. package/lib/_services/core/email.service.js +329 -94
  71. package/lib/_services/core/email.service.js.map +1 -1
  72. package/lib/_services/core/global.service.d.ts.map +1 -1
  73. package/lib/_services/core/global.service.js +30 -19
  74. package/lib/_services/core/global.service.js.map +1 -1
  75. package/lib/_services/route/controller.service.d.ts.map +1 -1
  76. package/lib/_services/route/controller.service.js.map +1 -1
  77. package/lib/_services/route/routing-module.service.d.ts.map +1 -1
  78. package/lib/_services/route/routing-module.service.js +2 -2
  79. package/lib/_services/route/routing-module.service.js.map +1 -1
  80. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  81. package/lib/_services/server/app-extended.server.js +19 -14
  82. package/lib/_services/server/app-extended.server.js.map +1 -1
  83. package/lib/_services/server/app-extended.server.spec.js +1 -0
  84. package/lib/_services/server/app-extended.server.spec.js.map +1 -1
  85. package/lib/_services/server/app.server.d.ts +4 -3
  86. package/lib/_services/server/app.server.d.ts.map +1 -1
  87. package/lib/_services/server/app.server.js +106 -51
  88. package/lib/_services/server/app.server.js.map +1 -1
  89. package/lib/_services/server/app.server.spec.js +1 -0
  90. package/lib/_services/server/app.server.spec.js.map +1 -1
  91. package/lib/_services/shared.static-service.js.map +1 -1
  92. package/lib/_services/socket/socket-client.service.js.map +1 -1
  93. package/lib/_services/socket/socket-server.service.js.map +1 -1
  94. package/lib/tsconfig.tsbuildinfo +1 -1
  95. package/nodemon.json +3 -1
  96. package/package.json +9 -8
  97. package/src/_constants/mocks/app-extended-server.mock.ts +6 -2
  98. package/src/_constants/mocks/app-server.mock.ts +7 -1
  99. package/src/_constants/mocks/data-model.mock.ts +2 -2
  100. package/src/_constants/mocks/email-service-collection.mock.ts +2 -1
  101. package/src/_constants/mocks/email-service.mock.ts +2 -2
  102. package/src/_constants/mocks/endpoint.mock.ts +28 -26
  103. package/src/_constants/mocks/socket-server.mock.ts +12 -4
  104. package/src/_enums/index.ts +1 -1
  105. package/src/_models/control-models/api-call-params.control-model.ts +3 -2
  106. package/src/_models/control-models/app-system-controls.control-model copy.ts +1 -1
  107. package/src/_models/control-models/app-system-controls.control-model.ts +1 -1
  108. package/src/_models/control-models/endpoint-params.control-model.ts +39 -16
  109. package/src/_models/control-models/http-settings.control-model.ts +4 -2
  110. package/src/_modules/custom-data/custom-data.controller.ts +55 -51
  111. package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +7 -3
  112. package/src/_modules/test/get-test-routing-module.util.ts +7 -3
  113. package/src/_modules/test/test.controller.ts +98 -96
  114. package/src/_modules/usage/get-usage-routing-module.util.ts +8 -4
  115. package/src/_modules/usage/usage.controller.ts +108 -102
  116. package/src/_modules/usage/usage.data-service.ts +54 -28
  117. package/src/_services/base/data.service.ts +133 -34
  118. package/src/_services/base/db.service.ts +254 -171
  119. package/src/_services/base/singleton.service.ts +1 -1
  120. package/src/_services/core/api.service.ts +348 -218
  121. package/src/_services/core/auth.service.ts +2 -0
  122. package/src/_services/core/email.service.ts +537 -129
  123. package/src/_services/core/global.service.ts +56 -26
  124. package/src/_services/route/controller.service.ts +3 -1
  125. package/src/_services/route/routing-module.service.ts +33 -16
  126. package/src/_services/server/app-extended.server.spec.ts +22 -17
  127. package/src/_services/server/app-extended.server.ts +108 -45
  128. package/src/_services/server/app.server.spec.ts +17 -12
  129. package/src/_services/server/app.server.ts +264 -138
@@ -5,109 +5,111 @@ import { testModuleSettings } from '@futdevpro/fsm-dynamo/test-module';
5
5
 
6
6
  import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
7
7
  import { DynamoNTS_Controller } from '../../_services/route/controller.service';
8
- import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-params.control-model';
8
+ import {
9
+ DynamoNTS_EndpointParams
10
+ } from '../../_models/control-models/endpoint-params.control-model';
9
11
  import { DynamoNTS_GlobalService } from '../../_services/core/global.service';
10
12
 
11
13
  export class TestController extends DynamoNTS_Controller {
12
14
 
13
- static getInstance(): TestController {
14
- return TestController.getSingletonInstance();
15
- }
15
+ static getInstance(): TestController {
16
+ return TestController.getSingletonInstance();
17
+ }
16
18
 
17
- setupEndpoints(): void {
18
- this.endpoints = [
19
- // TESTS
20
- new DynamoNTS_EndpointParams({
21
- name: 'testGet',
22
- type: DynamoNTS_HttpCallType.get,
23
- endpoint: testModuleSettings.endPoints.testGet,
24
- tasks: [
25
- async (req: Request, res: Response) => {
26
- res.send({
27
- url: req.url,
28
- result: 'test-get call was successful!',
29
- request: req.body
30
- });
31
- }
32
- ]
33
- }),
34
-
35
- new DynamoNTS_EndpointParams({
36
- name: 'testPost',
37
- type: DynamoNTS_HttpCallType.post,
38
- endpoint: testModuleSettings.endPoints.testPost,
39
- tasks: [
40
- async (req: Request, res: Response) => {
41
- res.send({
42
- url: req.url,
43
- result: 'test-post call was successful!',
44
- request: req.body
45
- });
46
- }
47
- ]
48
- }),
19
+ setupEndpoints(): void {
20
+ this.endpoints = [
21
+ // TESTS
22
+ new DynamoNTS_EndpointParams({
23
+ name: 'testGet',
24
+ type: DynamoNTS_HttpCallType.get,
25
+ endpoint: testModuleSettings.endPoints.testGet,
26
+ tasks: [
27
+ async (req: Request, res: Response): Promise<void> => {
28
+ res.send({
29
+ url: req.url,
30
+ result: 'test-get call was successful!',
31
+ request: req.body
32
+ });
33
+ }
34
+ ]
35
+ }),
49
36
 
50
- new DynamoNTS_EndpointParams({
51
- name: 'testPut',
52
- type: DynamoNTS_HttpCallType.put,
53
- endpoint: testModuleSettings.endPoints.testPut,
54
- tasks: [
55
- async (req: Request, res: Response) => {
56
- res.send({
57
- url: req.url,
58
- result: 'test-put call was successful!',
59
- request: req.body
60
- });
61
- }
62
- ]
63
- }),
37
+ new DynamoNTS_EndpointParams({
38
+ name: 'testPost',
39
+ type: DynamoNTS_HttpCallType.post,
40
+ endpoint: testModuleSettings.endPoints.testPost,
41
+ tasks: [
42
+ async (req: Request, res: Response): Promise<void> => {
43
+ res.send({
44
+ url: req.url,
45
+ result: 'test-post call was successful!',
46
+ request: req.body
47
+ });
48
+ }
49
+ ]
50
+ }),
64
51
 
65
- new DynamoNTS_EndpointParams({
66
- name: 'testPatch',
67
- type: DynamoNTS_HttpCallType.patch,
68
- endpoint: testModuleSettings.endPoints.testPatch,
69
- tasks: [
70
- async (req: Request, res: Response) => {
71
- res.send({
72
- url: req.url,
73
- result: 'test-patch call was successful!',
74
- request: req.body
75
- });
76
- }
77
- ]
78
- }),
52
+ new DynamoNTS_EndpointParams({
53
+ name: 'testPut',
54
+ type: DynamoNTS_HttpCallType.put,
55
+ endpoint: testModuleSettings.endPoints.testPut,
56
+ tasks: [
57
+ async (req: Request, res: Response): Promise<void> => {
58
+ res.send({
59
+ url: req.url,
60
+ result: 'test-put call was successful!',
61
+ request: req.body
62
+ });
63
+ }
64
+ ]
65
+ }),
79
66
 
80
- new DynamoNTS_EndpointParams({
81
- name: 'testDelete',
82
- type: DynamoNTS_HttpCallType.delete,
83
- endpoint: testModuleSettings.endPoints.testDelete,
84
- tasks: [
85
- async (req: Request, res: Response) => {
86
- res.send({
87
- url: req.url,
88
- result: 'test-delete call was successful!',
89
- request: req.body
90
- });
91
- }
92
- ]
93
- }),
94
-
95
- new DynamoNTS_EndpointParams({
96
- name: 'getServerStatus',
97
- type: DynamoNTS_HttpCallType.get,
98
- endpoint: testModuleSettings.endPoints.getServerStatus,
99
- tasks: [
100
- async (req: Request, res: Response) => {
101
-
102
- res.send({
103
- status: 'ready',
104
- version: DynamoNTS_GlobalService.params.version,
105
- upTime: DynamoNTS_GlobalService.upTime,
106
- });
107
- }
108
- ]
109
- }),
110
- ];
111
- }
67
+ new DynamoNTS_EndpointParams({
68
+ name: 'testPatch',
69
+ type: DynamoNTS_HttpCallType.patch,
70
+ endpoint: testModuleSettings.endPoints.testPatch,
71
+ tasks: [
72
+ async (req: Request, res: Response): Promise<void> => {
73
+ res.send({
74
+ url: req.url,
75
+ result: 'test-patch call was successful!',
76
+ request: req.body
77
+ });
78
+ }
79
+ ]
80
+ }),
81
+
82
+ new DynamoNTS_EndpointParams({
83
+ name: 'testDelete',
84
+ type: DynamoNTS_HttpCallType.delete,
85
+ endpoint: testModuleSettings.endPoints.testDelete,
86
+ tasks: [
87
+ async (req: Request, res: Response): Promise<void> => {
88
+ res.send({
89
+ url: req.url,
90
+ result: 'test-delete call was successful!',
91
+ request: req.body
92
+ });
93
+ }
94
+ ]
95
+ }),
96
+
97
+ new DynamoNTS_EndpointParams({
98
+ name: 'getServerStatus',
99
+ type: DynamoNTS_HttpCallType.get,
100
+ endpoint: testModuleSettings.endPoints.getServerStatus,
101
+ tasks: [
102
+ async (req: Request, res: Response): Promise<void> => {
103
+
104
+ res.send({
105
+ status: 'ready',
106
+ version: DynamoNTS_GlobalService.params.version,
107
+ upTime: DynamoNTS_GlobalService.upTime,
108
+ });
109
+ }
110
+ ]
111
+ }),
112
+ ];
113
+ }
112
114
  }
113
115
 
@@ -1,15 +1,19 @@
1
1
 
2
2
  import { usageModuleSettings } from '@futdevpro/fsm-dynamo/usage-module';
3
3
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
4
- import { DynamoNTS_RoutingModuleSettings } from '../../_models/interfaces/routing-module-settings.interface';
4
+ import {
5
+ DynamoNTS_RoutingModuleSettings
6
+ } from '../../_models/interfaces/routing-module-settings.interface';
5
7
  import { DynamoNTS_RoutingModule } from '../../_services/route/routing-module.service';
6
8
  import { UsageController } from './usage.controller';
7
9
 
8
- export function getUsageRoutingModule(securityOverride?: DynamoNTS_RouteSecurity): DynamoNTS_RoutingModule {
10
+ export function getUsageRoutingModule(
11
+ securityOverride?: DynamoNTS_RouteSecurity
12
+ ): DynamoNTS_RoutingModule {
9
13
  const set: DynamoNTS_RoutingModuleSettings = {
10
14
  route: usageModuleSettings.mainRoute,
11
- controllers: [ UsageController.getInstance() ]
12
- }
15
+ controllers: [ UsageController.getInstance() ],
16
+ };
13
17
 
14
18
  if (securityOverride) {
15
19
  set.securityOverride = securityOverride;
@@ -1,115 +1,121 @@
1
1
 
2
2
  import { Request, Response } from 'express';
3
3
 
4
- import { usageModuleSettings, Dynamo_UsageSession } from '@futdevpro/fsm-dynamo/usage-module';
4
+ import {
5
+ usageModuleSettings, Dynamo_UsageSession, Dynamo_RelativeDate
6
+ } from '@futdevpro/fsm-dynamo/usage-module';
5
7
 
6
8
  import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
7
9
  import { DynamoNTS_AuthService } from '../../_services/core/auth.service';
8
10
  import { DynamoNTS_Controller } from '../../_services/route/controller.service';
9
11
  import { DynamoNTS_GlobalService } from '../../_services/core/global.service';
10
- import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-params.control-model';
12
+ import {
13
+ DynamoNTS_EndpointParams
14
+ } from '../../_models/control-models/endpoint-params.control-model';
11
15
  import { UsageService } from './usage.data-service';
12
16
 
13
17
  export class UsageController extends DynamoNTS_Controller {
14
-
15
- static getInstance(): UsageController {
16
- return UsageController.getSingletonInstance();
17
- }
18
-
19
- // SERVICES
20
- private authService: DynamoNTS_AuthService;
21
-
22
- setupEndpoints(): void {
23
- this.authService = DynamoNTS_GlobalService.getAuthService();
24
-
25
- this.endpoints = [
26
- new DynamoNTS_EndpointParams({
27
- name: 'newSession',
28
- type: DynamoNTS_HttpCallType.get,
29
- endpoint: usageModuleSettings.endPoints.newSession,
30
- tasks: [
31
- async (req: Request, res: Response, issuer: string) => {
32
- const authService = DynamoNTS_GlobalService.getAuthService();
33
- const username = authService.getUsernameFromRequest(req);
34
- const usageService = new UsageService({
35
- usageSession: new Dynamo_UsageSession({
36
- sessionStart: new Date(),
37
- issuer: username,
38
- }),
39
- issuer
40
- });
41
-
42
- await usageService.getLocationDataFromRequest(req);
43
- await usageService.saveData();
44
-
45
- res.send(
46
- usageService.data
47
- );
48
- }
49
- ]
50
- }),
51
-
52
- new DynamoNTS_EndpointParams({
53
- name: 'updateUsage',
54
- type: DynamoNTS_HttpCallType.post,
55
- endpoint: usageModuleSettings.endPoints.updateUsage,
56
- logRequestsContent: false,
57
- tasks: [
58
- async (req: Request, res: Response, issuer: string) => {
59
- const usageService = new UsageService({
60
- usageSession: { _id: req.params.sessionId },
61
- usageData: req.body,
62
- issuer
63
- });
64
-
65
- await usageService.updateUsageData(req);
66
-
67
- res.send(
68
- usageService.data
69
- );
70
- }
71
- ]
72
- }),
73
-
74
- new DynamoNTS_EndpointParams({
75
- name: 'closeSession',
76
- type: DynamoNTS_HttpCallType.get,
77
- endpoint: usageModuleSettings.endPoints.closeSession,
78
- tasks: [
79
- async (req: Request, res: Response, issuer: string) => {
80
- const usageService = new UsageService({
81
- usageSession: { _id: req.params.sessionId },
82
- issuer
83
- });
84
-
85
- await usageService.closeSession(req);
86
-
87
- res.send(
88
- usageService.data
89
- );
90
- }
91
- ]
92
- }),
93
-
94
- new DynamoNTS_EndpointParams({
95
- name: 'getAllUsageData',
96
- type: DynamoNTS_HttpCallType.get,
97
- endpoint: usageModuleSettings.endPoints.getAllUsageData,
98
- preProcessess: [ this.authService.authTokenPermAccUsageData ],
99
- tasks: [
100
- async (req: Request, res: Response) => {
101
- const usageService = new UsageService();
102
-
103
- await usageService.getLastWeekUsage();
104
-
105
- res.send(
106
- usageService.simplifiedDailyUsage
107
- );
108
- }
109
- ]
110
- }),
111
-
112
- ];
113
- }
18
+
19
+ static getInstance(): UsageController {
20
+ return UsageController.getSingletonInstance();
21
+ }
22
+
23
+ // SERVICES
24
+ private authService: DynamoNTS_AuthService;
25
+
26
+ setupEndpoints(): void {
27
+ this.authService = DynamoNTS_GlobalService.getAuthService();
28
+
29
+ this.endpoints = [
30
+ new DynamoNTS_EndpointParams({
31
+ name: 'newSession',
32
+ type: DynamoNTS_HttpCallType.get,
33
+ endpoint: usageModuleSettings.endPoints.newSession,
34
+ tasks: [
35
+ async (req: Request, res: Response, issuer: string): Promise<void> => {
36
+ const authService = DynamoNTS_GlobalService.getAuthService();
37
+ const username = authService.getUsernameFromRequest(req);
38
+ const usageService = new UsageService({
39
+ usageSession: new Dynamo_UsageSession({
40
+ sessionStart: new Date(),
41
+ issuer: username,
42
+ }),
43
+ issuer,
44
+ });
45
+
46
+ await usageService.getLocationDataFromRequest(req);
47
+ await usageService.saveData();
48
+
49
+ res.send(
50
+ usageService.data
51
+ );
52
+ },
53
+ ],
54
+ }),
55
+
56
+ new DynamoNTS_EndpointParams({
57
+ name: 'updateUsage',
58
+ type: DynamoNTS_HttpCallType.post,
59
+ endpoint: usageModuleSettings.endPoints.updateUsage,
60
+ logRequestsContent: false,
61
+ tasks: [
62
+ async (req: Request, res: Response, issuer: string): Promise<void> => {
63
+ const usageService = new UsageService({
64
+ usageSession: { _id: req.params.sessionId },
65
+ usageData: req.body,
66
+ issuer,
67
+ });
68
+
69
+ await usageService.updateUsageData(req);
70
+
71
+ res.send(
72
+ usageService.data
73
+ );
74
+ },
75
+ ],
76
+ }),
77
+
78
+ new DynamoNTS_EndpointParams({
79
+ name: 'closeSession',
80
+ type: DynamoNTS_HttpCallType.get,
81
+ endpoint: usageModuleSettings.endPoints.closeSession,
82
+ tasks: [
83
+ async (req: Request, res: Response, issuer: string): Promise<void> => {
84
+ const usageService = new UsageService({
85
+ usageSession: { _id: req.params.sessionId },
86
+ issuer,
87
+ });
88
+
89
+ await usageService.closeSession(req);
90
+
91
+ res.send(
92
+ usageService.data
93
+ );
94
+ },
95
+ ],
96
+ }),
97
+
98
+ new DynamoNTS_EndpointParams({
99
+ name: 'getUsageData',
100
+ type: DynamoNTS_HttpCallType.get,
101
+ endpoint: usageModuleSettings.endPoints.getUsageData,
102
+ preProcessess: [this.authService.authTokenPermAccUsageData],
103
+ tasks: [
104
+ async (req: Request, res: Response): Promise<void> => {
105
+ const range: Dynamo_RelativeDate = req.params.range as Dynamo_RelativeDate;
106
+
107
+ const usageService = new UsageService();
108
+
109
+ await usageService.getUsage(range);
110
+
111
+ res.send(
112
+ usageService.simplifiedDailyUsage
113
+ );
114
+ },
115
+ ],
116
+ }),
117
+
118
+ ];
119
+ }
114
120
  }
115
121
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { Request } from 'express';
3
- import { Dynamo_Error, Dynamo_Time } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Error, Dynamo_Time, Dynamo_RelativeDate } from '@futdevpro/fsm-dynamo';
4
4
  import { Dynamo_UsageSession, usageSessionModelParams, Dynamo_UsageData,
5
5
  Dynamo_DailyUsageData } from '@futdevpro/fsm-dynamo/usage-module';
6
6
 
@@ -34,31 +34,35 @@ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
34
34
  /* console.log(`...getLocationDataFromRequest... ip: ${this.data.address}`, this.data.locationData); */
35
35
  } catch (error) {
36
36
  throw new Dynamo_Error({
37
- status: 417,
37
+ ...this.getDefaultErrorSettings('getLocationDataFromRequest', error),
38
+
38
39
  errorCode: 'NTS-US0-GLD',
39
- message: 'getLocationDataFromRequest was unsuccessful',
40
40
  userMessage: `We were unable to deep analyze your request.`,
41
- error
42
41
  });
43
42
  }
44
43
  }
45
44
 
46
- async getLastWeekUsage(): Promise<void> {
45
+ async getUsage(range: Dynamo_RelativeDate = Dynamo_RelativeDate.lastWeek): Promise<void> {
47
46
  try {
48
47
  await this.dataDBService.find({
49
- sessionStart: { $gte: Dynamo_Time.oneWeekAgo() }
50
- }).then((res: Dynamo_UsageSession[]) => {
48
+ sessionStart: { $gte: Dynamo_Time.getDateByRelativeDate(range) },
49
+ }).then((res: Dynamo_UsageSession[]): void => {
51
50
  this.dataList = res;
52
51
  });
53
52
  this.simplifiedDailyUsage = [];
54
- this.dataList.forEach((session: Dynamo_UsageSession) => {
53
+ this.dataList.forEach((session: Dynamo_UsageSession): void => {
55
54
  let dateIndex = this.simplifiedDailyUsage.findIndex(
56
- (dailyData: Dynamo_DailyUsageData) => dailyData.date === session.date
55
+ (dailyData: Dynamo_DailyUsageData): boolean => dailyData.date === session.date
57
56
  );
57
+
58
58
  if (-1 < dateIndex) {
59
59
  this.simplifiedDailyUsage[dateIndex].visitations.push(session);
60
60
  } else {
61
- const newUsageSimple = new Dynamo_DailyUsageData({ date: session.date, visitations: [ session ] });
61
+ const newUsageSimple = new Dynamo_DailyUsageData({
62
+ date: session.date,
63
+ visitations: [ session ],
64
+ });
65
+
62
66
  this.simplifiedDailyUsage.push(newUsageSimple);
63
67
  dateIndex = this.simplifiedDailyUsage.length - 1;
64
68
  }
@@ -72,27 +76,28 @@ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
72
76
  }
73
77
  this.simplifiedDailyUsage[dateIndex].totalVisitTime += session.totalSessionTime;
74
78
  this.simplifiedDailyUsage[dateIndex].averageVisitTime = Math.round(
75
- (this.simplifiedDailyUsage[dateIndex].totalVisitTime /
76
- this.simplifiedDailyUsage[dateIndex].visitations.length) * 100
77
- ) / 100;
79
+ (this.simplifiedDailyUsage[dateIndex].totalVisitTime /
80
+ this.simplifiedDailyUsage[dateIndex].visitations.length) * 100
81
+ ) / 100;
78
82
  });
79
83
 
80
84
  this.simplifiedDailyUsage.sort(
81
- (a: Dynamo_DailyUsageData, b: Dynamo_DailyUsageData) => +new Date(b.date) - +new Date(a.date)
85
+ (a: Dynamo_DailyUsageData, b: Dynamo_DailyUsageData): number =>
86
+ +new Date(b.date) - +new Date(a.date)
82
87
  );
83
- this.simplifiedDailyUsage.forEach((daily: Dynamo_DailyUsageData) => {
88
+ this.simplifiedDailyUsage.forEach((daily: Dynamo_DailyUsageData): void => {
84
89
  daily.visitations.sort(
85
- (a: Dynamo_UsageSession, b: Dynamo_UsageSession) => +a.sessionStart - +b.sessionStart
90
+ (a: Dynamo_UsageSession, b: Dynamo_UsageSession): number =>
91
+ +a.sessionStart - +b.sessionStart
86
92
  );
87
93
  });
88
94
 
89
95
  } catch (error) {
90
96
  throw new Dynamo_Error({
91
- status: 417,
97
+ ...this.getDefaultErrorSettings('getLastWeekUsage', error),
98
+
92
99
  errorCode: 'NTS-US0-GLW',
93
- message: 'getDailyUsage was unsuccessful',
94
100
  userMessage: `We've failed to collect last week's usage data.`,
95
- error
96
101
  });
97
102
  }
98
103
  }
@@ -102,9 +107,11 @@ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
102
107
  await this.getDataById();
103
108
  this.data.usageData = this.usageData;
104
109
  let totalTime = 0;
105
- this.data.usageData.forEach((data: Dynamo_UsageData) => {
110
+
111
+ this.data.usageData.forEach((data: Dynamo_UsageData): void => {
106
112
  totalTime += data.timeSpentOnPage;
107
113
  });
114
+
108
115
  if (!this.data.locationData) {
109
116
  this.getLocationDataFromRequest(req);
110
117
  }
@@ -112,11 +119,10 @@ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
112
119
  await this.saveData();
113
120
  } catch (error) {
114
121
  throw new Dynamo_Error({
115
- status: 417,
122
+ ...this.getDefaultErrorSettings('updateUsageData', error),
123
+
116
124
  errorCode: 'NTS-US0-UU0',
117
- message: 'updateSessionData was unsuccessful',
118
125
  userMessage: `The attempt to update Usage Data was unsuccessful.`,
119
- error
120
126
  });
121
127
  }
122
128
  }
@@ -126,21 +132,41 @@ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
126
132
  await this.getDataById();
127
133
  this.data.sessionEnd = new Date();
128
134
  const newTotalSessionTime = +this.data.sessionEnd - +this.data.sessionStart;
129
- this.data.usageData[this.data.usageData.length - 1].timeSpentOnPage = newTotalSessionTime - this.data.totalSessionTime;
135
+
136
+ this.data.usageData[this.data.usageData.length - 1].timeSpentOnPage =
137
+ newTotalSessionTime - this.data.totalSessionTime;
138
+
130
139
  if (!this.data.locationData) {
131
140
  this.getLocationDataFromRequest(req);
132
141
  }
133
- this.data.usageData.sort((a: Dynamo_UsageData, b: Dynamo_UsageData) => +a.opened - +b.opened);
142
+ this.data.usageData.sort(
143
+ (a: Dynamo_UsageData, b: Dynamo_UsageData): number => +a.opened - +b.opened
144
+ );
134
145
  this.data.totalSessionTime = newTotalSessionTime;
135
146
  await this.saveData();
136
147
  } catch (error) {
137
148
  throw new Dynamo_Error({
138
- status: 417,
149
+ ...this.getDefaultErrorSettings('closeSession', error),
150
+
139
151
  errorCode: 'NTS-US0-CS0',
140
- message: 'closeSession was unsuccessful',
141
152
  userMessage: `The attempt to close Usage Session was unsuccessful.`,
142
- error
143
153
  });
144
154
  }
145
155
  }
156
+
157
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
158
+ private getDefaultErrorSettings(
159
+ fnName: string,
160
+ error: Error | Dynamo_Error
161
+ )/* : Dynamo_ErrorSettings */ {
162
+ return {
163
+ status: (error as Dynamo_Error)?.___status ?? 417,
164
+ message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.serviceName})`,
165
+ addECToUserMsg: true,
166
+ userMessage: this.defaultErrorUserMsg,
167
+ issuer: this.issuer,
168
+ issuerService: this.serviceName,
169
+ error: error,
170
+ };
171
+ }
146
172
  }