@futdevpro/nts-dynamo 1.5.45 → 1.5.49

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 (67) hide show
  1. package/futdevpro-nts-dynamo-01.05.47.tgz +0 -0
  2. package/futdevpro-nts-dynamo-01.05.49.tgz +0 -0
  3. package/lib/_models/dynamo-nts-endpoint-params.js +1 -1
  4. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  5. package/lib/_models/dynamo-nts-socket-dictionary.d.ts.map +1 -1
  6. package/lib/_models/dynamo-nts-socket-dictionary.js +5 -2
  7. package/lib/_models/dynamo-nts-socket-dictionary.js.map +1 -1
  8. package/lib/_modules/test/custom-data.service.d.ts +3 -3
  9. package/lib/_modules/test/custom-data.service.d.ts.map +1 -1
  10. package/lib/_modules/test/custom-data.service.js +4 -4
  11. package/lib/_modules/test/custom-data.service.js.map +1 -1
  12. package/lib/_modules/test/test-controller.js +6 -6
  13. package/lib/_modules/test/test-controller.js.map +1 -1
  14. package/lib/_modules/usage/usage-controller.js +1 -1
  15. package/lib/_modules/usage/usage-controller.js.map +1 -1
  16. package/lib/_modules/usage/usage.service.d.ts +6 -6
  17. package/lib/_modules/usage/usage.service.d.ts.map +1 -1
  18. package/lib/_modules/usage/usage.service.js +10 -6
  19. package/lib/_modules/usage/usage.service.js.map +1 -1
  20. package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
  21. package/lib/_services/dynamo-nts-api.service.js +16 -6
  22. package/lib/_services/dynamo-nts-api.service.js.map +1 -1
  23. package/lib/_services/dynamo-nts-app.d.ts +1 -0
  24. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  25. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  26. package/lib/_services/dynamo-nts-auth.service.js +8 -4
  27. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  28. package/lib/_services/dynamo-nts-data.service.d.ts +2 -2
  29. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  30. package/lib/_services/dynamo-nts-data.service.js +72 -43
  31. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  32. package/lib/_services/dynamo-nts-db.service.d.ts +4 -4
  33. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  34. package/lib/_services/dynamo-nts-db.service.js +124 -84
  35. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  36. package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
  37. package/lib/_services/dynamo-nts-email.service.js +20 -16
  38. package/lib/_services/dynamo-nts-email.service.js.map +1 -1
  39. package/lib/_services/dynamo-nts-global.service.d.ts +3 -3
  40. package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
  41. package/lib/_services/dynamo-nts-global.service.js.map +1 -1
  42. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  43. package/lib/_services/dynamo-nts-routing-module.service.js +17 -11
  44. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  45. package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
  46. package/lib/_services/dynamo-nts-socket.service.js +5 -1
  47. package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
  48. package/lib/_services/dynamobe-data.service.d.ts +2 -2
  49. package/lib/_services/dynamobe-db.service.d.ts +4 -4
  50. package/lib/_services/dynamobe-db.service.js +4 -4
  51. package/lib/_services/dynamobe-global.service.d.ts +3 -3
  52. package/lib/tsconfig.tsbuildinfo +1 -5589
  53. package/package.json +13 -6
  54. package/src/_models/dynamo-nts-endpoint-params.ts +1 -1
  55. package/src/_models/dynamo-nts-socket-dictionary.ts +6 -3
  56. package/src/_modules/test/custom-data.service.ts +4 -4
  57. package/src/_modules/test/test-controller.ts +7 -7
  58. package/src/_modules/usage/usage-controller.ts +2 -2
  59. package/src/_modules/usage/usage.service.ts +26 -22
  60. package/src/_services/dynamo-nts-api.service.ts +22 -8
  61. package/src/_services/dynamo-nts-auth.service.ts +10 -6
  62. package/src/_services/dynamo-nts-data.service.ts +74 -45
  63. package/src/_services/dynamo-nts-db.service.ts +157 -87
  64. package/src/_services/dynamo-nts-email.service.ts +21 -17
  65. package/src/_services/dynamo-nts-global.service.ts +3 -3
  66. package/src/_services/dynamo-nts-routing-module.service.ts +16 -10
  67. package/src/_services/dynamo-nts-socket.service.ts +6 -2
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@futdevpro/nts-dynamo",
3
- "version": "01.05.45",
3
+ "version": "01.05.49",
4
4
  "description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Ltd.",
