@nsshunt/stsdatamanagement 1.18.178 → 1.18.179
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 +10 -17
- package/dist/cliworker.js.map +1 -1
- package/dist/commonTypes.js +11 -14
- package/dist/commonTypes.js.map +1 -1
- package/dist/dalUserManager.js +7 -11
- package/dist/dalUserManager.js.map +1 -1
- package/dist/dalUserManager.test.js +45 -51
- package/dist/dalUserManager.test.js.map +1 -1
- package/dist/databaseutils.js +19 -26
- package/dist/databaseutils.js.map +1 -1
- package/dist/datagenerator.js +26 -33
- package/dist/datagenerator.js.map +1 -1
- package/dist/dbAccessLayerManager.js +5 -9
- package/dist/dbAccessLayerManager.js.map +1 -1
- package/dist/dbaccess.js +7 -23
- package/dist/dbaccess.js.map +1 -1
- package/dist/dbbuild.test.js +42 -47
- package/dist/dbbuild.test.js.map +1 -1
- package/dist/dberrors.js +13 -22
- package/dist/dberrors.js.map +1 -1
- package/dist/pcaccesslayer-entity.test.js +166 -171
- package/dist/pcaccesslayer-entity.test.js.map +1 -1
- package/dist/pcaccesslayer.test.js +208 -213
- package/dist/pcaccesslayer.test.js.map +1 -1
- package/dist/pgaccesslayer-old.js +114 -154
- package/dist/pgaccesslayer-old.js.map +1 -1
- package/dist/pgaccesslayer.js +131 -135
- package/dist/pgaccesslayer.js.map +1 -1
- package/dist/pgpoolmanager.js +32 -39
- package/dist/pgpoolmanager.js.map +1 -1
- package/dist/pgutils.js +10 -14
- package/dist/pgutils.js.map +1 -1
- package/dist/setupdb.js +8 -14
- package/dist/setupdb.js.map +1 -1
- package/package.json +5 -5
package/dist/pgaccesslayer.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PGAccessLayer = exports.updateMode = void 0;
|
|
4
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var updateMode;
|
|
2
|
+
import { StatusCodes } from 'http-status-codes';
|
|
3
|
+
import { Redis } from "ioredis";
|
|
4
|
+
import { goptions } from '@nsshunt/stsconfig';
|
|
5
|
+
import { PGPoolManager } from './pgpoolmanager.js';
|
|
6
|
+
import { IDBAccessLayerEvents, eOperations } from './commonTypes.js';
|
|
7
|
+
import { TinyEmitter } from 'tiny-emitter';
|
|
8
|
+
export var updateMode;
|
|
12
9
|
(function (updateMode) {
|
|
13
10
|
updateMode[updateMode["patchResources"] = 0] = "patchResources";
|
|
14
11
|
updateMode[updateMode["updateResources"] = 1] = "updateResources";
|
|
@@ -16,8 +13,8 @@ var updateMode;
|
|
|
16
13
|
updateMode[updateMode["patchEntities"] = 3] = "patchEntities";
|
|
17
14
|
updateMode[updateMode["updateEntities"] = 4] = "updateEntities";
|
|
18
15
|
updateMode[updateMode["deleteEntities"] = 5] = "deleteEntities";
|
|
19
|
-
})(updateMode || (
|
|
20
|
-
class PGAccessLayer extends
|
|
16
|
+
})(updateMode || (updateMode = {}));
|
|
17
|
+
export class PGAccessLayer extends TinyEmitter {
|
|
21
18
|
#options;
|
|
22
19
|
// eslint-disable-next-line @/no-unused-private-class-members
|
|
23
20
|
#cache = null;
|
|
@@ -25,22 +22,22 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
25
22
|
constructor(options) {
|
|
26
23
|
super();
|
|
27
24
|
this.#options = options;
|
|
28
|
-
const { useRedisDatabaseCache, redisDatabaseCacheUrl } =
|
|
29
|
-
this.#poolManager = new
|
|
25
|
+
const { useRedisDatabaseCache, redisDatabaseCacheUrl } = goptions;
|
|
26
|
+
this.#poolManager = new PGPoolManager({
|
|
30
27
|
logger: this.#options.logger,
|
|
31
28
|
usedefaultdb: this.#options.usedefaultdb
|
|
32
29
|
});
|
|
33
|
-
this.#poolManager.on(
|
|
30
|
+
this.#poolManager.on(IDBAccessLayerEvents.UpdateInstruments, this.#UpdateInstruments);
|
|
34
31
|
if (useRedisDatabaseCache === true) {
|
|
35
32
|
const redisOptions = {
|
|
36
33
|
showFriendlyErrorStack: true,
|
|
37
34
|
maxRetriesPerRequest: 20
|
|
38
35
|
};
|
|
39
|
-
this.#cache = new
|
|
36
|
+
this.#cache = new Redis(redisDatabaseCacheUrl, redisOptions);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
#UpdateInstruments = (data) => {
|
|
43
|
-
this.emit(
|
|
40
|
+
this.emit(IDBAccessLayerEvents.UpdateInstruments, data);
|
|
44
41
|
};
|
|
45
42
|
#LogErrorMessage = (message) => {
|
|
46
43
|
this.#options.logger.error(message);
|
|
@@ -197,7 +194,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
197
194
|
}
|
|
198
195
|
async EndDatabase() {
|
|
199
196
|
if (this.#poolManager) {
|
|
200
|
-
this.#poolManager.off(
|
|
197
|
+
this.#poolManager.off(IDBAccessLayerEvents.UpdateInstruments, this.#UpdateInstruments);
|
|
201
198
|
await this.#poolManager.End();
|
|
202
199
|
}
|
|
203
200
|
this.#poolManager = null;
|
|
@@ -220,19 +217,19 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
220
217
|
return {
|
|
221
218
|
options: useOptions,
|
|
222
219
|
operation: 'GetResourceCount',
|
|
223
|
-
status:
|
|
220
|
+
status: StatusCodes.OK,
|
|
224
221
|
detail: parseInt(dbResponse.count) //@@ needs to be number
|
|
225
222
|
};
|
|
226
223
|
}
|
|
227
224
|
catch (error) {
|
|
228
|
-
return this.#LogAndGetErrorMessage(useOptions,
|
|
225
|
+
return this.#LogAndGetErrorMessage(useOptions, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResourceCount, `pgaccesslayer:GetResourceCount(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
229
226
|
}
|
|
230
227
|
finally {
|
|
231
228
|
client.release();
|
|
232
229
|
}
|
|
233
230
|
}
|
|
234
231
|
catch (error) {
|
|
235
|
-
return this.#LogAndGetErrorMessage(useOptions,
|
|
232
|
+
return this.#LogAndGetErrorMessage(useOptions, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResourceCount, `pgaccesslayer:GetResourceCount(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
235
|
async GetEntityCount(options) {
|
|
@@ -255,25 +252,25 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
255
252
|
const { rows } = await client.query(query, values);
|
|
256
253
|
const dbResponse = rows[0];
|
|
257
254
|
return {
|
|
258
|
-
status:
|
|
255
|
+
status: StatusCodes.OK,
|
|
259
256
|
options,
|
|
260
257
|
detail: parseInt(dbResponse.count), //@@ needs to be number
|
|
261
258
|
operation: 'GetEntityCount'
|
|
262
259
|
};
|
|
263
260
|
}
|
|
264
261
|
catch (error) {
|
|
265
|
-
return this.#LogAndGetErrorMessage(options,
|
|
262
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntityCount, `pgaccesslayer:GetEntityCount(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
266
263
|
}
|
|
267
264
|
finally {
|
|
268
265
|
client.release();
|
|
269
266
|
}
|
|
270
267
|
}
|
|
271
268
|
else {
|
|
272
|
-
return this.#LogAndGetErrorMessage(options,
|
|
269
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntityCount, `pgaccesslayer:GetEntityCount(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
273
270
|
}
|
|
274
271
|
}
|
|
275
272
|
catch (error) {
|
|
276
|
-
return this.#LogAndGetErrorMessage(options,
|
|
273
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntityCount, `pgaccesslayer:GetEntityCount(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
277
274
|
}
|
|
278
275
|
}
|
|
279
276
|
async #__CreateResource(client, options, operation, resource) {
|
|
@@ -292,7 +289,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
292
289
|
const dbResponse = rows[0];
|
|
293
290
|
dbResponse.resdesc = this.#JSONParse(dbResponse.resdesc);
|
|
294
291
|
return {
|
|
295
|
-
status:
|
|
292
|
+
status: StatusCodes.CREATED,
|
|
296
293
|
detail: dbResponse,
|
|
297
294
|
options,
|
|
298
295
|
operation
|
|
@@ -300,15 +297,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
300
297
|
}
|
|
301
298
|
catch (error) {
|
|
302
299
|
if (error.code === '23505') {
|
|
303
|
-
return this.#LogAndGetErrorMessage(options,
|
|
300
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.CONFLICT, eOperations.CreateResource, `pgaccesslayer:__CreateResource(): resourceid [${options.filters?.resname}] already exists. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
304
301
|
}
|
|
305
302
|
else {
|
|
306
|
-
return this.#LogAndGetErrorMessage(options,
|
|
303
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateResource, `pgaccesslayer:__CreateResource(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
307
304
|
}
|
|
308
305
|
}
|
|
309
306
|
}
|
|
310
307
|
else {
|
|
311
|
-
return this.#LogAndGetErrorMessage(options,
|
|
308
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateResource, `pgaccesslayer:__CreateResource(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
312
309
|
}
|
|
313
310
|
}
|
|
314
311
|
async CreateResource(options, resource) {
|
|
@@ -316,8 +313,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
316
313
|
const client = await this.#poolManager?.connectReadWrite();
|
|
317
314
|
try {
|
|
318
315
|
await client.query('BEGIN');
|
|
319
|
-
const retVal = await this.#__CreateResource(client, options,
|
|
320
|
-
if (retVal.status ===
|
|
316
|
+
const retVal = await this.#__CreateResource(client, options, eOperations.CreateResource, resource);
|
|
317
|
+
if (retVal.status === StatusCodes.CREATED) {
|
|
321
318
|
await client.query('COMMIT');
|
|
322
319
|
}
|
|
323
320
|
else {
|
|
@@ -327,14 +324,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
327
324
|
}
|
|
328
325
|
catch (error) {
|
|
329
326
|
await client.query('ROLLBACK');
|
|
330
|
-
return this.#LogAndGetErrorMessage(options,
|
|
327
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateResource, `pgaccesslayer:CreateResource(): Operation was not successful (__CreateResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
331
328
|
}
|
|
332
329
|
finally {
|
|
333
330
|
client.release();
|
|
334
331
|
}
|
|
335
332
|
}
|
|
336
333
|
catch (error) {
|
|
337
|
-
return this.#LogAndGetErrorMessage(options,
|
|
334
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateResource, `pgaccesslayer:CreateResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
338
335
|
}
|
|
339
336
|
}
|
|
340
337
|
async #__GetResource(client, options) {
|
|
@@ -355,10 +352,10 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
355
352
|
const { rows } = await client.query(query, values);
|
|
356
353
|
if (rows.length === 0) {
|
|
357
354
|
// Don't log this type as this may be used to determine if a record exists.
|
|
358
|
-
return this.#GetErrorMessage(options,
|
|
355
|
+
return this.#GetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.GetResource, `pgaccesslayer:GetResource(): resourceid [${resourceid}] (current version) not found.`);
|
|
359
356
|
}
|
|
360
357
|
if (rows.length > 1) {
|
|
361
|
-
return this.#LogAndGetErrorMessage(options,
|
|
358
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.GetResource, `pgaccesslayer:GetResource(): Multiple resourceid [${resourceid}] (current version) exist within database. Invalid database state.`);
|
|
362
359
|
}
|
|
363
360
|
const dbResponse = rows[0];
|
|
364
361
|
//try {
|
|
@@ -368,22 +365,22 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
368
365
|
//`pgaccesslayer:GetResource(): Could not parse JSON object. Value: [${dbResponse.resdesc}]`);
|
|
369
366
|
//}
|
|
370
367
|
return {
|
|
371
|
-
status:
|
|
368
|
+
status: StatusCodes.OK,
|
|
372
369
|
detail: dbResponse,
|
|
373
|
-
operation:
|
|
370
|
+
operation: eOperations.GetResource,
|
|
374
371
|
options
|
|
375
372
|
};
|
|
376
373
|
}
|
|
377
374
|
catch (error) {
|
|
378
|
-
return this.#LogAndGetErrorMessage(options,
|
|
375
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResource, `pgaccesslayer:GetResource(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
379
376
|
}
|
|
380
377
|
}
|
|
381
378
|
else {
|
|
382
|
-
return this.#LogAndGetErrorMessage(options,
|
|
379
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResource, `pgaccesslayer:GetResource(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
383
380
|
}
|
|
384
381
|
}
|
|
385
382
|
catch (error) {
|
|
386
|
-
return this.#LogAndGetErrorMessage(options,
|
|
383
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResource, `pgaccesslayer:GetResource(): Operation was not successful (outer). Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
387
384
|
}
|
|
388
385
|
}
|
|
389
386
|
async GetResource(options) {
|
|
@@ -400,7 +397,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
400
397
|
return retVal;
|
|
401
398
|
}
|
|
402
399
|
catch (error) {
|
|
403
|
-
return this.#LogAndGetErrorMessage(options,
|
|
400
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResource, `pgaccesslayer:GetResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
404
401
|
}
|
|
405
402
|
}
|
|
406
403
|
async #__UpdateResource(client, options, operation, resource) {
|
|
@@ -416,7 +413,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
416
413
|
const dbResponse = rows[0];
|
|
417
414
|
dbResponse.resdesc = this.#JSONParse(dbResponse.resdesc);
|
|
418
415
|
return {
|
|
419
|
-
status:
|
|
416
|
+
status: StatusCodes.OK,
|
|
420
417
|
detail: dbResponse,
|
|
421
418
|
operation,
|
|
422
419
|
options
|
|
@@ -424,15 +421,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
424
421
|
}
|
|
425
422
|
catch (error) {
|
|
426
423
|
if (error.code === 'P0002') {
|
|
427
|
-
return this.#LogAndGetErrorMessage(options,
|
|
424
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.UpdateResource, `pgaccesslayer:__UpdateResource(): resourceid [${options.filters?.resname}] not found or not current. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
428
425
|
}
|
|
429
426
|
else {
|
|
430
|
-
return this.#LogAndGetErrorMessage(options,
|
|
427
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateResource, `pgaccesslayer:__UpdateResource(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
431
428
|
}
|
|
432
429
|
}
|
|
433
430
|
}
|
|
434
431
|
catch (error) {
|
|
435
|
-
return this.#LogAndGetErrorMessage(options,
|
|
432
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateResource, `pgaccesslayer:__UpdateResource(): Operation was not successful (__GetResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
436
433
|
}
|
|
437
434
|
}
|
|
438
435
|
async UpdateResource(options, resource) {
|
|
@@ -440,8 +437,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
440
437
|
const client = await this.#poolManager?.connectReadWrite();
|
|
441
438
|
try {
|
|
442
439
|
await client.query('BEGIN');
|
|
443
|
-
const retVal = await this.#__UpdateResource(client, options,
|
|
444
|
-
if (retVal.status ===
|
|
440
|
+
const retVal = await this.#__UpdateResource(client, options, eOperations.UpdateResource, resource);
|
|
441
|
+
if (retVal.status === StatusCodes.OK) {
|
|
445
442
|
await client.query('COMMIT');
|
|
446
443
|
}
|
|
447
444
|
else {
|
|
@@ -451,14 +448,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
451
448
|
}
|
|
452
449
|
catch (error) {
|
|
453
450
|
await client.query('ROLLBACK');
|
|
454
|
-
return this.#LogAndGetErrorMessage(options,
|
|
451
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateResource, `pgaccesslayer:UpdateResource(): Operation was not successful (__GetResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
455
452
|
}
|
|
456
453
|
finally {
|
|
457
454
|
client.release();
|
|
458
455
|
}
|
|
459
456
|
}
|
|
460
457
|
catch (error) {
|
|
461
|
-
return this.#LogAndGetErrorMessage(options,
|
|
458
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateResource, `pgaccesslayer:UpdateResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
462
459
|
}
|
|
463
460
|
}
|
|
464
461
|
async PatchResource(options, resource) {
|
|
@@ -467,10 +464,10 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
467
464
|
try {
|
|
468
465
|
await client.query('BEGIN');
|
|
469
466
|
const currentResource = await this.#__GetResource(client, options);
|
|
470
|
-
if (currentResource.status ===
|
|
467
|
+
if (currentResource.status === StatusCodes.OK) {
|
|
471
468
|
const updatedRecord = { ...currentResource.detail.resdesc, ...resource };
|
|
472
|
-
const retVal = await this.#__UpdateResource(client, options,
|
|
473
|
-
if (retVal.status ===
|
|
469
|
+
const retVal = await this.#__UpdateResource(client, options, eOperations.PatchResource, updatedRecord);
|
|
470
|
+
if (retVal.status === StatusCodes.OK) {
|
|
474
471
|
await client.query('COMMIT');
|
|
475
472
|
}
|
|
476
473
|
else {
|
|
@@ -485,14 +482,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
485
482
|
}
|
|
486
483
|
catch (error) {
|
|
487
484
|
await client.query('ROLLBACK');
|
|
488
|
-
return this.#LogAndGetErrorMessage(options,
|
|
485
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.PatchResource, `pgaccesslayer:PatchResource(): Operation was not successful (__GetResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
489
486
|
}
|
|
490
487
|
finally {
|
|
491
488
|
client.release();
|
|
492
489
|
}
|
|
493
490
|
}
|
|
494
491
|
catch (error) {
|
|
495
|
-
return this.#LogAndGetErrorMessage(options,
|
|
492
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.PatchResource, `pgaccesslayer:PatchResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
496
493
|
}
|
|
497
494
|
}
|
|
498
495
|
async #__UpdateOrPatchResources(resourceParameterRecords, mode, operation) {
|
|
@@ -505,7 +502,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
505
502
|
const UpdateRecordPromise = new Promise((resolve, reject) => {
|
|
506
503
|
if (mode === updateMode.updateResources || mode === updateMode.patchResources || mode === updateMode.deleteResources) {
|
|
507
504
|
this.#__GetResource(client, rpr.opitons).then((currentResource) => {
|
|
508
|
-
if (currentResource.status ===
|
|
505
|
+
if (currentResource.status === StatusCodes.OK) {
|
|
509
506
|
let updatedRecord;
|
|
510
507
|
switch (mode) {
|
|
511
508
|
case updateMode.patchResources:
|
|
@@ -523,11 +520,11 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
523
520
|
reject(`pgaccesslayer:#__UpdateOrPatchResources(): Unknown mode (resource): [${mode}]`);
|
|
524
521
|
}
|
|
525
522
|
}
|
|
526
|
-
else if (currentResource.status ===
|
|
523
|
+
else if (currentResource.status === StatusCodes.NOT_FOUND
|
|
527
524
|
&& mode === updateMode.updateResources
|
|
528
525
|
&& !rpr.opitons.errorOnBatchUpdate) {
|
|
529
526
|
const createNewResourceRecord = rpr.resource;
|
|
530
|
-
this.#__CreateResource(client, rpr.opitons,
|
|
527
|
+
this.#__CreateResource(client, rpr.opitons, eOperations.UpdateResources, createNewResourceRecord).then(retVal => resolve(retVal)).catch(error => reject(error));
|
|
531
528
|
}
|
|
532
529
|
else {
|
|
533
530
|
resolve(currentResource);
|
|
@@ -538,7 +535,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
538
535
|
}
|
|
539
536
|
else {
|
|
540
537
|
this.#__GetEntity(client, rpr.opitons).then((currentEntity) => {
|
|
541
|
-
if (currentEntity.status ===
|
|
538
|
+
if (currentEntity.status === StatusCodes.OK) {
|
|
542
539
|
let updatedRecord;
|
|
543
540
|
switch (mode) {
|
|
544
541
|
case updateMode.patchEntities:
|
|
@@ -556,11 +553,11 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
556
553
|
reject(`pgaccesslayer:#__UpdateOrPatchResources(): Unknown mode (entity): [${mode}]`);
|
|
557
554
|
}
|
|
558
555
|
}
|
|
559
|
-
else if (currentEntity.status ===
|
|
556
|
+
else if (currentEntity.status === StatusCodes.NOT_FOUND
|
|
560
557
|
&& mode === updateMode.updateEntities
|
|
561
558
|
&& !rpr.opitons.errorOnBatchUpdate) {
|
|
562
559
|
const createNewEntityRecord = rpr.entity;
|
|
563
|
-
this.#__CreateEntity(client, rpr.opitons,
|
|
560
|
+
this.#__CreateEntity(client, rpr.opitons, eOperations.UpdateEntities, createNewEntityRecord).then(retVal => resolve(retVal)).catch(error => reject(error));
|
|
564
561
|
}
|
|
565
562
|
else {
|
|
566
563
|
resolve(currentEntity);
|
|
@@ -578,32 +575,32 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
578
575
|
}
|
|
579
576
|
catch (error) {
|
|
580
577
|
await client.query('ROLLBACK');
|
|
581
|
-
return this.#LogAndGetErrorMessage({},
|
|
578
|
+
return this.#LogAndGetErrorMessage({}, StatusCodes.INTERNAL_SERVER_ERROR, operation, `pgaccesslayer:#__UpdateOrPatchResources(): Operation was not successful (Promise.all(promArray)). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
582
579
|
}
|
|
583
580
|
const retVal = {
|
|
584
|
-
status:
|
|
581
|
+
status: StatusCodes.OK,
|
|
585
582
|
detail: [],
|
|
586
583
|
options: {},
|
|
587
584
|
operation: operation
|
|
588
585
|
};
|
|
589
586
|
promRetVal.forEach(prv => {
|
|
590
|
-
if (!(prv.status ===
|
|
591
|
-
if (retVal.status ===
|
|
587
|
+
if (!(prv.status === StatusCodes.OK || prv.status === StatusCodes.CREATED)) {
|
|
588
|
+
if (retVal.status === StatusCodes.OK) { // only set the first error
|
|
592
589
|
const message = `pgaccesslayer:#__UpdateOrPatchResources(): Operation was not successful. Check array for specific details.`;
|
|
593
|
-
retVal.status =
|
|
590
|
+
retVal.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
594
591
|
retVal.options = prv.options;
|
|
595
592
|
retVal.operation = prv.operation;
|
|
596
593
|
retVal.error = {
|
|
597
594
|
error: new Error(message),
|
|
598
595
|
errorMessage: message,
|
|
599
596
|
operation: prv.operation,
|
|
600
|
-
status:
|
|
597
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
601
598
|
};
|
|
602
599
|
}
|
|
603
600
|
}
|
|
604
601
|
retVal.detail.push(prv);
|
|
605
602
|
});
|
|
606
|
-
if (retVal.status ===
|
|
603
|
+
if (retVal.status === StatusCodes.OK) {
|
|
607
604
|
await client.query('COMMIT');
|
|
608
605
|
}
|
|
609
606
|
else {
|
|
@@ -616,33 +613,33 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
616
613
|
}
|
|
617
614
|
catch (error) {
|
|
618
615
|
await client.query('ROLLBACK');
|
|
619
|
-
return this.#LogAndGetErrorMessage({},
|
|
616
|
+
return this.#LogAndGetErrorMessage({}, StatusCodes.INTERNAL_SERVER_ERROR, operation, `pgaccesslayer:__#UpdateOrPatchResources(): Operation was not successful (Promise processing). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
620
617
|
}
|
|
621
618
|
finally {
|
|
622
619
|
client.release();
|
|
623
620
|
}
|
|
624
621
|
}
|
|
625
622
|
catch (error) {
|
|
626
|
-
return this.#LogAndGetErrorMessage({},
|
|
623
|
+
return this.#LogAndGetErrorMessage({}, StatusCodes.INTERNAL_SERVER_ERROR, operation, `pgaccesslayer:__#UpdateOrPatchResources(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
627
624
|
}
|
|
628
625
|
}
|
|
629
626
|
async PatchResources(resourceParameterRecords) {
|
|
630
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.patchResources,
|
|
627
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.patchResources, eOperations.PatchResources);
|
|
631
628
|
}
|
|
632
629
|
async UpdateResources(resourceParameterRecords) {
|
|
633
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.updateResources,
|
|
630
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.updateResources, eOperations.UpdateResources);
|
|
634
631
|
}
|
|
635
632
|
async DeleteResources(resourceParameterRecords) {
|
|
636
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.deleteResources,
|
|
633
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.deleteResources, eOperations.DeleteResources);
|
|
637
634
|
}
|
|
638
635
|
async PatchEntities(resourceParameterRecords) {
|
|
639
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.patchEntities,
|
|
636
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.patchEntities, eOperations.PatchEntities);
|
|
640
637
|
}
|
|
641
638
|
async UpdateEntities(resourceParameterRecords) {
|
|
642
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.updateEntities,
|
|
639
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.updateEntities, eOperations.UpdateEntities);
|
|
643
640
|
}
|
|
644
641
|
async DeleteEntities(resourceParameterRecords) {
|
|
645
|
-
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.deleteEntities,
|
|
642
|
+
return this.#__UpdateOrPatchResources(resourceParameterRecords, updateMode.deleteEntities, eOperations.DeleteEntities);
|
|
646
643
|
}
|
|
647
644
|
async #__DeleteResource(client, options, operation) {
|
|
648
645
|
try {
|
|
@@ -656,7 +653,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
656
653
|
const dbResponse = rows[0];
|
|
657
654
|
dbResponse.resdesc = this.#JSONParse(dbResponse.resdesc);
|
|
658
655
|
return {
|
|
659
|
-
status:
|
|
656
|
+
status: StatusCodes.OK,
|
|
660
657
|
detail: dbResponse,
|
|
661
658
|
options,
|
|
662
659
|
operation
|
|
@@ -664,15 +661,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
664
661
|
}
|
|
665
662
|
catch (error) {
|
|
666
663
|
if (error.code === 'P0002') {
|
|
667
|
-
return this.#LogAndGetErrorMessage(options,
|
|
664
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.DeleteResource, `pgaccesslayer:DeleteResource(): resourceid [${options.filters?.resname}] not found or not current. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
668
665
|
}
|
|
669
666
|
else {
|
|
670
|
-
return this.#LogAndGetErrorMessage(options,
|
|
667
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteResource, `pgaccesslayer:DeleteResource(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
671
668
|
}
|
|
672
669
|
}
|
|
673
670
|
}
|
|
674
671
|
catch (error) {
|
|
675
|
-
return this.#LogAndGetErrorMessage(options,
|
|
672
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteResource, `pgaccesslayer:DeleteResource(): Operation was not successful (__GetResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
676
673
|
}
|
|
677
674
|
}
|
|
678
675
|
async DeleteResource(options) {
|
|
@@ -680,8 +677,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
680
677
|
const client = await this.#poolManager?.connectReadWrite();
|
|
681
678
|
try {
|
|
682
679
|
await client.query('BEGIN');
|
|
683
|
-
const retVal = await this.#__DeleteResource(client, options,
|
|
684
|
-
if (retVal.status ===
|
|
680
|
+
const retVal = await this.#__DeleteResource(client, options, eOperations.DeleteResource);
|
|
681
|
+
if (retVal.status === StatusCodes.OK) {
|
|
685
682
|
await client.query('COMMIT');
|
|
686
683
|
}
|
|
687
684
|
else {
|
|
@@ -691,14 +688,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
691
688
|
}
|
|
692
689
|
catch (error) {
|
|
693
690
|
await client.query('ROLLBACK');
|
|
694
|
-
return this.#LogAndGetErrorMessage(options,
|
|
691
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteResource, `pgaccesslayer:DeleteResource(): Operation was not successful (__GetResource). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
695
692
|
}
|
|
696
693
|
finally {
|
|
697
694
|
client.release();
|
|
698
695
|
}
|
|
699
696
|
}
|
|
700
697
|
catch (error) {
|
|
701
|
-
return this.#LogAndGetErrorMessage(options,
|
|
698
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteResource, `pgaccesslayer:DeleteResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
702
699
|
}
|
|
703
700
|
}
|
|
704
701
|
async #__CreateEntity(client, options, operation, entity) {
|
|
@@ -719,7 +716,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
719
716
|
dbResponse.resourceoid = dbResponse.resourceoid.toString();
|
|
720
717
|
dbResponse.entvalue = this.#JSONParse(dbResponse.entvalue);
|
|
721
718
|
return {
|
|
722
|
-
status:
|
|
719
|
+
status: StatusCodes.CREATED,
|
|
723
720
|
detail: dbResponse,
|
|
724
721
|
options,
|
|
725
722
|
operation
|
|
@@ -727,15 +724,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
727
724
|
}
|
|
728
725
|
catch (error) {
|
|
729
726
|
if (error.code === '23505') {
|
|
730
|
-
return this.#LogAndGetErrorMessage(options,
|
|
727
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.CONFLICT, eOperations.CreateEntity, `pgaccesslayer:CreateEntity(): entityid [${options.filters?.entname}] already exists. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
731
728
|
}
|
|
732
729
|
else {
|
|
733
|
-
return this.#LogAndGetErrorMessage(options,
|
|
730
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateEntity, `pgaccesslayer:CreateEntity(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
734
731
|
}
|
|
735
732
|
}
|
|
736
733
|
}
|
|
737
734
|
else {
|
|
738
|
-
return this.#LogAndGetErrorMessage(options,
|
|
735
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateEntity, `pgaccesslayer:CreateEntity(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
739
736
|
}
|
|
740
737
|
}
|
|
741
738
|
async CreateEntity(options, entity) {
|
|
@@ -743,8 +740,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
743
740
|
const client = await this.#poolManager?.connectReadWrite();
|
|
744
741
|
try {
|
|
745
742
|
await client.query('BEGIN');
|
|
746
|
-
const retVal = await this.#__CreateEntity(client, options,
|
|
747
|
-
if (retVal.status ===
|
|
743
|
+
const retVal = await this.#__CreateEntity(client, options, eOperations.CreateEntity, entity);
|
|
744
|
+
if (retVal.status === StatusCodes.CREATED) {
|
|
748
745
|
await client.query('COMMIT');
|
|
749
746
|
}
|
|
750
747
|
else {
|
|
@@ -754,14 +751,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
754
751
|
}
|
|
755
752
|
catch (error) {
|
|
756
753
|
await client.query('ROLLBACK');
|
|
757
|
-
return this.#LogAndGetErrorMessage(options,
|
|
754
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateEntity, `pgaccesslayer:CreateEntity(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
758
755
|
}
|
|
759
756
|
finally {
|
|
760
757
|
client.release();
|
|
761
758
|
}
|
|
762
759
|
}
|
|
763
760
|
catch (error) {
|
|
764
|
-
return this.#LogAndGetErrorMessage(options,
|
|
761
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.CreateEntity, `pgaccesslayer:CreateEntity(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
765
762
|
}
|
|
766
763
|
}
|
|
767
764
|
async #__GetEntity(client, options) {
|
|
@@ -784,32 +781,32 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
784
781
|
try {
|
|
785
782
|
const { rows } = await client.query(query, values);
|
|
786
783
|
if (rows.length === 0) {
|
|
787
|
-
return this.#LogAndGetErrorMessage(options,
|
|
784
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.GetEntity, `pgaccesslayer:GetEntity(): resname: [${options.filters?.resname}], entname: [${options.filters?.entname}] (current version) not found`);
|
|
788
785
|
}
|
|
789
786
|
if (rows.length > 1) {
|
|
790
|
-
return this.#LogAndGetErrorMessage(options,
|
|
787
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.GetEntity, `pgaccesslayer:GetEntity(): Multiple resname [${options.filters?.resname}], entname: [${options.filters?.entname}] (current version) exist within database. Invalid database state.`);
|
|
791
788
|
}
|
|
792
789
|
const dbResponse = rows[0];
|
|
793
790
|
// Convert the resourceoid to a string
|
|
794
791
|
dbResponse.resourceoid = dbResponse.resourceoid.toString();
|
|
795
792
|
dbResponse.entvalue = this.#JSONParse(dbResponse.entvalue);
|
|
796
793
|
return {
|
|
797
|
-
status:
|
|
794
|
+
status: StatusCodes.OK,
|
|
798
795
|
detail: dbResponse,
|
|
799
796
|
options,
|
|
800
|
-
operation:
|
|
797
|
+
operation: eOperations.GetEntity
|
|
801
798
|
};
|
|
802
799
|
}
|
|
803
800
|
catch (error) {
|
|
804
|
-
return this.#LogAndGetErrorMessage(options,
|
|
801
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntity, `pgaccesslayer:GetEntity(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
805
802
|
}
|
|
806
803
|
}
|
|
807
804
|
else {
|
|
808
|
-
return this.#LogAndGetErrorMessage(options,
|
|
805
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntity, `pgaccesslayer:GetEntity(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
809
806
|
}
|
|
810
807
|
}
|
|
811
808
|
catch (error) {
|
|
812
|
-
return this.#LogAndGetErrorMessage(options,
|
|
809
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntity, `pgaccesslayer:GetEntity(): peration was not successful (outer). Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
813
810
|
}
|
|
814
811
|
}
|
|
815
812
|
async GetEntity(options) {
|
|
@@ -820,7 +817,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
820
817
|
return retVal;
|
|
821
818
|
}
|
|
822
819
|
catch (error) {
|
|
823
|
-
return this.#LogAndGetErrorMessage(options,
|
|
820
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntity, `pgaccesslayer:GetEntity(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
824
821
|
}
|
|
825
822
|
}
|
|
826
823
|
async #__UpdateEntity(client, options, operation, entity) {
|
|
@@ -839,7 +836,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
839
836
|
dbResponse.resourceoid = dbResponse.resourceoid.toString();
|
|
840
837
|
dbResponse.entvalue = this.#JSONParse(dbResponse.entvalue);
|
|
841
838
|
return {
|
|
842
|
-
status:
|
|
839
|
+
status: StatusCodes.OK,
|
|
843
840
|
detail: dbResponse,
|
|
844
841
|
options,
|
|
845
842
|
operation
|
|
@@ -847,15 +844,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
847
844
|
}
|
|
848
845
|
catch (error) {
|
|
849
846
|
if (error.code === 'P0002') {
|
|
850
|
-
return this.#LogAndGetErrorMessage(options,
|
|
847
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.UpdateEntity, `resname: [${options.filters?.resname}], entname: [${options.filters?.entname}] not found or not current. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
851
848
|
}
|
|
852
849
|
else {
|
|
853
|
-
return this.#LogAndGetErrorMessage(options,
|
|
850
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateEntity, `pgaccesslayer:__UpdateEntity(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
854
851
|
}
|
|
855
852
|
}
|
|
856
853
|
}
|
|
857
854
|
catch (error) {
|
|
858
|
-
return this.#LogAndGetErrorMessage(options,
|
|
855
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateEntity, `pgaccesslayer:__UpdateEntity(): Operation was not successful (__GetEntity). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
859
856
|
}
|
|
860
857
|
}
|
|
861
858
|
async UpdateEntity(options, entity) {
|
|
@@ -863,8 +860,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
863
860
|
const client = await this.#poolManager?.connectReadWrite();
|
|
864
861
|
try {
|
|
865
862
|
await client.query('BEGIN');
|
|
866
|
-
const retVal = await this.#__UpdateEntity(client, options,
|
|
867
|
-
if (retVal.status ===
|
|
863
|
+
const retVal = await this.#__UpdateEntity(client, options, eOperations.UpdateEntity, entity);
|
|
864
|
+
if (retVal.status === StatusCodes.OK) {
|
|
868
865
|
await client.query('COMMIT');
|
|
869
866
|
}
|
|
870
867
|
else {
|
|
@@ -874,14 +871,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
874
871
|
}
|
|
875
872
|
catch (error) {
|
|
876
873
|
await client.query('ROLLBACK');
|
|
877
|
-
return this.#LogAndGetErrorMessage(options,
|
|
874
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateEntity, `pgaccesslayer:GetEntity(): Operation was not successful (__GetEntity). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
878
875
|
}
|
|
879
876
|
finally {
|
|
880
877
|
client.release();
|
|
881
878
|
}
|
|
882
879
|
}
|
|
883
880
|
catch (error) {
|
|
884
|
-
return this.#LogAndGetErrorMessage(options,
|
|
881
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.UpdateEntity, `pgaccesslayer:UpdateEntity(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
885
882
|
}
|
|
886
883
|
}
|
|
887
884
|
async PatchEntity(options, entity) {
|
|
@@ -890,10 +887,10 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
890
887
|
try {
|
|
891
888
|
await client.query('BEGIN');
|
|
892
889
|
const currentEntity = await this.#__GetEntity(client, options);
|
|
893
|
-
if (currentEntity.status ===
|
|
890
|
+
if (currentEntity.status === StatusCodes.OK) {
|
|
894
891
|
const updatedRecord = { ...currentEntity.detail.entvalue, ...entity };
|
|
895
|
-
const retVal = await this.#__UpdateEntity(client, options,
|
|
896
|
-
if (retVal.status ===
|
|
892
|
+
const retVal = await this.#__UpdateEntity(client, options, eOperations.PatchEntity, updatedRecord);
|
|
893
|
+
if (retVal.status === StatusCodes.OK) {
|
|
897
894
|
await client.query('COMMIT');
|
|
898
895
|
}
|
|
899
896
|
else {
|
|
@@ -908,14 +905,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
908
905
|
}
|
|
909
906
|
catch (error) {
|
|
910
907
|
await client.query('ROLLBACK');
|
|
911
|
-
return this.#LogAndGetErrorMessage(options,
|
|
908
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.PatchEntity, `pgaccesslayer:PatchEntity(): Operation was not successful (__GetEntity). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
912
909
|
}
|
|
913
910
|
finally {
|
|
914
911
|
client.release();
|
|
915
912
|
}
|
|
916
913
|
}
|
|
917
914
|
catch (error) {
|
|
918
|
-
return this.#LogAndGetErrorMessage(options,
|
|
915
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.PatchEntity, `pgaccesslayer:PatchEntity(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
919
916
|
}
|
|
920
917
|
}
|
|
921
918
|
async #__DeleteEntity(client, options, operation) {
|
|
@@ -933,7 +930,7 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
933
930
|
dbResponse.resourceoid = dbResponse.resourceoid.toString();
|
|
934
931
|
dbResponse.entvalue = this.#JSONParse(dbResponse.entvalue);
|
|
935
932
|
return {
|
|
936
|
-
status:
|
|
933
|
+
status: StatusCodes.OK,
|
|
937
934
|
detail: dbResponse,
|
|
938
935
|
options,
|
|
939
936
|
operation
|
|
@@ -941,15 +938,15 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
941
938
|
}
|
|
942
939
|
catch (error) {
|
|
943
940
|
if (error.code === 'P0002') {
|
|
944
|
-
return this.#LogAndGetErrorMessage(options,
|
|
941
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.NOT_FOUND, eOperations.DeleteEntity, `resname: [${options.filters?.resname}], entname: [${options.filters?.entname}] not found or not current. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
945
942
|
}
|
|
946
943
|
else {
|
|
947
|
-
return this.#LogAndGetErrorMessage(options,
|
|
944
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteEntity, `pgaccesslayer:__DeleteEntity(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
948
945
|
}
|
|
949
946
|
}
|
|
950
947
|
}
|
|
951
948
|
catch (error) {
|
|
952
|
-
return this.#LogAndGetErrorMessage(options,
|
|
949
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteEntity, `pgaccesslayer:__DeleteEntity(): Operation was not successful (__GetEntity). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
953
950
|
}
|
|
954
951
|
}
|
|
955
952
|
async DeleteEntity(options) {
|
|
@@ -957,8 +954,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
957
954
|
const client = await this.#poolManager?.connectReadWrite();
|
|
958
955
|
try {
|
|
959
956
|
await client.query('BEGIN');
|
|
960
|
-
const retVal = await this.#__DeleteEntity(client, options,
|
|
961
|
-
if (retVal.status ===
|
|
957
|
+
const retVal = await this.#__DeleteEntity(client, options, eOperations.DeleteEntity);
|
|
958
|
+
if (retVal.status === StatusCodes.OK) {
|
|
962
959
|
await client.query('COMMIT');
|
|
963
960
|
}
|
|
964
961
|
else {
|
|
@@ -968,14 +965,14 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
968
965
|
}
|
|
969
966
|
catch (error) {
|
|
970
967
|
await client.query('ROLLBACK');
|
|
971
|
-
return this.#LogAndGetErrorMessage(options,
|
|
968
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteEntity, `pgaccesslayer:DeleteEntity(): Operation was not successful (__GetEntity). Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
972
969
|
}
|
|
973
970
|
finally {
|
|
974
971
|
client.release();
|
|
975
972
|
}
|
|
976
973
|
}
|
|
977
974
|
catch (error) {
|
|
978
|
-
return this.#LogAndGetErrorMessage(options,
|
|
975
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.DeleteEntity, `pgaccesslayer:DeleteEntity(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
979
976
|
}
|
|
980
977
|
}
|
|
981
978
|
async GetResources(options) {
|
|
@@ -1003,21 +1000,21 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
1003
1000
|
r.resdesc = this.#JSONParse(r.resdesc);
|
|
1004
1001
|
});
|
|
1005
1002
|
return {
|
|
1006
|
-
status:
|
|
1003
|
+
status: StatusCodes.OK,
|
|
1007
1004
|
detail: dbResponse,
|
|
1008
1005
|
options: useOptions,
|
|
1009
|
-
operation:
|
|
1006
|
+
operation: eOperations.GetResources
|
|
1010
1007
|
};
|
|
1011
1008
|
}
|
|
1012
1009
|
catch (error) {
|
|
1013
|
-
return this.#LogAndGetErrorMessage(useOptions,
|
|
1010
|
+
return this.#LogAndGetErrorMessage(useOptions, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResources, `pgaccesslayer:GetResources(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
1014
1011
|
}
|
|
1015
1012
|
finally {
|
|
1016
1013
|
client.release();
|
|
1017
1014
|
}
|
|
1018
1015
|
}
|
|
1019
1016
|
catch (error) {
|
|
1020
|
-
return this.#LogAndGetErrorMessage(useOptions,
|
|
1017
|
+
return this.#LogAndGetErrorMessage(useOptions, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResources, `pgaccesslayer:GetResources(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
1021
1018
|
}
|
|
1022
1019
|
}
|
|
1023
1020
|
async GetEntities(options) {
|
|
@@ -1052,25 +1049,25 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
1052
1049
|
r.entvalue = this.#JSONParse(r.entvalue);
|
|
1053
1050
|
});
|
|
1054
1051
|
return {
|
|
1055
|
-
status:
|
|
1052
|
+
status: StatusCodes.OK,
|
|
1056
1053
|
detail: dbResponse,
|
|
1057
1054
|
options,
|
|
1058
|
-
operation:
|
|
1055
|
+
operation: eOperations.GetEntities
|
|
1059
1056
|
};
|
|
1060
1057
|
}
|
|
1061
1058
|
catch (error) {
|
|
1062
|
-
return this.#LogAndGetErrorMessage(options,
|
|
1059
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntities, `pgaccesslayer:GetEntities(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
1063
1060
|
}
|
|
1064
1061
|
finally {
|
|
1065
1062
|
client.release();
|
|
1066
1063
|
}
|
|
1067
1064
|
}
|
|
1068
1065
|
else {
|
|
1069
|
-
return this.#LogAndGetErrorMessage(options,
|
|
1066
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntities, `pgaccesslayer:GetEntities(): Required filters: [${JSON.stringify(requiredFields)}] not specified.`);
|
|
1070
1067
|
}
|
|
1071
1068
|
}
|
|
1072
1069
|
catch (error) {
|
|
1073
|
-
return this.#LogAndGetErrorMessage(options,
|
|
1070
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetEntities, `pgaccesslayer:GetEntities(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
1074
1071
|
}
|
|
1075
1072
|
}
|
|
1076
1073
|
async #__SearchResources(client, options, searchOptions) {
|
|
@@ -1104,18 +1101,18 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
1104
1101
|
dbResponse = rows;
|
|
1105
1102
|
}
|
|
1106
1103
|
return {
|
|
1107
|
-
status:
|
|
1104
|
+
status: StatusCodes.OK,
|
|
1108
1105
|
detail: dbResponse,
|
|
1109
1106
|
options: useOptions,
|
|
1110
|
-
operation:
|
|
1107
|
+
operation: eOperations.GetResources
|
|
1111
1108
|
};
|
|
1112
1109
|
}
|
|
1113
1110
|
catch (error) {
|
|
1114
|
-
return this.#LogAndGetErrorMessage(useOptions,
|
|
1111
|
+
return this.#LogAndGetErrorMessage(useOptions, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResources, `pgaccesslayer:GetResources(): Operation was not successful. Error: [${this.#ToErrorWithMessage(error).message}]`);
|
|
1115
1112
|
}
|
|
1116
1113
|
}
|
|
1117
1114
|
catch (error) {
|
|
1118
|
-
return this.#LogAndGetErrorMessage(options,
|
|
1115
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.GetResource, `pgaccesslayer:__SearchResources(): Operation was not successful (outer). Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
1119
1116
|
}
|
|
1120
1117
|
}
|
|
1121
1118
|
async SearchResources(options, searchOptions) {
|
|
@@ -1132,9 +1129,8 @@ class PGAccessLayer extends tiny_emitter_1.TinyEmitter {
|
|
|
1132
1129
|
return retVal;
|
|
1133
1130
|
}
|
|
1134
1131
|
catch (error) {
|
|
1135
|
-
return this.#LogAndGetErrorMessage(options,
|
|
1132
|
+
return this.#LogAndGetErrorMessage(options, StatusCodes.INTERNAL_SERVER_ERROR, eOperations.SearchResources, `pgaccesslayer:SearchResource(): Could not get client from pool. Error: [${this.#ToErrorWithMessage(error).message}}]`);
|
|
1136
1133
|
}
|
|
1137
1134
|
}
|
|
1138
1135
|
}
|
|
1139
|
-
exports.PGAccessLayer = PGAccessLayer;
|
|
1140
1136
|
//# sourceMappingURL=pgaccesslayer.js.map
|