@nsshunt/stsdatamanagement 1.18.200 → 1.18.201
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/dist/cliworker.js +20 -14
- package/dist/cliworker.js.map +1 -1
- package/dist/commonTypes.js.map +1 -1
- package/dist/dalUserManager.js +19 -19
- package/dist/dalUserManager.js.map +1 -1
- package/dist/dalUserManager.test.js +34 -34
- package/dist/dalUserManager.test.js.map +1 -1
- package/dist/databaseutils.js +11 -11
- package/dist/databaseutils.js.map +1 -1
- package/dist/datagenerator.js +77 -67
- package/dist/datagenerator.js.map +1 -1
- package/dist/dbAccessLayerManager.js +2 -2
- package/dist/dbAccessLayerManager.js.map +1 -1
- package/dist/dbaccess.js +7 -7
- package/dist/dbaccess.js.map +1 -1
- package/dist/dbbuild.test.js +41 -46
- package/dist/dbbuild.test.js.map +1 -1
- package/dist/dberrors.js +5 -5
- package/dist/dberrors.js.map +1 -1
- package/dist/pcaccesslayer-entity.test.js +189 -167
- package/dist/pcaccesslayer-entity.test.js.map +1 -1
- package/dist/pcaccesslayer.test.js +186 -164
- package/dist/pcaccesslayer.test.js.map +1 -1
- package/dist/pgaccesslayer-old.js +514 -264
- package/dist/pgaccesslayer-old.js.map +1 -1
- package/dist/pgpoolmanager.js +26 -22
- package/dist/pgpoolmanager.js.map +1 -1
- package/dist/pgutils.js +10 -9
- package/dist/pgutils.js.map +1 -1
- package/dist/setupdb.js +5 -7
- package/dist/setupdb.js.map +1 -1
- package/package.json +16 -15
- package/types/cliworker.d.ts +1 -1
- package/types/cliworker.d.ts.map +1 -1
- package/types/commonTypes.d.ts +3 -3
- package/types/commonTypes.d.ts.map +1 -1
- package/types/dalUserManager.d.ts +1 -1
- package/types/dalUserManager.d.ts.map +1 -1
- package/types/dalUserManager.test.d.ts.map +1 -1
- package/types/databaseutils.d.ts +2 -2
- package/types/databaseutils.d.ts.map +1 -1
- package/types/datagenerator.d.ts +3 -3
- package/types/datagenerator.d.ts.map +1 -1
- package/types/dbAccessLayerManager.d.ts +1 -1
- package/types/dbAccessLayerManager.d.ts.map +1 -1
- package/types/dbaccess.d.ts +7 -7
- package/types/dbaccess.d.ts.map +1 -1
- package/types/dberrors.d.ts +1 -1
- package/types/dberrors.d.ts.map +1 -1
- package/types/pgaccesslayer-old.d.ts +4 -4
- package/types/pgaccesslayer-old.d.ts.map +1 -1
- package/types/pgpoolmanager.d.ts +4 -4
- package/types/pgpoolmanager.d.ts.map +1 -1
- package/types/pgutils.d.ts +1 -1
- package/types/pgutils.d.ts.map +1 -1
- package/types/setupdb.d.ts +1 -1
- package/types/setupdb.d.ts.map +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { StatusCodes } from
|
|
3
|
-
import chalk from
|
|
2
|
+
import { StatusCodes } from "http-status-codes";
|
|
3
|
+
import chalk from "chalk";
|
|
4
4
|
import { Redis } from "ioredis";
|
|
5
|
-
import { goptions } from
|
|
6
|
-
import pgcopystreams from
|
|
5
|
+
import { goptions } from "@nsshunt/stsconfig";
|
|
6
|
+
import pgcopystreams from "pg-copy-streams";
|
|
7
7
|
const copyFrom = pgcopystreams.from;
|
|
8
|
-
import * as streamex from
|
|
9
|
-
import * as fs from
|
|
10
|
-
const defaultConfigId =
|
|
11
|
-
const systemUserId =
|
|
8
|
+
import * as streamex from "node:stream";
|
|
9
|
+
import * as fs from "node:fs/promises";
|
|
10
|
+
const defaultConfigId = "defaultconfig";
|
|
11
|
+
const systemUserId = "SystemUserID";
|
|
12
12
|
export class PGAccessLayer {
|
|
13
13
|
#options;
|
|
14
14
|
#ioredisCache = null;
|
|
@@ -20,7 +20,7 @@ export class PGAccessLayer {
|
|
|
20
20
|
if (useRedisDatabaseCache === true) {
|
|
21
21
|
const redisOptions = {
|
|
22
22
|
showFriendlyErrorStack: true,
|
|
23
|
-
maxRetriesPerRequest: 20
|
|
23
|
+
maxRetriesPerRequest: 20,
|
|
24
24
|
};
|
|
25
25
|
this.#ioredisCache = new Redis(redisDatabaseCacheUrl, redisOptions);
|
|
26
26
|
}
|
|
@@ -33,73 +33,80 @@ export class PGAccessLayer {
|
|
|
33
33
|
}
|
|
34
34
|
#latestResourceVersion(inputfilter) {
|
|
35
35
|
// Check if we are getting the latest version
|
|
36
|
-
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser } = inputfilter;
|
|
37
|
-
return (resname !== undefined &&
|
|
38
|
-
|
|
36
|
+
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser, } = inputfilter;
|
|
37
|
+
return (resname !== undefined &&
|
|
38
|
+
entname === undefined &&
|
|
39
|
+
vnum === undefined &&
|
|
40
|
+
filter === undefined &&
|
|
41
|
+
incdel === undefined &&
|
|
42
|
+
startdate === undefined &&
|
|
43
|
+
enddate === undefined &&
|
|
44
|
+
dbaction === undefined &&
|
|
45
|
+
dbactionuser === undefined);
|
|
39
46
|
}
|
|
40
47
|
#buildQueryString(filters, restype) {
|
|
41
|
-
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser } = filters;
|
|
48
|
+
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser, } = filters;
|
|
42
49
|
// Build query string
|
|
43
50
|
const qparams = [];
|
|
44
|
-
let qstring =
|
|
45
|
-
let sep =
|
|
51
|
+
let qstring = " where ";
|
|
52
|
+
let sep = "";
|
|
46
53
|
let qnum = 0;
|
|
47
54
|
if (resname !== undefined) {
|
|
48
55
|
qparams.push(resname);
|
|
49
|
-
qstring += sep +
|
|
50
|
-
sep =
|
|
56
|
+
qstring += sep + "r.resname = $" + ++qnum;
|
|
57
|
+
sep = " and ";
|
|
51
58
|
}
|
|
52
59
|
if (entname !== undefined) {
|
|
53
60
|
qparams.push(entname);
|
|
54
|
-
qstring += sep +
|
|
55
|
-
sep =
|
|
61
|
+
qstring += sep + "e.entname = $" + ++qnum;
|
|
62
|
+
sep = " and ";
|
|
56
63
|
}
|
|
57
64
|
if (vnum !== undefined) {
|
|
58
65
|
qparams.push(vnum);
|
|
59
|
-
qstring += sep + restype +
|
|
60
|
-
sep =
|
|
66
|
+
qstring += sep + restype + ".vnum = $" + ++qnum;
|
|
67
|
+
sep = " and ";
|
|
61
68
|
}
|
|
62
69
|
else {
|
|
63
70
|
// Only get current version provided enddate is not specified
|
|
64
71
|
if (enddate === undefined) {
|
|
65
|
-
qstring += sep + restype +
|
|
66
|
-
sep =
|
|
72
|
+
qstring += sep + restype + ".validto is null";
|
|
73
|
+
sep = " and ";
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
if (filter !== undefined) {
|
|
70
77
|
qparams.push(filter);
|
|
71
|
-
if (restype ===
|
|
72
|
-
qstring += sep + restype +
|
|
78
|
+
if (restype === "r") {
|
|
79
|
+
qstring += sep + restype + ".resname like $" + ++qnum;
|
|
73
80
|
}
|
|
74
81
|
else {
|
|
75
|
-
qstring += sep + restype +
|
|
82
|
+
qstring += sep + restype + ".entname like $" + ++qnum;
|
|
76
83
|
}
|
|
77
|
-
sep =
|
|
84
|
+
sep = " and ";
|
|
78
85
|
}
|
|
79
86
|
if (startdate !== undefined) {
|
|
80
87
|
qparams.push(startdate);
|
|
81
|
-
qstring += sep + restype +
|
|
82
|
-
sep =
|
|
88
|
+
qstring += sep + restype + ".validfrom >= $" + ++qnum;
|
|
89
|
+
sep = " and ";
|
|
83
90
|
}
|
|
84
91
|
if (enddate !== undefined) {
|
|
85
92
|
qparams.push(enddate);
|
|
86
|
-
qstring += sep + restype +
|
|
87
|
-
sep =
|
|
93
|
+
qstring += sep + restype + ".validto <= $" + ++qnum;
|
|
94
|
+
sep = " and ";
|
|
88
95
|
}
|
|
89
|
-
if (incdel === undefined || incdel.toLowerCase() ===
|
|
96
|
+
if (incdel === undefined || incdel.toLowerCase() === "n") {
|
|
90
97
|
qparams.push(3);
|
|
91
|
-
qstring += sep + restype +
|
|
92
|
-
sep =
|
|
98
|
+
qstring += sep + restype + ".dbaction != $" + ++qnum;
|
|
99
|
+
sep = " and ";
|
|
93
100
|
}
|
|
94
101
|
if (dbaction !== undefined) {
|
|
95
102
|
qparams.push(dbaction);
|
|
96
|
-
qstring += sep + restype +
|
|
97
|
-
sep =
|
|
103
|
+
qstring += sep + restype + ".dbaction = $" + ++qnum;
|
|
104
|
+
sep = " and ";
|
|
98
105
|
}
|
|
99
106
|
if (dbactionuser !== undefined) {
|
|
100
107
|
qparams.push(dbactionuser);
|
|
101
|
-
qstring += sep + restype +
|
|
102
|
-
sep =
|
|
108
|
+
qstring += sep + restype + ".dbactionuser = $" + ++qnum;
|
|
109
|
+
sep = " and ";
|
|
103
110
|
}
|
|
104
111
|
if (qnum === 0) {
|
|
105
112
|
return null;
|
|
@@ -141,20 +148,24 @@ export class PGAccessLayer {
|
|
|
141
148
|
await this.saveResource(systemUserId, defaultConfigId, config);
|
|
142
149
|
}
|
|
143
150
|
async getResourceCount(filter = null) {
|
|
144
|
-
const fname =
|
|
151
|
+
const fname = "getResourceCount";
|
|
145
152
|
try {
|
|
146
153
|
let createQuery = `select count(*) from stsresource r`;
|
|
147
154
|
if (filter !== null) {
|
|
148
|
-
createQuery +=
|
|
155
|
+
createQuery += " where " + filter;
|
|
149
156
|
}
|
|
150
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
157
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
151
158
|
try {
|
|
152
159
|
const { rows } = await client.query(createQuery);
|
|
153
160
|
const dbResponse = rows[0];
|
|
154
161
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
155
162
|
}
|
|
156
163
|
catch (error) {
|
|
157
|
-
return {
|
|
164
|
+
return {
|
|
165
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
166
|
+
error: `[${fname}]: Operation was not successful`,
|
|
167
|
+
detail: error,
|
|
168
|
+
}; // Set default
|
|
158
169
|
}
|
|
159
170
|
finally {
|
|
160
171
|
client.release();
|
|
@@ -163,32 +174,40 @@ export class PGAccessLayer {
|
|
|
163
174
|
catch (error) {
|
|
164
175
|
// Error getting the client connection from the pool
|
|
165
176
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
166
|
-
return {
|
|
177
|
+
return {
|
|
178
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
179
|
+
error: `[${fname}]: Operation was not successful`,
|
|
180
|
+
detail: error,
|
|
181
|
+
};
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
async createResource(userid, resourceid, payload) {
|
|
170
|
-
const fname =
|
|
185
|
+
const fname = "createResource";
|
|
171
186
|
try {
|
|
172
187
|
let createQuery = null;
|
|
173
188
|
createQuery = `select * from create_stsresource($1, $2, $3)`;
|
|
174
|
-
const values = [
|
|
175
|
-
|
|
176
|
-
resourceid,
|
|
177
|
-
payload
|
|
178
|
-
];
|
|
179
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
189
|
+
const values = [userid, resourceid, payload];
|
|
190
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
180
191
|
try {
|
|
181
|
-
await client.query(
|
|
192
|
+
await client.query("BEGIN");
|
|
182
193
|
const { rows } = await client.query(createQuery, values);
|
|
183
194
|
const dbResponse = rows[0];
|
|
184
|
-
await client.query(
|
|
195
|
+
await client.query("COMMIT");
|
|
185
196
|
return { status: StatusCodes.CREATED, detail: dbResponse };
|
|
186
197
|
}
|
|
187
198
|
catch (error) {
|
|
188
|
-
await client.query(
|
|
189
|
-
let err = {
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
await client.query("ROLLBACK");
|
|
200
|
+
let err = {
|
|
201
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
202
|
+
error: `[${fname}]: Operation was not successful`,
|
|
203
|
+
detail: error,
|
|
204
|
+
}; // Set default
|
|
205
|
+
if (error.code === "23505") {
|
|
206
|
+
err = {
|
|
207
|
+
status: StatusCodes.CONFLICT,
|
|
208
|
+
error: `[${fname}: resourceid [${resourceid}] already exists`,
|
|
209
|
+
detail: error,
|
|
210
|
+
};
|
|
192
211
|
}
|
|
193
212
|
this.#LogDebugMessage(chalk.red(`Error: ${JSON.stringify(error)}`));
|
|
194
213
|
return err;
|
|
@@ -200,68 +219,81 @@ export class PGAccessLayer {
|
|
|
200
219
|
catch (error) {
|
|
201
220
|
// Error getting the client connection from the pool
|
|
202
221
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
203
|
-
return {
|
|
222
|
+
return {
|
|
223
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
224
|
+
error: `[${fname}]: Operation was not successful`,
|
|
225
|
+
detail: error,
|
|
226
|
+
};
|
|
204
227
|
}
|
|
205
228
|
}
|
|
206
229
|
async beginX(readOnly) {
|
|
207
|
-
const fname =
|
|
230
|
+
const fname = "beginX";
|
|
208
231
|
try {
|
|
209
232
|
let client;
|
|
210
233
|
if (readOnly) {
|
|
211
|
-
client =
|
|
234
|
+
client =
|
|
235
|
+
(await this.#poolManager?.connectReadOnly());
|
|
212
236
|
}
|
|
213
237
|
else {
|
|
214
|
-
client =
|
|
238
|
+
client =
|
|
239
|
+
(await this.#poolManager?.connectReadWrite());
|
|
215
240
|
}
|
|
216
|
-
await client.query(
|
|
241
|
+
await client.query("BEGIN");
|
|
217
242
|
return client;
|
|
218
243
|
}
|
|
219
244
|
catch (error) {
|
|
220
245
|
// Error getting the client connection from the pool
|
|
221
246
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
222
|
-
return {
|
|
247
|
+
return {
|
|
248
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
249
|
+
error: `[${fname}]: Operation was not successful`,
|
|
250
|
+
detail: error,
|
|
251
|
+
};
|
|
223
252
|
}
|
|
224
253
|
}
|
|
225
254
|
async commitX(client) {
|
|
226
|
-
const fname =
|
|
255
|
+
const fname = "commitX";
|
|
227
256
|
try {
|
|
228
|
-
await client.query(
|
|
257
|
+
await client.query("COMMIT");
|
|
229
258
|
client.release();
|
|
230
259
|
}
|
|
231
260
|
catch (error) {
|
|
232
261
|
// Error getting the client connection from the pool
|
|
233
262
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
234
|
-
return {
|
|
263
|
+
return {
|
|
264
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
265
|
+
error: `[${fname}]: Operation was not successful`,
|
|
266
|
+
detail: error,
|
|
267
|
+
};
|
|
235
268
|
}
|
|
236
269
|
}
|
|
237
270
|
async rollbackX(client) {
|
|
238
|
-
const fname =
|
|
271
|
+
const fname = "rollbackX";
|
|
239
272
|
try {
|
|
240
|
-
await client.query(
|
|
273
|
+
await client.query("ROLLBACK");
|
|
241
274
|
client.release();
|
|
242
275
|
}
|
|
243
276
|
catch (error) {
|
|
244
277
|
// Error getting the client connection from the pool
|
|
245
278
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
246
|
-
return {
|
|
279
|
+
return {
|
|
280
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
281
|
+
error: `[${fname}]: Operation was not successful`,
|
|
282
|
+
detail: error,
|
|
283
|
+
};
|
|
247
284
|
}
|
|
248
285
|
}
|
|
249
286
|
async updateResource(userid, resourceid, resourcevnum, payload) {
|
|
250
|
-
const fname =
|
|
287
|
+
const fname = "updateResource";
|
|
251
288
|
try {
|
|
252
289
|
const createQuery = `select * from update_stsresource($1, $2, $3, $4)`;
|
|
253
|
-
const values = [
|
|
254
|
-
|
|
255
|
-
resourceid,
|
|
256
|
-
resourcevnum,
|
|
257
|
-
payload
|
|
258
|
-
];
|
|
259
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
290
|
+
const values = [userid, resourceid, resourcevnum, payload];
|
|
291
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
260
292
|
try {
|
|
261
|
-
await client.query(
|
|
293
|
+
await client.query("BEGIN");
|
|
262
294
|
const { rows } = await client.query(createQuery, values);
|
|
263
295
|
const dbResponse = rows[0];
|
|
264
|
-
await client.query(
|
|
296
|
+
await client.query("COMMIT");
|
|
265
297
|
// Now remove this resource from the cache. Currently this does an unconditional remove without checking if updating current version
|
|
266
298
|
// and a race condition exists in that the database transaction is seperate from the cache update.
|
|
267
299
|
if (this.#ioredisCache !== null) {
|
|
@@ -270,10 +302,18 @@ export class PGAccessLayer {
|
|
|
270
302
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
271
303
|
}
|
|
272
304
|
catch (error) {
|
|
273
|
-
await client.query(
|
|
274
|
-
let err = {
|
|
275
|
-
|
|
276
|
-
|
|
305
|
+
await client.query("ROLLBACK");
|
|
306
|
+
let err = {
|
|
307
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
308
|
+
error: `[${fname}]: Operation was not successful`,
|
|
309
|
+
detail: error,
|
|
310
|
+
}; // Set default
|
|
311
|
+
if (error.code === "P0002") {
|
|
312
|
+
err = {
|
|
313
|
+
status: StatusCodes.NOT_FOUND,
|
|
314
|
+
error: `[${fname}: resourceid [${resourceid}] and version [${resourcevnum}] not found or not current`,
|
|
315
|
+
detail: error,
|
|
316
|
+
};
|
|
277
317
|
}
|
|
278
318
|
this.#LogDebugMessage(chalk.red(`updateResource(): Error: [${JSON.stringify(err)}]`));
|
|
279
319
|
return err;
|
|
@@ -285,14 +325,22 @@ export class PGAccessLayer {
|
|
|
285
325
|
catch (error) {
|
|
286
326
|
// Error getting the client connection from the pool
|
|
287
327
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
288
|
-
return {
|
|
328
|
+
return {
|
|
329
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
330
|
+
error: `[${fname}]: Operation was not successful`,
|
|
331
|
+
detail: error,
|
|
332
|
+
};
|
|
289
333
|
}
|
|
290
334
|
}
|
|
291
335
|
async deleteLatestResource(userid, resid) {
|
|
292
|
-
const fname =
|
|
336
|
+
const fname = "deleteLatestResource";
|
|
293
337
|
const retVal = await this.getLatestResource(resid, false);
|
|
294
338
|
if (retVal.status !== StatusCodes.OK) {
|
|
295
|
-
return {
|
|
339
|
+
return {
|
|
340
|
+
status: retVal.status,
|
|
341
|
+
error: `[${fname}]: Operation was not successful: [${resid}]`,
|
|
342
|
+
detail: retVal,
|
|
343
|
+
};
|
|
296
344
|
}
|
|
297
345
|
else {
|
|
298
346
|
const vnum = retVal.detail.vnum;
|
|
@@ -300,20 +348,16 @@ export class PGAccessLayer {
|
|
|
300
348
|
}
|
|
301
349
|
}
|
|
302
350
|
async deleteResource(userid, resourceid, resourcevnum) {
|
|
303
|
-
const fname =
|
|
351
|
+
const fname = "deleteResource";
|
|
304
352
|
try {
|
|
305
353
|
const createQuery = `select * from delete_stsresource($1, $2, $3)`;
|
|
306
|
-
const values = [
|
|
307
|
-
|
|
308
|
-
resourceid,
|
|
309
|
-
resourcevnum
|
|
310
|
-
];
|
|
311
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
354
|
+
const values = [userid, resourceid, resourcevnum];
|
|
355
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
312
356
|
try {
|
|
313
|
-
await client.query(
|
|
357
|
+
await client.query("BEGIN");
|
|
314
358
|
const { rows } = await client.query(createQuery, values);
|
|
315
359
|
const dbResponse = rows[0];
|
|
316
|
-
await client.query(
|
|
360
|
+
await client.query("COMMIT");
|
|
317
361
|
// Now remove this resource from the cache. Currently this does an unconditional remove without checking if updating current version
|
|
318
362
|
// and a race condition exists in that the database transaction is seperate from the cache update.
|
|
319
363
|
if (this.#ioredisCache !== null) {
|
|
@@ -322,10 +366,18 @@ export class PGAccessLayer {
|
|
|
322
366
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
323
367
|
}
|
|
324
368
|
catch (error) {
|
|
325
|
-
await client.query(
|
|
326
|
-
let err = {
|
|
327
|
-
|
|
328
|
-
|
|
369
|
+
await client.query("ROLLBACK");
|
|
370
|
+
let err = {
|
|
371
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
372
|
+
error: `[${fname}]: Operation was not successful`,
|
|
373
|
+
detail: error,
|
|
374
|
+
}; // Set default
|
|
375
|
+
if (error.code === "P0002") {
|
|
376
|
+
err = {
|
|
377
|
+
status: StatusCodes.NOT_FOUND,
|
|
378
|
+
error: `[${fname}: resourceid [${resourceid}] and version [${resourcevnum}] not found or not current`,
|
|
379
|
+
detail: error,
|
|
380
|
+
};
|
|
329
381
|
}
|
|
330
382
|
this.#LogDebugMessage(chalk.red(`deleteResource(): Error: [${JSON.stringify(err)}]`));
|
|
331
383
|
return err;
|
|
@@ -337,11 +389,15 @@ export class PGAccessLayer {
|
|
|
337
389
|
catch (error) {
|
|
338
390
|
// Error getting the client connection from the pool
|
|
339
391
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
340
|
-
return {
|
|
392
|
+
return {
|
|
393
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
394
|
+
error: `[${fname}]: Operation was not successful`,
|
|
395
|
+
detail: error,
|
|
396
|
+
};
|
|
341
397
|
}
|
|
342
398
|
}
|
|
343
399
|
async createEntity(userid, resourceid, resourcevnum, entityid, payload) {
|
|
344
|
-
const fname =
|
|
400
|
+
const fname = "createEntity";
|
|
345
401
|
try {
|
|
346
402
|
const createQuery = `select * from create_stsentity($1, $2, $3, $4, $5)`;
|
|
347
403
|
const values = [
|
|
@@ -349,21 +405,29 @@ export class PGAccessLayer {
|
|
|
349
405
|
resourceid,
|
|
350
406
|
resourcevnum,
|
|
351
407
|
entityid,
|
|
352
|
-
payload
|
|
408
|
+
payload,
|
|
353
409
|
];
|
|
354
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
410
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
355
411
|
try {
|
|
356
|
-
await client.query(
|
|
412
|
+
await client.query("BEGIN");
|
|
357
413
|
const { rows } = await client.query(createQuery, values);
|
|
358
414
|
const dbResponse = rows[0];
|
|
359
|
-
await client.query(
|
|
415
|
+
await client.query("COMMIT");
|
|
360
416
|
return { status: StatusCodes.CREATED, detail: dbResponse };
|
|
361
417
|
}
|
|
362
418
|
catch (error) {
|
|
363
|
-
await client.query(
|
|
364
|
-
let err = {
|
|
365
|
-
|
|
366
|
-
|
|
419
|
+
await client.query("ROLLBACK");
|
|
420
|
+
let err = {
|
|
421
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
422
|
+
error: `[${fname}]: Operation was not successful`,
|
|
423
|
+
detail: error,
|
|
424
|
+
}; // Set default
|
|
425
|
+
if (error.code === "23505") {
|
|
426
|
+
err = {
|
|
427
|
+
status: StatusCodes.CONFLICT,
|
|
428
|
+
error: `[${fname}: entityid [${entityid}] already exists`,
|
|
429
|
+
detail: error,
|
|
430
|
+
};
|
|
367
431
|
}
|
|
368
432
|
this.#LogDebugMessage(chalk.red(`createEntity(): Error: [${JSON.stringify(err)}]`));
|
|
369
433
|
return err;
|
|
@@ -375,11 +439,15 @@ export class PGAccessLayer {
|
|
|
375
439
|
catch (error) {
|
|
376
440
|
// Error getting the client connection from the pool
|
|
377
441
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
378
|
-
return {
|
|
442
|
+
return {
|
|
443
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
444
|
+
error: `[${fname}]: Operation was not successful`,
|
|
445
|
+
detail: error,
|
|
446
|
+
};
|
|
379
447
|
}
|
|
380
448
|
}
|
|
381
449
|
async createEntityEx(userid, resourceid, resourcevnum, entityid, entity) {
|
|
382
|
-
const fname =
|
|
450
|
+
const fname = "createEntity";
|
|
383
451
|
try {
|
|
384
452
|
const createQuery = `select * from create_stsentity($1, $2, $3, $4, $5)`;
|
|
385
453
|
const values = [
|
|
@@ -387,21 +455,29 @@ export class PGAccessLayer {
|
|
|
387
455
|
resourceid,
|
|
388
456
|
resourcevnum,
|
|
389
457
|
entityid,
|
|
390
|
-
JSON.stringify(entity)
|
|
458
|
+
JSON.stringify(entity),
|
|
391
459
|
];
|
|
392
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
460
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
393
461
|
try {
|
|
394
|
-
await client.query(
|
|
395
|
-
const { rows } =
|
|
462
|
+
await client.query("BEGIN");
|
|
463
|
+
const { rows } = await client.query(createQuery, values);
|
|
396
464
|
const dbResponse = rows[0];
|
|
397
|
-
await client.query(
|
|
465
|
+
await client.query("COMMIT");
|
|
398
466
|
return { status: StatusCodes.CREATED, detail: dbResponse };
|
|
399
467
|
}
|
|
400
468
|
catch (error) {
|
|
401
|
-
await client.query(
|
|
402
|
-
let err = {
|
|
403
|
-
|
|
404
|
-
|
|
469
|
+
await client.query("ROLLBACK");
|
|
470
|
+
let err = {
|
|
471
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
472
|
+
error: `[${fname}]: Operation was not successful`,
|
|
473
|
+
detail: error,
|
|
474
|
+
}; // Set default
|
|
475
|
+
if (error.code === "23505") {
|
|
476
|
+
err = {
|
|
477
|
+
status: StatusCodes.CONFLICT,
|
|
478
|
+
error: `[${fname}: entityid [${entityid}] already exists`,
|
|
479
|
+
detail: error,
|
|
480
|
+
};
|
|
405
481
|
}
|
|
406
482
|
this.#LogDebugMessage(chalk.red(`createEntity(): Error: [${JSON.stringify(err)}]`));
|
|
407
483
|
return err;
|
|
@@ -413,11 +489,15 @@ export class PGAccessLayer {
|
|
|
413
489
|
catch (error) {
|
|
414
490
|
// Error getting the client connection from the pool
|
|
415
491
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
416
|
-
return {
|
|
492
|
+
return {
|
|
493
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
494
|
+
error: `[${fname}]: Operation was not successful`,
|
|
495
|
+
detail: error,
|
|
496
|
+
};
|
|
417
497
|
}
|
|
418
498
|
}
|
|
419
499
|
async updateEntity(userid, resourceid, resourcevnum, entityid, entityvnum, payload) {
|
|
420
|
-
const fname =
|
|
500
|
+
const fname = "updateEntity";
|
|
421
501
|
try {
|
|
422
502
|
const createQuery = `select * from update_stsentity($1, $2, $3, $4, $5, $6)`;
|
|
423
503
|
const values = [
|
|
@@ -426,21 +506,29 @@ export class PGAccessLayer {
|
|
|
426
506
|
resourcevnum,
|
|
427
507
|
entityid,
|
|
428
508
|
entityvnum,
|
|
429
|
-
payload
|
|
509
|
+
payload,
|
|
430
510
|
];
|
|
431
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
511
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
432
512
|
try {
|
|
433
|
-
await client.query(
|
|
513
|
+
await client.query("BEGIN");
|
|
434
514
|
const { rows } = await client.query(createQuery, values);
|
|
435
515
|
const dbResponse = rows[0];
|
|
436
|
-
await client.query(
|
|
516
|
+
await client.query("COMMIT");
|
|
437
517
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
438
518
|
}
|
|
439
519
|
catch (error) {
|
|
440
|
-
await client.query(
|
|
441
|
-
let err = {
|
|
442
|
-
|
|
443
|
-
|
|
520
|
+
await client.query("ROLLBACK");
|
|
521
|
+
let err = {
|
|
522
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
523
|
+
error: `[${fname}]: Operation was not successful`,
|
|
524
|
+
detail: error,
|
|
525
|
+
}; // Set default
|
|
526
|
+
if (error.code === "P0002") {
|
|
527
|
+
err = {
|
|
528
|
+
status: StatusCodes.NOT_FOUND,
|
|
529
|
+
error: `[${fname}: resourceid [${resourceid}:${resourcevnum}], entityid [${entityid}:${entityvnum}] not found or not current`,
|
|
530
|
+
detail: error,
|
|
531
|
+
};
|
|
444
532
|
}
|
|
445
533
|
this.#LogDebugMessage(chalk.red(`updateEntity(): Error: [${JSON.stringify(err)}]`));
|
|
446
534
|
return err;
|
|
@@ -452,11 +540,15 @@ export class PGAccessLayer {
|
|
|
452
540
|
catch (error) {
|
|
453
541
|
// Error getting the client connection from the pool
|
|
454
542
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
455
|
-
return {
|
|
543
|
+
return {
|
|
544
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
545
|
+
error: `[${fname}]: Operation was not successful`,
|
|
546
|
+
detail: error,
|
|
547
|
+
};
|
|
456
548
|
}
|
|
457
549
|
}
|
|
458
550
|
async deleteEntity(userid, resourceid, resourcevnum, entityid, entityvnum) {
|
|
459
|
-
const fname =
|
|
551
|
+
const fname = "deleteEntity";
|
|
460
552
|
try {
|
|
461
553
|
const createQuery = `select * from delete_stsentity($1, $2, $3, $4, $5)`;
|
|
462
554
|
const values = [
|
|
@@ -464,21 +556,29 @@ export class PGAccessLayer {
|
|
|
464
556
|
resourceid,
|
|
465
557
|
resourcevnum,
|
|
466
558
|
entityid,
|
|
467
|
-
entityvnum
|
|
559
|
+
entityvnum,
|
|
468
560
|
];
|
|
469
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
561
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
470
562
|
try {
|
|
471
|
-
await client.query(
|
|
563
|
+
await client.query("BEGIN");
|
|
472
564
|
const { rows } = await client.query(createQuery, values);
|
|
473
565
|
const dbResponse = rows[0];
|
|
474
|
-
await client.query(
|
|
566
|
+
await client.query("COMMIT");
|
|
475
567
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
476
568
|
}
|
|
477
569
|
catch (error) {
|
|
478
|
-
await client.query(
|
|
479
|
-
let err = {
|
|
480
|
-
|
|
481
|
-
|
|
570
|
+
await client.query("ROLLBACK");
|
|
571
|
+
let err = {
|
|
572
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
573
|
+
error: `[${fname}]: Operation was not successful`,
|
|
574
|
+
detail: error,
|
|
575
|
+
}; // Set default
|
|
576
|
+
if (error.code === "P0002") {
|
|
577
|
+
err = {
|
|
578
|
+
status: StatusCodes.NOT_FOUND,
|
|
579
|
+
error: `[${fname}: resourceid [${resourceid}:${resourcevnum}], entityid [${entityid}:${entityvnum}] not found or not current`,
|
|
580
|
+
detail: error,
|
|
581
|
+
};
|
|
482
582
|
}
|
|
483
583
|
this.#LogDebugMessage(chalk.red(`deleteEntity(): Error: [${JSON.stringify(err)}]`));
|
|
484
584
|
return err;
|
|
@@ -490,17 +590,21 @@ export class PGAccessLayer {
|
|
|
490
590
|
catch (error) {
|
|
491
591
|
// Error getting the client connection from the pool
|
|
492
592
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
493
|
-
return {
|
|
593
|
+
return {
|
|
594
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
595
|
+
error: `[${fname}]: Operation was not successful`,
|
|
596
|
+
detail: error,
|
|
597
|
+
};
|
|
494
598
|
}
|
|
495
599
|
}
|
|
496
600
|
// get single resource and all associated entities for this resource
|
|
497
601
|
async getResource(filters, useCache, usemultipledatabases = false) {
|
|
498
|
-
const fname =
|
|
602
|
+
const fname = "getResource";
|
|
499
603
|
try {
|
|
500
|
-
let query =
|
|
604
|
+
let query = "select r.oid::bigint, r.resname, r.resdesc, r.vnum::bigint, r.validfrom, r.validto, r.dbaction, r.dbactionuser from stsresource r";
|
|
501
605
|
let values = [];
|
|
502
606
|
const resourceid = filters.resname;
|
|
503
|
-
const qs = this.#buildQueryString(filters,
|
|
607
|
+
const qs = this.#buildQueryString(filters, "r");
|
|
504
608
|
if (qs !== null) {
|
|
505
609
|
query += qs.qstring;
|
|
506
610
|
values = qs.qparams;
|
|
@@ -510,34 +614,56 @@ export class PGAccessLayer {
|
|
|
510
614
|
const cacheVal = await this.#ioredisCache.get(resourceid);
|
|
511
615
|
if (cacheVal !== null) {
|
|
512
616
|
const cacheResponse = JSON.parse(cacheVal);
|
|
513
|
-
return {
|
|
617
|
+
return {
|
|
618
|
+
status: StatusCodes.OK,
|
|
619
|
+
usedcache: true,
|
|
620
|
+
detail: cacheResponse,
|
|
621
|
+
};
|
|
514
622
|
}
|
|
515
623
|
}
|
|
516
624
|
}
|
|
517
625
|
query += " limit 2";
|
|
518
626
|
let client;
|
|
519
627
|
if (usemultipledatabases) {
|
|
520
|
-
client =
|
|
628
|
+
client =
|
|
629
|
+
(await this.#poolManager?.connectReadOnly());
|
|
521
630
|
}
|
|
522
631
|
else {
|
|
523
|
-
client =
|
|
632
|
+
client =
|
|
633
|
+
(await this.#poolManager?.connectReadWrite());
|
|
524
634
|
}
|
|
525
635
|
try {
|
|
526
636
|
const { rows } = await client.query(query, values);
|
|
527
637
|
if (rows.length === 0) {
|
|
528
|
-
return {
|
|
638
|
+
return {
|
|
639
|
+
status: StatusCodes.NOT_FOUND,
|
|
640
|
+
error: `[${fname}: resourceid [${resourceid}] (current version) not found`,
|
|
641
|
+
detail: null,
|
|
642
|
+
};
|
|
529
643
|
}
|
|
530
644
|
if (rows.length > 1) {
|
|
531
|
-
return {
|
|
645
|
+
return {
|
|
646
|
+
status: StatusCodes.NOT_FOUND,
|
|
647
|
+
error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`,
|
|
648
|
+
detail: null,
|
|
649
|
+
};
|
|
532
650
|
}
|
|
533
651
|
const dbResponse = rows[0];
|
|
534
652
|
if (this.#ioredisCache !== null) {
|
|
535
653
|
this.#ioredisCache.set(resourceid, JSON.stringify(dbResponse));
|
|
536
654
|
}
|
|
537
|
-
return {
|
|
655
|
+
return {
|
|
656
|
+
status: StatusCodes.OK,
|
|
657
|
+
usedcache: false,
|
|
658
|
+
detail: dbResponse,
|
|
659
|
+
};
|
|
538
660
|
}
|
|
539
661
|
catch (error) {
|
|
540
|
-
return {
|
|
662
|
+
return {
|
|
663
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
664
|
+
error: `[${fname}]: Operation was not successful`,
|
|
665
|
+
detail: error,
|
|
666
|
+
}; // Set default;
|
|
541
667
|
}
|
|
542
668
|
finally {
|
|
543
669
|
client.release();
|
|
@@ -546,17 +672,21 @@ export class PGAccessLayer {
|
|
|
546
672
|
catch (error) {
|
|
547
673
|
// Error getting the client connection from the pool
|
|
548
674
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
549
|
-
return {
|
|
675
|
+
return {
|
|
676
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
677
|
+
error: `[${fname}]: Operation was not successful`,
|
|
678
|
+
detail: error,
|
|
679
|
+
};
|
|
550
680
|
}
|
|
551
681
|
}
|
|
552
682
|
// get single resource and all associated entities for this resource
|
|
553
683
|
async getResourceEx(filters) {
|
|
554
|
-
const fname =
|
|
684
|
+
const fname = "getResource";
|
|
555
685
|
try {
|
|
556
|
-
let query =
|
|
686
|
+
let query = "select r.oid::bigint, r.resname, r.resdesc, r.vnum::bigint, r.validfrom, r.validto, r.dbaction, r.dbactionuser from stsresource r";
|
|
557
687
|
let values = [];
|
|
558
688
|
const resourceid = filters.resname;
|
|
559
|
-
const qs = this.#buildQueryString(filters,
|
|
689
|
+
const qs = this.#buildQueryString(filters, "r");
|
|
560
690
|
if (qs !== null) {
|
|
561
691
|
query += qs.qstring;
|
|
562
692
|
values = qs.qparams;
|
|
@@ -572,28 +702,28 @@ export class PGAccessLayer {
|
|
|
572
702
|
// sts parsed values
|
|
573
703
|
status: StatusCodes.OK,
|
|
574
704
|
usedcache: true,
|
|
575
|
-
detail: JSON.parse(cacheedResponse.resdesc)
|
|
705
|
+
detail: JSON.parse(cacheedResponse.resdesc),
|
|
576
706
|
};
|
|
577
707
|
return retVal;
|
|
578
708
|
}
|
|
579
709
|
}
|
|
580
710
|
}
|
|
581
711
|
query += " limit 2";
|
|
582
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
712
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
583
713
|
try {
|
|
584
714
|
const { rows } = await client.query(query, values);
|
|
585
715
|
if (rows.length === 0) {
|
|
586
716
|
return {
|
|
587
717
|
status: StatusCodes.NOT_FOUND,
|
|
588
718
|
error: `[${fname}: resourceid [${resourceid}] (current version) not found`,
|
|
589
|
-
usedcache: false
|
|
719
|
+
usedcache: false,
|
|
590
720
|
};
|
|
591
721
|
}
|
|
592
722
|
if (rows.length > 1) {
|
|
593
723
|
return {
|
|
594
724
|
status: StatusCodes.NOT_FOUND,
|
|
595
725
|
error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`,
|
|
596
|
-
usedcache: false
|
|
726
|
+
usedcache: false,
|
|
597
727
|
};
|
|
598
728
|
}
|
|
599
729
|
const dbResponse = rows[0];
|
|
@@ -608,7 +738,7 @@ export class PGAccessLayer {
|
|
|
608
738
|
// sts parsed values
|
|
609
739
|
status: StatusCodes.OK,
|
|
610
740
|
usedcache: false,
|
|
611
|
-
detail: parsedDetail
|
|
741
|
+
detail: parsedDetail,
|
|
612
742
|
};
|
|
613
743
|
}
|
|
614
744
|
catch (error) {
|
|
@@ -618,7 +748,7 @@ export class PGAccessLayer {
|
|
|
618
748
|
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
619
749
|
sourceError: error,
|
|
620
750
|
error: `[${fname}]: Operation was not successful - Could not JSON.parse(dbResponse.resdesc).`,
|
|
621
|
-
usedcache: false
|
|
751
|
+
usedcache: false,
|
|
622
752
|
};
|
|
623
753
|
}
|
|
624
754
|
}
|
|
@@ -627,7 +757,7 @@ export class PGAccessLayer {
|
|
|
627
757
|
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
628
758
|
sourceError: error,
|
|
629
759
|
error: `[${fname}]: Operation was not successful.`,
|
|
630
|
-
usedcache: false
|
|
760
|
+
usedcache: false,
|
|
631
761
|
};
|
|
632
762
|
}
|
|
633
763
|
finally {
|
|
@@ -641,17 +771,17 @@ export class PGAccessLayer {
|
|
|
641
771
|
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
642
772
|
sourceError: error,
|
|
643
773
|
error: `[${fname}]: Operation was not successful - Fallback.`,
|
|
644
|
-
usedcache: false
|
|
774
|
+
usedcache: false,
|
|
645
775
|
};
|
|
646
776
|
}
|
|
647
777
|
}
|
|
648
778
|
// get single resource and all associated entities for this resource
|
|
649
779
|
async getEntity(filters) {
|
|
650
|
-
const fname =
|
|
780
|
+
const fname = "getEntity";
|
|
651
781
|
try {
|
|
652
|
-
let query =
|
|
782
|
+
let query = "select e.* from stsentity e join stsresource r on e.resourceoid = r.oid";
|
|
653
783
|
let values = [];
|
|
654
|
-
const qs = this.#buildQueryString(filters,
|
|
784
|
+
const qs = this.#buildQueryString(filters, "e");
|
|
655
785
|
const resourceid = filters.resname;
|
|
656
786
|
//let entityid = filters.entname;
|
|
657
787
|
if (qs !== null) {
|
|
@@ -659,20 +789,32 @@ export class PGAccessLayer {
|
|
|
659
789
|
values = qs.qparams;
|
|
660
790
|
}
|
|
661
791
|
query += " limit 2";
|
|
662
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
792
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
663
793
|
try {
|
|
664
794
|
const { rows } = await client.query(query, values);
|
|
665
795
|
if (rows.length === 0) {
|
|
666
|
-
return {
|
|
796
|
+
return {
|
|
797
|
+
status: StatusCodes.NOT_FOUND,
|
|
798
|
+
error: `[${fname}: resourceid [${resourceid}] (current version) not found`,
|
|
799
|
+
detail: null,
|
|
800
|
+
};
|
|
667
801
|
}
|
|
668
802
|
if (rows.length > 1) {
|
|
669
|
-
return {
|
|
803
|
+
return {
|
|
804
|
+
status: StatusCodes.NOT_FOUND,
|
|
805
|
+
error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`,
|
|
806
|
+
detail: null,
|
|
807
|
+
};
|
|
670
808
|
}
|
|
671
809
|
const dbResponse = rows[0];
|
|
672
810
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
673
811
|
}
|
|
674
812
|
catch (error) {
|
|
675
|
-
return {
|
|
813
|
+
return {
|
|
814
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
815
|
+
error: `[${fname}]: Operation was not successful`,
|
|
816
|
+
detail: error,
|
|
817
|
+
}; // Set default;
|
|
676
818
|
}
|
|
677
819
|
finally {
|
|
678
820
|
client.release();
|
|
@@ -681,15 +823,19 @@ export class PGAccessLayer {
|
|
|
681
823
|
catch (error) {
|
|
682
824
|
// Error getting the client connection from the pool
|
|
683
825
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
684
|
-
return {
|
|
826
|
+
return {
|
|
827
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
828
|
+
error: `[${fname}]: Operation was not successful`,
|
|
829
|
+
detail: error,
|
|
830
|
+
};
|
|
685
831
|
}
|
|
686
832
|
}
|
|
687
833
|
async getEntityEx(filters) {
|
|
688
|
-
const fname =
|
|
834
|
+
const fname = "getEntityEx";
|
|
689
835
|
try {
|
|
690
|
-
let query =
|
|
836
|
+
let query = "select e.* from stsentity e join stsresource r on e.resourceoid = r.oid";
|
|
691
837
|
let values = [];
|
|
692
|
-
const qs = this.#buildQueryString(filters,
|
|
838
|
+
const qs = this.#buildQueryString(filters, "e");
|
|
693
839
|
const resourceid = filters.resname;
|
|
694
840
|
//let entityid = filters.entname;
|
|
695
841
|
if (qs !== null) {
|
|
@@ -697,21 +843,33 @@ export class PGAccessLayer {
|
|
|
697
843
|
values = qs.qparams;
|
|
698
844
|
}
|
|
699
845
|
query += " limit 2";
|
|
700
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
846
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
701
847
|
try {
|
|
702
848
|
const { rows } = await client.query(query, values);
|
|
703
849
|
if (rows.length === 0) {
|
|
704
|
-
return {
|
|
850
|
+
return {
|
|
851
|
+
status: StatusCodes.NOT_FOUND,
|
|
852
|
+
error: `[${fname}: resourceid [${resourceid}] (current version) not found`,
|
|
853
|
+
detail: null,
|
|
854
|
+
};
|
|
705
855
|
}
|
|
706
856
|
if (rows.length > 1) {
|
|
707
|
-
return {
|
|
857
|
+
return {
|
|
858
|
+
status: StatusCodes.NOT_FOUND,
|
|
859
|
+
error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`,
|
|
860
|
+
detail: null,
|
|
861
|
+
};
|
|
708
862
|
}
|
|
709
863
|
const dbResponse = rows[0];
|
|
710
864
|
const parsedDetail = JSON.parse(dbResponse.entvalue);
|
|
711
865
|
return { status: StatusCodes.OK, detail: parsedDetail };
|
|
712
866
|
}
|
|
713
867
|
catch (error) {
|
|
714
|
-
return {
|
|
868
|
+
return {
|
|
869
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
870
|
+
error: `[${fname}]: Operation was not successful`,
|
|
871
|
+
detail: error,
|
|
872
|
+
}; // Set default;
|
|
715
873
|
}
|
|
716
874
|
finally {
|
|
717
875
|
client.release();
|
|
@@ -720,29 +878,37 @@ export class PGAccessLayer {
|
|
|
720
878
|
catch (error) {
|
|
721
879
|
// Error getting the client connection from the pool
|
|
722
880
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
723
|
-
return {
|
|
881
|
+
return {
|
|
882
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
883
|
+
error: `[${fname}]: Operation was not successful`,
|
|
884
|
+
detail: error,
|
|
885
|
+
};
|
|
724
886
|
}
|
|
725
887
|
}
|
|
726
888
|
// get single resource and all associated entities for this resource
|
|
727
889
|
async getEntities(filters) {
|
|
728
|
-
const fname =
|
|
890
|
+
const fname = "getEntities";
|
|
729
891
|
try {
|
|
730
892
|
let query = `select e.* from stsentity e join stsresource r on e.resourceoid = r.oid`;
|
|
731
893
|
let values = [];
|
|
732
|
-
const qs = this.#buildQueryString(filters,
|
|
894
|
+
const qs = this.#buildQueryString(filters, "e");
|
|
733
895
|
if (qs !== null) {
|
|
734
896
|
query += qs.qstring;
|
|
735
897
|
values = qs.qparams;
|
|
736
898
|
}
|
|
737
899
|
query += " limit 10";
|
|
738
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
900
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
739
901
|
try {
|
|
740
902
|
const { rows } = await client.query(query, values);
|
|
741
903
|
const dbResponse = rows;
|
|
742
904
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
743
905
|
}
|
|
744
906
|
catch (error) {
|
|
745
|
-
return {
|
|
907
|
+
return {
|
|
908
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
909
|
+
error: `[${fname}]: Operation was not successful`,
|
|
910
|
+
detail: error,
|
|
911
|
+
}; // Set default;
|
|
746
912
|
}
|
|
747
913
|
finally {
|
|
748
914
|
client.release();
|
|
@@ -751,26 +917,30 @@ export class PGAccessLayer {
|
|
|
751
917
|
catch (error) {
|
|
752
918
|
// Error getting the client connection from the pool
|
|
753
919
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
754
|
-
return {
|
|
920
|
+
return {
|
|
921
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
922
|
+
error: `[${fname}]: Operation was not successful`,
|
|
923
|
+
detail: error,
|
|
924
|
+
};
|
|
755
925
|
}
|
|
756
926
|
}
|
|
757
927
|
async getEntitiesEx(filters) {
|
|
758
|
-
const fname =
|
|
928
|
+
const fname = "getEntities";
|
|
759
929
|
try {
|
|
760
930
|
let query = `select e.* from stsentity e join stsresource r on e.resourceoid = r.oid`;
|
|
761
931
|
let values = [];
|
|
762
|
-
const qs = this.#buildQueryString(filters,
|
|
932
|
+
const qs = this.#buildQueryString(filters, "e");
|
|
763
933
|
if (qs !== null) {
|
|
764
934
|
query += qs.qstring;
|
|
765
935
|
values = qs.qparams;
|
|
766
936
|
}
|
|
767
937
|
query += " limit 10";
|
|
768
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
938
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
769
939
|
try {
|
|
770
940
|
const { rows } = await client.query(query, values);
|
|
771
941
|
const dbResponse = rows;
|
|
772
942
|
const response = [];
|
|
773
|
-
dbResponse.forEach(r => {
|
|
943
|
+
dbResponse.forEach((r) => {
|
|
774
944
|
const obj = JSON.parse(r.entvalue);
|
|
775
945
|
r.entvalue = obj;
|
|
776
946
|
response.push(obj);
|
|
@@ -779,7 +949,11 @@ export class PGAccessLayer {
|
|
|
779
949
|
//return { status: StatusCodes.OK, detail: dbResponse };
|
|
780
950
|
}
|
|
781
951
|
catch (error) {
|
|
782
|
-
return {
|
|
952
|
+
return {
|
|
953
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
954
|
+
error: `[${fname}]: Operation was not successful`,
|
|
955
|
+
detail: error,
|
|
956
|
+
}; // Set default;
|
|
783
957
|
}
|
|
784
958
|
finally {
|
|
785
959
|
client.release();
|
|
@@ -788,29 +962,37 @@ export class PGAccessLayer {
|
|
|
788
962
|
catch (error) {
|
|
789
963
|
// Error getting the client connection from the pool
|
|
790
964
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
791
|
-
return {
|
|
965
|
+
return {
|
|
966
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
967
|
+
error: `[${fname}]: Operation was not successful`,
|
|
968
|
+
detail: error,
|
|
969
|
+
};
|
|
792
970
|
}
|
|
793
971
|
}
|
|
794
972
|
// get current resource
|
|
795
973
|
async getResources(filters) {
|
|
796
|
-
const fname =
|
|
974
|
+
const fname = "getResources";
|
|
797
975
|
try {
|
|
798
|
-
let query =
|
|
976
|
+
let query = "select r.* from stsresource r";
|
|
799
977
|
let values = [];
|
|
800
|
-
const qs = this.#buildQueryString(filters,
|
|
978
|
+
const qs = this.#buildQueryString(filters, "r");
|
|
801
979
|
if (qs !== null) {
|
|
802
980
|
query += qs.qstring;
|
|
803
981
|
values = qs.qparams;
|
|
804
982
|
}
|
|
805
983
|
query += " limit 10";
|
|
806
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
984
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
807
985
|
try {
|
|
808
986
|
const { rows } = await client.query(query, values);
|
|
809
987
|
const dbResponse = rows;
|
|
810
988
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
811
989
|
}
|
|
812
990
|
catch (error) {
|
|
813
|
-
return {
|
|
991
|
+
return {
|
|
992
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
993
|
+
error: `[${fname}]: Operation was not successful`,
|
|
994
|
+
detail: error,
|
|
995
|
+
}; // Set default;
|
|
814
996
|
}
|
|
815
997
|
finally {
|
|
816
998
|
client.release();
|
|
@@ -819,25 +1001,33 @@ export class PGAccessLayer {
|
|
|
819
1001
|
catch (error) {
|
|
820
1002
|
// Error getting the client connection from the pool
|
|
821
1003
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
822
|
-
return {
|
|
1004
|
+
return {
|
|
1005
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1006
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1007
|
+
detail: error,
|
|
1008
|
+
};
|
|
823
1009
|
}
|
|
824
1010
|
}
|
|
825
1011
|
async deleteResources(resname, actionuser) {
|
|
826
|
-
const fname =
|
|
1012
|
+
const fname = "deleteResources";
|
|
827
1013
|
try {
|
|
828
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
1014
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
829
1015
|
try {
|
|
830
|
-
const query =
|
|
1016
|
+
const query = "delete from stsresource where resname like $1 and dbactionuser = $2";
|
|
831
1017
|
const values = [resname, actionuser];
|
|
832
|
-
await client.query(
|
|
1018
|
+
await client.query("BEGIN");
|
|
833
1019
|
await client.query(query, values);
|
|
834
|
-
await client.query(
|
|
1020
|
+
await client.query("COMMIT");
|
|
835
1021
|
return { status: StatusCodes.OK };
|
|
836
1022
|
}
|
|
837
1023
|
catch (error) {
|
|
838
1024
|
this.#LogErrorMessage(`[${fname}]: Failed to delete resources: ${error}`);
|
|
839
|
-
await client.query(
|
|
840
|
-
return {
|
|
1025
|
+
await client.query("ROLLBACK");
|
|
1026
|
+
return {
|
|
1027
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1028
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1029
|
+
detail: error,
|
|
1030
|
+
};
|
|
841
1031
|
}
|
|
842
1032
|
finally {
|
|
843
1033
|
client.release();
|
|
@@ -846,25 +1036,33 @@ export class PGAccessLayer {
|
|
|
846
1036
|
catch (error) {
|
|
847
1037
|
// Error getting the client connection from the pool
|
|
848
1038
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
849
|
-
return {
|
|
1039
|
+
return {
|
|
1040
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1041
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1042
|
+
detail: error,
|
|
1043
|
+
};
|
|
850
1044
|
}
|
|
851
1045
|
}
|
|
852
1046
|
async deleteAllResources() {
|
|
853
|
-
const fname =
|
|
1047
|
+
const fname = "createResource";
|
|
854
1048
|
try {
|
|
855
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
1049
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
856
1050
|
try {
|
|
857
1051
|
const query = "delete from stsresource";
|
|
858
1052
|
//const query = "truncate stsresource cascade";
|
|
859
|
-
await client.query(
|
|
1053
|
+
await client.query("BEGIN");
|
|
860
1054
|
await client.query(query);
|
|
861
|
-
await client.query(
|
|
1055
|
+
await client.query("COMMIT");
|
|
862
1056
|
return { status: StatusCodes.OK };
|
|
863
1057
|
}
|
|
864
1058
|
catch (error) {
|
|
865
1059
|
this.#LogErrorMessage(`[${fname}]: Failed to truncate table(s): ${error}`);
|
|
866
|
-
await client.query(
|
|
867
|
-
return {
|
|
1060
|
+
await client.query("ROLLBACK");
|
|
1061
|
+
return {
|
|
1062
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1063
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1064
|
+
detail: error,
|
|
1065
|
+
};
|
|
868
1066
|
}
|
|
869
1067
|
finally {
|
|
870
1068
|
client.release();
|
|
@@ -873,13 +1071,17 @@ export class PGAccessLayer {
|
|
|
873
1071
|
catch (error) {
|
|
874
1072
|
// Error getting the client connection from the pool
|
|
875
1073
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
876
|
-
return {
|
|
1074
|
+
return {
|
|
1075
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1076
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1077
|
+
detail: error,
|
|
1078
|
+
};
|
|
877
1079
|
}
|
|
878
1080
|
}
|
|
879
1081
|
async getTotalResources() {
|
|
880
|
-
const fname =
|
|
1082
|
+
const fname = "getTotalResources";
|
|
881
1083
|
try {
|
|
882
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
1084
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
883
1085
|
try {
|
|
884
1086
|
//const query = "delete from stsresource";
|
|
885
1087
|
const query = "select count(*) from stsresource";
|
|
@@ -889,8 +1091,12 @@ export class PGAccessLayer {
|
|
|
889
1091
|
}
|
|
890
1092
|
catch (error) {
|
|
891
1093
|
this.#LogErrorMessage(`[${fname}]: Could not get count from stsresource table: ${error}`);
|
|
892
|
-
await client.query(
|
|
893
|
-
return {
|
|
1094
|
+
await client.query("ROLLBACK");
|
|
1095
|
+
return {
|
|
1096
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1097
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1098
|
+
detail: error,
|
|
1099
|
+
};
|
|
894
1100
|
}
|
|
895
1101
|
finally {
|
|
896
1102
|
client.release();
|
|
@@ -899,23 +1105,27 @@ export class PGAccessLayer {
|
|
|
899
1105
|
catch (error) {
|
|
900
1106
|
// Error getting the client connection from the pool
|
|
901
1107
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
902
|
-
return {
|
|
1108
|
+
return {
|
|
1109
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1110
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1111
|
+
detail: error,
|
|
1112
|
+
};
|
|
903
1113
|
}
|
|
904
1114
|
}
|
|
905
1115
|
async executedbscript(scriptfile) {
|
|
906
1116
|
try {
|
|
907
|
-
const fname =
|
|
908
|
-
const queryText = await fs.readFile(scriptfile,
|
|
1117
|
+
const fname = "executedbscript";
|
|
1118
|
+
const queryText = await fs.readFile(scriptfile, "utf-8");
|
|
909
1119
|
try {
|
|
910
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
1120
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
911
1121
|
try {
|
|
912
|
-
await client.query(
|
|
1122
|
+
await client.query("BEGIN");
|
|
913
1123
|
await client.query(queryText);
|
|
914
|
-
await client.query(
|
|
1124
|
+
await client.query("COMMIT");
|
|
915
1125
|
return `Completed executing file: ${scriptfile}`;
|
|
916
1126
|
}
|
|
917
1127
|
catch (error) {
|
|
918
|
-
await client.query(
|
|
1128
|
+
await client.query("ROLLBACK");
|
|
919
1129
|
this.#LogErrorMessage(`Error executing script: [${scriptfile}], Error: [${error}]`);
|
|
920
1130
|
throw error;
|
|
921
1131
|
}
|
|
@@ -967,27 +1177,29 @@ export class PGAccessLayer {
|
|
|
967
1177
|
}
|
|
968
1178
|
bulkInsert(fakerdata) {
|
|
969
1179
|
return new Promise((resolve, reject) => {
|
|
970
|
-
this.#poolManager
|
|
1180
|
+
this.#poolManager
|
|
1181
|
+
?.connectReadWrite()
|
|
1182
|
+
.then((client) => {
|
|
971
1183
|
const done = () => {
|
|
972
1184
|
client.release();
|
|
973
|
-
resolve(
|
|
1185
|
+
resolve("Completed");
|
|
974
1186
|
};
|
|
975
1187
|
/*
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1188
|
+
CREATE TABLE public.stsresource
|
|
1189
|
+
oid bigint NOT NULL DEFAULT nextval('stsresource_oid_seq'::regclass),
|
|
1190
|
+
resname character varying(80) COLLATE pg_catalog."default" NOT NULL,
|
|
1191
|
+
resdesc character varying(32768) COLLATE pg_catalog."default",
|
|
1192
|
+
vnum bigint NOT NULL,
|
|
1193
|
+
validfrom timestamp without time zone NOT NULL,
|
|
1194
|
+
validto timestamp without time zone,
|
|
1195
|
+
dbaction smallint NOT NULL,
|
|
1196
|
+
dbactionuser character varying(64) COLLATE pg_catalog."default" NOT NULL,
|
|
1197
|
+
*/
|
|
986
1198
|
//insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
|
|
987
1199
|
//values (_resname, _resdesc, 1, 1, _dbactionuser, __now);
|
|
988
1200
|
//var stream = client.query(copyFrom('COPY stsresource (oid,resname,resdesc,vnum,validfrom,validto,dbaction,dbactionuser) FROM STDIN'));
|
|
989
|
-
const stream = client.query(copyFrom(
|
|
990
|
-
const rs = new streamex.Readable;
|
|
1201
|
+
const stream = client.query(copyFrom("COPY stsresource (resname,resdesc,vnum,validfrom,dbaction,dbactionuser) FROM STDIN"));
|
|
1202
|
+
const rs = new streamex.Readable();
|
|
991
1203
|
let currentIndex = 0;
|
|
992
1204
|
rs._read = function () {
|
|
993
1205
|
if (currentIndex === fakerdata.length) {
|
|
@@ -997,15 +1209,20 @@ export class PGAccessLayer {
|
|
|
997
1209
|
const data = fakerdata[currentIndex];
|
|
998
1210
|
rs.push(
|
|
999
1211
|
//data.oid
|
|
1000
|
-
data.resname
|
|
1001
|
-
//+ '\t' + data.resname
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1212
|
+
data.resname +
|
|
1213
|
+
//+ '\t' + data.resname
|
|
1214
|
+
"\t" +
|
|
1215
|
+
data.resdesc +
|
|
1216
|
+
"\t" +
|
|
1217
|
+
data.vnum +
|
|
1218
|
+
"\t" +
|
|
1219
|
+
data.validfrom +
|
|
1220
|
+
//+ '\t' + data.validto
|
|
1221
|
+
"\t" +
|
|
1222
|
+
data.dbaction +
|
|
1223
|
+
"\t" +
|
|
1224
|
+
data.dbactionuser +
|
|
1225
|
+
"\n");
|
|
1009
1226
|
currentIndex++;
|
|
1010
1227
|
}
|
|
1011
1228
|
};
|
|
@@ -1013,27 +1230,32 @@ export class PGAccessLayer {
|
|
|
1013
1230
|
client.release();
|
|
1014
1231
|
reject(strErr);
|
|
1015
1232
|
};
|
|
1016
|
-
rs.on(
|
|
1017
|
-
stream.on(
|
|
1018
|
-
stream.on(
|
|
1233
|
+
rs.on("error", onError);
|
|
1234
|
+
stream.on("error", onError);
|
|
1235
|
+
stream.on("finish", done);
|
|
1019
1236
|
rs.pipe(stream);
|
|
1020
|
-
})
|
|
1237
|
+
})
|
|
1238
|
+
.catch((error) => {
|
|
1021
1239
|
this.#LogErrorMessage(error);
|
|
1022
1240
|
});
|
|
1023
1241
|
});
|
|
1024
1242
|
}
|
|
1025
1243
|
async GetMonitorSummary() {
|
|
1026
|
-
const fname =
|
|
1244
|
+
const fname = "GetMonitorSummary";
|
|
1027
1245
|
try {
|
|
1028
1246
|
const createQuery = `select * from get_monitor_summary()`;
|
|
1029
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
1247
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
1030
1248
|
try {
|
|
1031
1249
|
const { rows } = await client.query(createQuery);
|
|
1032
1250
|
const dbResponse = rows;
|
|
1033
1251
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
1034
1252
|
}
|
|
1035
1253
|
catch (error) {
|
|
1036
|
-
const err = {
|
|
1254
|
+
const err = {
|
|
1255
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1256
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1257
|
+
detail: error,
|
|
1258
|
+
}; // Set default
|
|
1037
1259
|
this.#LogDebugMessage(chalk.red(`Error: ${JSON.stringify(error)}`));
|
|
1038
1260
|
return err;
|
|
1039
1261
|
}
|
|
@@ -1044,22 +1266,30 @@ export class PGAccessLayer {
|
|
|
1044
1266
|
catch (error) {
|
|
1045
1267
|
// Error getting the client connection from the pool
|
|
1046
1268
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
1047
|
-
return {
|
|
1269
|
+
return {
|
|
1270
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1271
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1272
|
+
detail: error,
|
|
1273
|
+
};
|
|
1048
1274
|
}
|
|
1049
1275
|
}
|
|
1050
1276
|
async GetMonitorSummaryByServiceId(serviceId) {
|
|
1051
|
-
const fname =
|
|
1277
|
+
const fname = "GetMonitorSummaryByServiceId";
|
|
1052
1278
|
try {
|
|
1053
1279
|
const createQuery = `select * from get_monitor_summary_by_serviceid($1)`;
|
|
1054
1280
|
const values = [serviceId];
|
|
1055
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
1281
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
1056
1282
|
try {
|
|
1057
1283
|
const { rows } = await client.query(createQuery, values);
|
|
1058
1284
|
const dbResponse = rows;
|
|
1059
1285
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
1060
1286
|
}
|
|
1061
1287
|
catch (error) {
|
|
1062
|
-
const err = {
|
|
1288
|
+
const err = {
|
|
1289
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1290
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1291
|
+
detail: error,
|
|
1292
|
+
}; // Set default
|
|
1063
1293
|
this.#LogDebugMessage(chalk.red(`Error: ${JSON.stringify(error)}`));
|
|
1064
1294
|
return err;
|
|
1065
1295
|
}
|
|
@@ -1070,22 +1300,30 @@ export class PGAccessLayer {
|
|
|
1070
1300
|
catch (error) {
|
|
1071
1301
|
// Error getting the client connection from the pool
|
|
1072
1302
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
1073
|
-
return {
|
|
1303
|
+
return {
|
|
1304
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1305
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1306
|
+
detail: error,
|
|
1307
|
+
};
|
|
1074
1308
|
}
|
|
1075
1309
|
}
|
|
1076
1310
|
async GetMonitorSummaryByServiceInstanceId(serviceInstanceId) {
|
|
1077
|
-
const fname =
|
|
1311
|
+
const fname = "GetMonitorSummaryByServiceInstanceId";
|
|
1078
1312
|
try {
|
|
1079
1313
|
const createQuery = `select * from get_monitor_summary_by_serviceinstanceid($1)`;
|
|
1080
1314
|
const values = [serviceInstanceId];
|
|
1081
|
-
const client = await this.#poolManager?.connectReadOnly();
|
|
1315
|
+
const client = (await this.#poolManager?.connectReadOnly());
|
|
1082
1316
|
try {
|
|
1083
1317
|
const { rows } = await client.query(createQuery, values);
|
|
1084
1318
|
const dbResponse = rows;
|
|
1085
1319
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
1086
1320
|
}
|
|
1087
1321
|
catch (error) {
|
|
1088
|
-
const err = {
|
|
1322
|
+
const err = {
|
|
1323
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1324
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1325
|
+
detail: error,
|
|
1326
|
+
}; // Set default
|
|
1089
1327
|
this.#LogDebugMessage(chalk.red(`Error: ${JSON.stringify(error)}`));
|
|
1090
1328
|
return err;
|
|
1091
1329
|
}
|
|
@@ -1096,22 +1334,30 @@ export class PGAccessLayer {
|
|
|
1096
1334
|
catch (error) {
|
|
1097
1335
|
// Error getting the client connection from the pool
|
|
1098
1336
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
1099
|
-
return {
|
|
1337
|
+
return {
|
|
1338
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1339
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1340
|
+
detail: error,
|
|
1341
|
+
};
|
|
1100
1342
|
}
|
|
1101
1343
|
}
|
|
1102
1344
|
async PurgeOldMonitorData(keepAgeSeconds) {
|
|
1103
|
-
const fname =
|
|
1345
|
+
const fname = "GetMonitorSummaryByServiceInstanceId";
|
|
1104
1346
|
try {
|
|
1105
1347
|
const createQuery = `select * from purge_old_monitor_data($1)`;
|
|
1106
1348
|
const values = [keepAgeSeconds];
|
|
1107
|
-
const client = await this.#poolManager?.connectReadWrite();
|
|
1349
|
+
const client = (await this.#poolManager?.connectReadWrite());
|
|
1108
1350
|
try {
|
|
1109
1351
|
const { rows } = await client.query(createQuery, values);
|
|
1110
1352
|
const dbResponse = rows[0];
|
|
1111
1353
|
return { status: StatusCodes.OK, detail: dbResponse };
|
|
1112
1354
|
}
|
|
1113
1355
|
catch (error) {
|
|
1114
|
-
const err = {
|
|
1356
|
+
const err = {
|
|
1357
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1358
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1359
|
+
detail: error,
|
|
1360
|
+
}; // Set default
|
|
1115
1361
|
this.#LogDebugMessage(chalk.red(`Error: ${JSON.stringify(error)}`));
|
|
1116
1362
|
return err;
|
|
1117
1363
|
}
|
|
@@ -1122,7 +1368,11 @@ export class PGAccessLayer {
|
|
|
1122
1368
|
catch (error) {
|
|
1123
1369
|
// Error getting the client connection from the pool
|
|
1124
1370
|
this.#LogErrorMessage(`[${fname}]: Could not get client from pool: ${error}`);
|
|
1125
|
-
return {
|
|
1371
|
+
return {
|
|
1372
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR,
|
|
1373
|
+
error: `[${fname}]: Operation was not successful`,
|
|
1374
|
+
detail: error,
|
|
1375
|
+
};
|
|
1126
1376
|
}
|
|
1127
1377
|
}
|
|
1128
1378
|
}
|