5
5
  "scripts": {
6
- "build": "npx tsc",
7
- "postbuild": "npm publish",
8
- "build-tgz": "npx tsc",
9
- "postbuild-tgz": "npm pack"
6
+ "build": "npm run inb",
7
+ "inb": "npm i",
8
+ "postinb": "npm run pinb",
9
+ "pinb": "npx tsc",
10
+ "postpinb": "npm publish",
11
+
12
+ "build-tgz": "npm run inbt",
13
+ "inbt": "npm i",
14
+ "postinbt": "npm run pinbt",
15
+ "pinbt": "npx tsc",
16
+ "postpinbt": "npm pack"
10
17
  },
11
18
  "main": "./lib/index.js",
12
19
  "module": "./lib/index.js",
@@ -169,7 +176,7 @@
169
176
  },
170
177
  "homepage": "https:/futdevpro.hu/projects/dynamo",
171
178
  "peerDependencies": {
172
- "@futdevpro/fsm-dynamo": "^1.5.24",
179
+ "@futdevpro/fsm-dynamo": "^1.5.29",
173
180
 
174
181
  "@types/express": "^4.17.7",
175
182
  "@types/geoip-lite": "^1.4.1",
@@ -84,7 +84,7 @@ export class DynamoNTS_EndpointParams{
84
84
  let inputs = '';
85
85
  for(let i = 0; i < this.pathParams.length; i++) {
86
86
  inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
87
- if (i + 1 < this.pathParams.length || req.body && req.body !== {}) {
87
+ if (i + 1 < this.pathParams.length || req.body && `${req.body}` !== '{}') {
88
88
  inputs += ',';
89
89
  }
90
90
  }
@@ -1,5 +1,5 @@
1
1
 
2
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
2
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
3
3
  import * as SocketIO from 'socket.io';
4
4
 
5
5
  export class DynamoNTS_SocketDictionary {
@@ -14,9 +14,12 @@ export class DynamoNTS_SocketDictionary {
14
14
  ) {
15
15
  this.issuerId = set.issuerId;
16
16
  if (!set.sockets.length) {
17
- throw new DynamoNTS_Error({
17
+ throw new Dynamo_Error({
18
18
  status: 406,
19
- message: 'trying to create DynamoNTS_SocketDictionary without a single active sockets'
19
+ errorCode: 'NTS-SD0-C00',
20
+ addECToUserMsg: true,
21
+ message: 'trying to create DynamoNTS_SocketDictionary without a single active socket',
22
+ userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.'
20
23
  });
21
24
  }
22
25
  this.sockets = set.sockets;
@@ -1,17 +1,17 @@
1
1
 
2
2
 
3
3
 
4
- import { CustomData, customDataModelParams } from '@futdevpro/fsm-dynamo/test-module';
4
+ import { Dynamo_CustomData, customDataModelParams } from '@futdevpro/fsm-dynamo/test-module';
5
5
  import { DynamoNTS_DataService } from '../../_services/dynamo-nts-data.service';
6
6
 
7
- export class CustomDataService extends DynamoNTS_DataService<CustomData> {
7
+ export class Dynamo_CustomDataService extends DynamoNTS_DataService<Dynamo_CustomData> {
8
8
 
9
9
  constructor(
10
- customData?: CustomData,
10
+ customData?: Dynamo_CustomData,
11
11
  issuer?: string,
12
12
  ) {
13
13
  super(
14
- new CustomData(customData),
14
+ new Dynamo_CustomData(customData),
15
15
  customDataModelParams,
16
16
  issuer
17
17
  );
@@ -4,7 +4,7 @@ import { testModuleSettings } from '@futdevpro/fsm-dynamo/test-module';
4
4
  import { HttpCallType } from '../../_enums/http/http-call-type.enum';
5
5
  import { DynamoNTS_EndpointParams } from '../../_models/dynamo-nts-endpoint-params';
6
6
  import { DynamoNTS_Controller } from '../../_services/dynamo-nts-controller.service';
7
- import { CustomDataService } from './custom-data.service';
7
+ import { Dynamo_CustomDataService } from './custom-data.service';
8
8
 
9
9
  export class TestController extends DynamoNTS_Controller {
10
10
 
@@ -92,12 +92,12 @@ export class TestController extends DynamoNTS_Controller {
92
92
 
93
93
  // CUSTOM DATA
94
94
  new DynamoNTS_EndpointParams({
95
- name: 'getCustomData',
95
+ name: 'getDynamo_CustomData',
96
96
  type: HttpCallType.get,
97
- endpoint: testModuleSettings.endPoints.getCustomData,
97
+ endpoint: testModuleSettings.endPoints.getDynamo_CustomData,
98
98
  tasks: [
99
99
  async (req: Request, res: Response) => {
100
- const customDataService = new CustomDataService({ _id: req.params.customId });
100
+ const customDataService = new Dynamo_CustomDataService({ _id: req.params.customId });
101
101
 
102
102
  await customDataService.getDataById();
103
103
 
@@ -112,12 +112,12 @@ export class TestController extends DynamoNTS_Controller {
112
112
  }),
113
113
 
114
114
  new DynamoNTS_EndpointParams({
115
- name: 'modifyCustomData',
115
+ name: 'modifyDynamo_CustomData',
116
116
  type: HttpCallType.post,
117
- endpoint: testModuleSettings.endPoints.modifyCustomData,
117
+ endpoint: testModuleSettings.endPoints.modifyDynamo_CustomData,
118
118
  tasks: [
119
119
  async (req: Request, res: Response, issuer: string) => {
120
- const customDataService = new CustomDataService(req.body, issuer);
120
+ const customDataService = new Dynamo_CustomDataService(req.body, issuer);
121
121
 
122
122
  await customDataService.saveData();
123
123
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { Request, Response } from 'express';
3
- import { usageModuleSettings, DynamoUsageSession } from '@futdevpro/fsm-dynamo/usage-module';
3
+ import { usageModuleSettings, Dynamo_UsageSession } from '@futdevpro/fsm-dynamo/usage-module';
4
4
  import { HttpCallType } from '../../_enums/http/http-call-type.enum';
5
5
  import { DynamoNTS_EndpointParams } from '../../_models/dynamo-nts-endpoint-params';
6
6
  import { DynamoNTS_AuthService } from '../../_services/dynamo-nts-auth.service';
@@ -30,7 +30,7 @@ export class UsageController extends DynamoNTS_Controller {
30
30
  const authService = DynamoNTS_GlobalService.getAuthService();
31
31
  const username = authService.getUsernameFromRequest(req);
32
32
  const usageService = new UsageService({
33
- usageSession: new DynamoUsageSession({
33
+ usageSession: new Dynamo_UsageSession({
34
34
  sessionStart: new Date(),
35
35
  issuer: username,
36
36
  }),
@@ -1,25 +1,25 @@
1
1
 
2
2
  import { Request } from 'express';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
4
- import { DynamoUsageSession, usageSessionModelParams, DynamoUsageData,
5
- DailyUsageData } from '@futdevpro/fsm-dynamo/usage-module';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
+ import { Dynamo_UsageSession, usageSessionModelParams, Dynamo_UsageData,
5
+ Dynamo_DailyUsageData } from '@futdevpro/fsm-dynamo/usage-module';
6
6
 
7
7
  import { DynamoNTS_DataService } from '../../_services/dynamo-nts-data.service';
8
8
  import { DynamoNTS_Shared } from '../../_services/dynamo-nts-shared.service';
9
9
 
10
- export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
11
- usageData: DynamoUsageData[] = [];
12
- simplifiedDailyUsage: DailyUsageData[] = [];
10
+ export class UsageService extends DynamoNTS_DataService<Dynamo_UsageSession> {
11
+ usageData: Dynamo_UsageData[] = [];
12
+ simplifiedDailyUsage: Dynamo_DailyUsageData[] = [];
13
13
 
14
14
  constructor(
15
15
  set?: {
16
- usageSession?: DynamoUsageSession,
17
- usageData?: DynamoUsageData[],
16
+ usageSession?: Dynamo_UsageSession,
17
+ usageData?: Dynamo_UsageData[],
18
18
  issuer?: string,
19
19
  }
20
20
  ) {
21
21
  super(
22
- new DynamoUsageSession(set?.usageSession),
22
+ new Dynamo_UsageSession(set?.usageSession),
23
23
  usageSessionModelParams,
24
24
  set?.issuer
25
25
  );
@@ -33,8 +33,9 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
33
33
 
34
34
  /* console.log(`...getLocationDataFromRequest... ip: ${this.data.address}`, this.data.locationData); */
35
35
  } catch (error) {
36
- throw new DynamoNTS_Error({
36
+ throw new Dynamo_Error({
37
37
  status: 417,
38
+ errorCode: 'NTS-US0-GLD',
38
39
  message: 'getLocationDataFromRequest was unsuccessful',
39
40
  userMessage: `We were unable to deep analyze your request.`,
40
41
  error
@@ -46,18 +47,18 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
46
47
  try {
47
48
  await this.dataDBService.find({
48
49
  sessionStart: { $gte: DynamoNTS_Shared.oneWeekAgo() }
49
- }).then((res: DynamoUsageSession[]) => {
50
+ }).then((res: Dynamo_UsageSession[]) => {
50
51
  this.dataList = res;
51
52
  });
52
53
  this.simplifiedDailyUsage = [];
53
- this.dataList.forEach((session: DynamoUsageSession) => {
54
+ this.dataList.forEach((session: Dynamo_UsageSession) => {
54
55
  let dateIndex = this.simplifiedDailyUsage.findIndex(
55
- (dailyData: DailyUsageData) => dailyData.date === session.date
56
+ (dailyData: Dynamo_DailyUsageData) => dailyData.date === session.date
56
57
  );
57
58
  if (-1 < dateIndex) {
58
59
  this.simplifiedDailyUsage[dateIndex].visitations.push(session);
59
60
  } else {
60
- const newUsageSimple = new DailyUsageData({ date: session.date, visitations: [ session ] });
61
+ const newUsageSimple = new Dynamo_DailyUsageData({ date: session.date, visitations: [ session ] });
61
62
  this.simplifiedDailyUsage.push(newUsageSimple);
62
63
  dateIndex = this.simplifiedDailyUsage.length - 1;
63
64
  }
@@ -77,17 +78,18 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
77
78
  });
78
79
 
79
80
  this.simplifiedDailyUsage.sort(
80
- (a: DailyUsageData, b: DailyUsageData) => +new Date(b.date) - +new Date(a.date)
81
+ (a: Dynamo_DailyUsageData, b: Dynamo_DailyUsageData) => +new Date(b.date) - +new Date(a.date)
81
82
  );
82
- this.simplifiedDailyUsage.forEach((daily: DailyUsageData) => {
83
+ this.simplifiedDailyUsage.forEach((daily: Dynamo_DailyUsageData) => {
83
84
  daily.visitations.sort(
84
- (a: DynamoUsageSession, b: DynamoUsageSession) => +a.sessionStart - +b.sessionStart
85
+ (a: Dynamo_UsageSession, b: Dynamo_UsageSession) => +a.sessionStart - +b.sessionStart
85
86
  );
86
87
  });
87
88
 
88
89
  } catch (error) {
89
- throw new DynamoNTS_Error({
90
+ throw new Dynamo_Error({
90
91
  status: 417,
92
+ errorCode: 'NTS-US0-GLW',
91
93
  message: 'getDailyUsage was unsuccessful',
92
94
  userMessage: `We've failed to collect last week's usage data.`,
93
95
  error
@@ -100,7 +102,7 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
100
102
  await this.getDataById();
101
103
  this.data.usageData = this.usageData;
102
104
  let totalTime = 0;
103
- this.data.usageData.forEach((data: DynamoUsageData) => {
105
+ this.data.usageData.forEach((data: Dynamo_UsageData) => {
104
106
  totalTime += data.timeSpentOnPage;
105
107
  });
106
108
  if (!this.data.locationData) {
@@ -109,8 +111,9 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
109
111
  this.data.totalSessionTime = totalTime;
110
112
  await this.saveData();
111
113
  } catch (error) {
112
- throw new DynamoNTS_Error({
114
+ throw new Dynamo_Error({
113
115
  status: 417,
116
+ errorCode: 'NTS-US0-UU0',
114
117
  message: 'updateSessionData was unsuccessful',
115
118
  userMessage: `The attempt to update Usage Data was unsuccessful.`,
116
119
  error
@@ -127,12 +130,13 @@ export class UsageService extends DynamoNTS_DataService<DynamoUsageSession> {
127
130
  if (!this.data.locationData) {
128
131
  this.getLocationDataFromRequest(req);
129
132
  }
130
- this.data.usageData.sort((a: DynamoUsageData, b: DynamoUsageData) => +a.opened - +b.opened);
133
+ this.data.usageData.sort((a: Dynamo_UsageData, b: Dynamo_UsageData) => +a.opened - +b.opened);
131
134
  this.data.totalSessionTime = newTotalSessionTime;
132
135
  await this.saveData();
133
136
  } catch (error) {
134
- throw new DynamoNTS_Error({
137
+ throw new Dynamo_Error({
135
138
  status: 417,
139
+ errorCode: 'NTS-US0-CS0',
136
140
  message: 'closeSession was unsuccessful',
137
141
  userMessage: `The attempt to close Usage Session was unsuccessful.`,
138
142
  error
@@ -1,6 +1,6 @@
1
1
 
2
2
  import * as Axios from 'axios';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
4
 
5
5
  import { HttpCallType } from '../_enums/http/http-call-type.enum';
6
6
  import { HttpResponseType } from '../_enums/http/http-response-type.enum';
@@ -140,30 +140,44 @@ export class DynamoNTS_ApiService {
140
140
  } catch (error) {
141
141
  DynamoNTS_Shared.logError(`\nAPI ERROR: ${callParams?.name} failed...` +
142
142
  `\n${callParams?.baseUrl}${callParams?.endPoint}`);
143
+
143
144
  if (callParams?.httpOptions?.responseType === HttpResponseType.text) {
144
145
  error.error = JSON.parse(error.error);
145
146
  }
146
- if (error?.response?.data?.flag === 'DYNAMO-BE ERROR OBJECT') {
147
+
148
+ if (error?.response?.data?.flag === 'DYNAMO ERROR OBJECT') {
147
149
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
148
-
149
- throw new DynamoNTS_Error(error.response.data);
150
+
151
+ throw new Dynamo_Error({
152
+ errorCode: 'NTS-API-002',
153
+ addECToUserMsg: true,
154
+ message: 'API call failed on the other end! error response found...',
155
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
156
+ error: error.response.data
157
+ });
150
158
  } else if (error.code === 'ENOTFOUND') {
151
159
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
152
160
 
153
- throw new DynamoNTS_Error({
161
+ throw new Dynamo_Error({
154
162
  status: 404,
163
+ errorCode: 'NTS-API-000',
164
+ addECToUserMsg: true,
155
165
  message: 'DNS error; address cannot be resolved!',
156
- userMessage: `We encountered a BackEnd API Error, please contact the responsible development team. \nerrorCode: 965-453-300`,
166
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
157
167
  error: error
158
168
  });
159
169
  } else if (error.config && error.message) {
160
- throw new DynamoNTS_Error({
170
+
171
+ throw new Dynamo_Error({
161
172
  status: +error.message.substring(error.message.length - 4, 3),
162
- userMessage: `We encountered a BackEnd API Error, please contact the responsible development team. \nerrorCode: 965-453-303`,
173
+ errorCode: 'NTS-API-003',
174
+ addECToUserMsg: true,
175
+ userMessage: `We encountered a BackEnd API Error, please contact the responsible development team.`,
163
176
  error: error
164
177
  });
165
178
  } else {
166
179
  DynamoNTS_Shared.logError(`\n${callParams.name} was UNSUCCESSFUL`, error, '\n\n', new Error());
180
+
167
181
  throw error;
168
182
  }
169
183
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { NextFunction, Request, Response } from 'express';
3
- import { DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
4
 
5
5
  import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
6
6
 
@@ -29,22 +29,26 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
29
29
  static getTokenFromRequest(req: Request): string {
30
30
  const authHeader = req.headers['authorization'];
31
31
  if (!authHeader) {
32
- throw new DynamoNTS_Error({
32
+ throw new Dynamo_Error({
33
33
  status: 401,
34
+ errorCode: 'NTS-AS0-GT0',
35
+ addECToUserMsg: true,
34
36
  message: 'AuthHeader missing!',
35
- userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team. \nerrorCode: 007-636-500`,
37
+ userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team.`,
36
38
  });
37
39
  }
38
40
 
39
41
  const token = authHeader.split(' ')[1];
40
42
  if (!token) {
41
- throw new DynamoNTS_Error({
43
+ throw new Dynamo_Error({
42
44
  status: 401,
45
+ errorCode: 'NTS-AS0-GT1',
46
+ addECToUserMsg: true,
43
47
  message: 'Token missing!',
44
- userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team. \nerrorCode: 007-636-501`,
48
+ userMessage: `We encountered an unhandled BackEnd Auth Error, please contact the responsible development team.`,
45
49
  });
46
50
  }
47
-
51
+
48
52
  return token;
49
53
  }
50
54
 
@@ -1,5 +1,5 @@
1
1
 
2
- import { Metadata, DynamoNTS_DataParams, DynamoNTS_DataPropertyParams, DynamoNTS_Error } from '@futdevpro/fsm-dynamo';
2
+ import { Dynamo_Metadata, DynamoNTS_DataParams, DynamoNTS_DataPropertyParams, Dynamo_Error } from '@futdevpro/fsm-dynamo';
3
3
 
4
4
  import { DynamoNTS_DBService } from './dynamo-nts-db.service';
5
5
  import { DynamoNTS_GlobalService } from './dynamo-nts-global.service';
@@ -23,7 +23,7 @@ import { DynamoNTS_GlobalService } from './dynamo-nts-global.service';
23
23
  * }
24
24
  * }
25
25
  */
26
- export class DynamoNTS_DataService<T extends Metadata> {
26
+ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
27
27
  dataDBService: DynamoNTS_DBService<T>;
28
28
  data: T;
29
29
  dataList: T[] = [];
@@ -57,10 +57,12 @@ export class DynamoNTS_DataService<T extends Metadata> {
57
57
  this.dataList = dataList;
58
58
  });
59
59
  } catch (error) {
60
- throw new DynamoNTS_Error({
60
+ throw new Dynamo_Error({
61
61
  status: 417,
62
+ errorCode: 'NTS-DS0-GA0',
63
+ addECToUserMsg: true,
62
64
  message: 'getAll was unsuccessful',
63
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-130`,
65
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
64
66
  error: error
65
67
  });
66
68
  }
@@ -81,18 +83,21 @@ export class DynamoNTS_DataService<T extends Metadata> {
81
83
  });
82
84
  return dataExists;
83
85
  } else {
84
- throw new DynamoNTS_Error({
86
+ throw new Dynamo_Error({
85
87
  status: 417,
88
+ errorCode: 'NTS-DS0-GI1',
89
+ addECToUserMsg: true,
86
90
  message: `ID is missing! (maybe you wanted to use getDataByDependencyId instead...)`,
87
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-131B`,
88
- error: new Error()
91
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
89
92
  });
90
93
  }
91
94
  } catch (error) {
92
- throw new DynamoNTS_Error({
95
+ throw new Dynamo_Error({
93
96
  status: 417,
97
+ errorCode: 'NTS-DS0-GI0',
98
+ addECToUserMsg: true,
94
99
  message: 'getDataById was unsuccessful',
95
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-131A`,
100
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
96
101
  error: error
97
102
  });
98
103
  }
@@ -115,26 +120,30 @@ export class DynamoNTS_DataService<T extends Metadata> {
115
120
  });
116
121
  return dataExists;
117
122
  } else {
118
- throw new DynamoNTS_Error({
123
+ throw new Dynamo_Error({
119
124
  status: 417,
125
+ errorCode: 'NTS-DS0-GD3',
126
+ addECToUserMsg: true,
120
127
  message: `${this.depKey} is missing!`,
121
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-132C`,
122
- error: new Error()
128
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
123
129
  });
124
130
  }
125
131
  } else {
126
- throw new DynamoNTS_Error({
132
+ throw new Dynamo_Error({
127
133
  status: 417,
134
+ errorCode: 'NTS-DS0-GD2',
135
+ addECToUserMsg: true,
128
136
  message: 'dependencyDataIdKey is missing from service!',
129
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-132B`,
130
- error: new Error()
137
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
131
138
  });
132
139
  }
133
140
  } catch (error) {
134
- throw new DynamoNTS_Error({
141
+ throw new Dynamo_Error({
135
142
  status: 417,
143
+ errorCode: 'NTS-DS0-GD0',
144
+ addECToUserMsg: true,
136
145
  message: 'getDataByDependencyId was unsuccessful',
137
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-132A`,
146
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
138
147
  error: error
139
148
  });
140
149
  }
@@ -152,25 +161,30 @@ export class DynamoNTS_DataService<T extends Metadata> {
152
161
  this.dataList = data;
153
162
  });
154
163
  } else {
155
- throw new DynamoNTS_Error({
164
+ throw new Dynamo_Error({
156
165
  status: 417,
166
+ errorCode: 'NTS-DS0-GLD3',
167
+ addECToUserMsg: true,
157
168
  message: `${this.depKey} is missing!`,
158
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-133C`,
159
- error: new Error()
169
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
160
170
  });
161
171
  }
162
172
  } else {
163
- throw new DynamoNTS_Error({
173
+ throw new Dynamo_Error({
164
174
  status: 417,
175
+ errorCode: 'NTS-DS0-GLD2',
176
+ addECToUserMsg: true,
165
177
  message: 'dependencyDataIdKey is missing from service!',
166
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-133B`,
167
- error: new Error()
178
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
168
179
  });
169
180
  }
170
181
  } catch (error) {
171
- throw new DynamoNTS_Error({ status: 417,
182
+ throw new Dynamo_Error({
183
+ status: 417,
184
+ errorCode: 'NTS-DS0-GLD0',
185
+ addECToUserMsg: true,
172
186
  message: 'getDataListByDependencyId was unsuccessful',
173
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-133A`,
187
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
174
188
  error: error
175
189
  });
176
190
  }
@@ -198,19 +212,21 @@ export class DynamoNTS_DataService<T extends Metadata> {
198
212
  dependencyExists = !!dep;
199
213
  });
200
214
  if (!dependencyExists) {
201
- throw new DynamoNTS_Error({
215
+ throw new Dynamo_Error({
202
216
  status: 417,
217
+ errorCode: 'NTS-DS0-SD1',
218
+ addECToUserMsg: true,
203
219
  message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
204
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-333A`,
205
- error: new Error()
220
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
206
221
  });
207
222
  }
208
223
  } else {
209
- throw new DynamoNTS_Error({
224
+ throw new Dynamo_Error({
210
225
  status: 417,
226
+ errorCode: 'NTS-DS0-SD2',
227
+ addECToUserMsg: true,
211
228
  message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey})`,
212
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-333B`,
213
- error: new Error()
229
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
214
230
  });
215
231
  }
216
232
  }
@@ -231,10 +247,12 @@ export class DynamoNTS_DataService<T extends Metadata> {
231
247
  });
232
248
  }
233
249
  } catch (error) {
234
- throw new DynamoNTS_Error({
250
+ throw new Dynamo_Error({
235
251
  status: 417,
252
+ errorCode: 'NTS-DS0-SD0',
253
+ addECToUserMsg: true,
236
254
  message: `modifyData was unsuccessful (${this.dataParams.dataName})`,
237
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-222`,
255
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
238
256
  error: error
239
257
  });
240
258
  }
@@ -248,13 +266,15 @@ export class DynamoNTS_DataService<T extends Metadata> {
248
266
  if (this.data._id) {
249
267
  await this.dataDBService.deleteDataById(this.data._id);
250
268
  } else {
251
- throw new DynamoNTS_Error({ status: 417, message: 'ID is missing!' });
269
+ throw new Dynamo_Error({ status: 417, message: 'ID is missing!' });
252
270
  }
253
271
  } catch (error) {
254
- throw new DynamoNTS_Error({
272
+ throw new Dynamo_Error({
255
273
  status: 417,
274
+ errorCode: 'NTS-DS0-DD0',
275
+ addECToUserMsg: true,
256
276
  message: 'deleteData was unsuccessful',
257
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-223`,
277
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
258
278
  error: error
259
279
  });
260
280
  }
@@ -269,16 +289,22 @@ export class DynamoNTS_DataService<T extends Metadata> {
269
289
  // basic required validations
270
290
  if ((this.dataParams.modelParams[i].required && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined)) ||
271
291
  (this.dataParams.modelParams[i].index && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined))) {
272
- throw new DynamoNTS_Error({
292
+ throw new Dynamo_Error({
273
293
  status: 422,
274
- message: `${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.modelParams[i].required ? 'required' : 'index'})`
294
+ errorCode: 'NTS-DS0-VD1',
295
+ addECToUserMsg: true,
296
+ message: `${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.modelParams[i].required ? 'required' : 'index'})`,
297
+ userMessage: `We encountered an unhandled Validation Error, please contact the responsible development team.`
275
298
  });
276
299
  }
277
300
  // specific Date validation
278
301
  if (this.dataParams.modelParams[i].type === 'Date' && !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
279
- throw new DynamoNTS_Error({
302
+ throw new Dynamo_Error({
280
303
  status: 422,
281
- message: `${this.dataParams.modelParams[i].key} is not a date!`
304
+ errorCode: 'NTS-DS0-VD2',
305
+ addECToUserMsg: true,
306
+ message: `${this.dataParams.modelParams[i].key} is not a date!`,
307
+ userMessage: `We encountered an unhandled Validation Error, please contact the responsible development team.`
282
308
  });
283
309
  }
284
310
  // call additional validators
@@ -289,10 +315,12 @@ export class DynamoNTS_DataService<T extends Metadata> {
289
315
  }
290
316
  }
291
317
  } catch (error) {
292
- throw new DynamoNTS_Error({
318
+ throw new Dynamo_Error({
293
319
  status: 422,
320
+ errorCode: 'NTS-DS0-VD0',
321
+ addECToUserMsg: true,
294
322
  message: 'validateForSave was unsuccessful',
295
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-220`,
323
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`,
296
324
  error: error
297
325
  });
298
326
  }
@@ -319,11 +347,12 @@ export class DynamoNTS_DataService<T extends Metadata> {
319
347
  if (this.depDBServiceKey) {
320
348
  return DynamoNTS_GlobalService.getDBService(this.dataParams);
321
349
  } else {
322
- throw new DynamoNTS_Error({
350
+ throw new Dynamo_Error({
323
351
  status: 501,
352
+ errorCode: 'NTS-DS0-GDDB0',
353
+ addECToUserMsg: true,
324
354
  message: 'getDependencyDataDBService was unsuccessful, service key not setted up!',
325
- userMessage: `We encountered a DB Error, please contact the responsible development team. \nerrorCode: 744-234-200`,
326
- error: new Error()
355
+ userMessage: `We encountered an unhandled Data Error, please contact the responsible development team.`
327
356
  });
328
357
  }
329
358
  }