@futdevpro/nts-dynamo 1.7.16 → 1.7.20
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/.eslintrc.json +171 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/data-model.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service.mock.js +3 -3
- package/lib/_constants/mocks/email-service.mock.js.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_enums/index.js +1 -1
- package/lib/_enums/index.js.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.d.ts +2 -2
- package/lib/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +15 -9
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.js +3 -1
- package/lib/_models/control-models/http-settings.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.js +2 -1
- package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.js.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.js.map +1 -1
- package/lib/_modules/test/test.controller.d.ts.map +1 -1
- package/lib/_modules/test/test.controller.js.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js.map +1 -1
- package/lib/_modules/usage/usage.controller.d.ts.map +1 -1
- package/lib/_modules/usage/usage.controller.js +15 -14
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_modules/usage/usage.data-service.d.ts +3 -1
- package/lib/_modules/usage/usage.data-service.d.ts.map +1 -1
- package/lib/_modules/usage/usage.data-service.js +24 -16
- package/lib/_modules/usage/usage.data-service.js.map +1 -1
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +45 -23
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +82 -53
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/base/singleton.service.d.ts.map +1 -1
- package/lib/_services/base/singleton.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts +21 -13
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +192 -143
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/auth.service.d.ts.map +1 -1
- package/lib/_services/core/auth.service.js.map +1 -1
- package/lib/_services/core/email.service.d.ts +50 -36
- package/lib/_services/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +329 -94
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +30 -19
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/controller.service.d.ts.map +1 -1
- package/lib/_services/route/controller.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.js +2 -2
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +19 -14
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.js +1 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +4 -3
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +107 -52
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +1 -0
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.static-service.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/nodemon.json +3 -1
- package/package.json +9 -8
- package/src/_constants/mocks/app-extended-server.mock.ts +6 -2
- package/src/_constants/mocks/app-server.mock.ts +7 -1
- package/src/_constants/mocks/data-model.mock.ts +2 -2
- package/src/_constants/mocks/email-service-collection.mock.ts +2 -1
- package/src/_constants/mocks/email-service.mock.ts +2 -2
- package/src/_constants/mocks/endpoint.mock.ts +28 -26
- package/src/_constants/mocks/socket-server.mock.ts +12 -4
- package/src/_enums/index.ts +1 -1
- package/src/_models/control-models/api-call-params.control-model.ts +3 -2
- package/src/_models/control-models/app-system-controls.control-model copy.ts +1 -1
- package/src/_models/control-models/app-system-controls.control-model.ts +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +39 -16
- package/src/_models/control-models/http-settings.control-model.ts +4 -2
- package/src/_modules/custom-data/custom-data.controller.ts +55 -51
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +7 -3
- package/src/_modules/test/get-test-routing-module.util.ts +7 -3
- package/src/_modules/test/test.controller.ts +98 -96
- package/src/_modules/usage/get-usage-routing-module.util.ts +8 -4
- package/src/_modules/usage/usage.controller.ts +108 -102
- package/src/_modules/usage/usage.data-service.ts +54 -28
- package/src/_services/base/data.service.ts +133 -34
- package/src/_services/base/db.service.ts +254 -171
- package/src/_services/base/singleton.service.ts +1 -1
- package/src/_services/core/api.service.ts +348 -218
- package/src/_services/core/auth.service.ts +2 -0
- package/src/_services/core/email.service.ts +537 -129
- package/src/_services/core/global.service.ts +56 -26
- package/src/_services/route/controller.service.ts +3 -1
- package/src/_services/route/routing-module.service.ts +33 -16
- package/src/_services/server/app-extended.server.spec.ts +22 -17
- package/src/_services/server/app-extended.server.ts +108 -45
- package/src/_services/server/app.server.spec.ts +17 -12
- 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 {
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
static getInstance(): TestController {
|
|
16
|
+
return TestController.getSingletonInstance();
|
|
17
|
+
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 {
|
|
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(
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
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({
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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) =>
|
|
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) =>
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
}
|