@nsshunt/stsdatamanagement 1.14.0 → 1.14.1
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/dberrors.js +7 -7
- package/dist/dberrors.js +9 -7
- package/dist/dberrors.js.map +1 -1
- package/dist/pgaccesslayer.js +64 -62
- package/dist/pgaccesslayer.js.map +1 -1
- package/package.json +2 -1
- package/pgaccesslayer.js +63 -62
- package/types/dbaccess.d.ts +0 -7
- package/types/dberrors.d.ts +1 -44
- package/types/dberrors.d.ts.map +1 -1
- package/types/pgaccesslayer.d.ts +1 -191
- package/types/pgaccesslayer.d.ts.map +1 -1
package/dberrors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { StatusCodes } from 'http-status-codes';
|
|
2
2
|
|
|
3
3
|
// https://rclayton.silvrback.com/custom-errors-in-node-js
|
|
4
4
|
class STSDataManagementError extends Error {
|
|
@@ -14,7 +14,7 @@ class STSDataManagementError extends Error {
|
|
|
14
14
|
Error.captureStackTrace(this, this.constructor);
|
|
15
15
|
|
|
16
16
|
this.detail = null;
|
|
17
|
-
this.status =
|
|
17
|
+
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ class STSResourceNotFoundError extends STSDataManagementError {
|
|
|
25
25
|
resourceId,
|
|
26
26
|
resource
|
|
27
27
|
}
|
|
28
|
-
this.status =
|
|
28
|
+
this.status = StatusCodes.NOT_FOUND;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -39,7 +39,7 @@ class STSResourceMalformedError extends STSDataManagementError {
|
|
|
39
39
|
error,
|
|
40
40
|
extraDetail
|
|
41
41
|
}
|
|
42
|
-
this.status =
|
|
42
|
+
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -51,7 +51,7 @@ class STSDatabaseAccessError extends STSDataManagementError {
|
|
|
51
51
|
resource,
|
|
52
52
|
error
|
|
53
53
|
}
|
|
54
|
-
this.status =
|
|
54
|
+
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -62,7 +62,7 @@ class STSInvalidCredentials extends STSDataManagementError {
|
|
|
62
62
|
resourceId,
|
|
63
63
|
resource,
|
|
64
64
|
}
|
|
65
|
-
this.status =
|
|
65
|
+
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -73,7 +73,7 @@ class STSNotAuthorized extends STSDataManagementError {
|
|
|
73
73
|
clientId,
|
|
74
74
|
audience
|
|
75
75
|
}
|
|
76
|
-
this.status =
|
|
76
|
+
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
package/dist/dberrors.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
2
4
|
// https://rclayton.silvrback.com/custom-errors-in-node-js
|
|
3
5
|
class STSDataManagementError extends Error {
|
|
4
6
|
constructor(message) {
|
|
@@ -10,7 +12,7 @@ class STSDataManagementError extends Error {
|
|
|
10
12
|
// @see Node.js reference (bottom)
|
|
11
13
|
Error.captureStackTrace(this, this.constructor);
|
|
12
14
|
this.detail = null;
|
|
13
|
-
this.status =
|
|
15
|
+
this.status = http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
class STSResourceNotFoundError extends STSDataManagementError {
|
|
@@ -20,7 +22,7 @@ class STSResourceNotFoundError extends STSDataManagementError {
|
|
|
20
22
|
resourceId,
|
|
21
23
|
resource
|
|
22
24
|
};
|
|
23
|
-
this.status =
|
|
25
|
+
this.status = http_status_codes_1.StatusCodes.NOT_FOUND;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
class STSResourceMalformedError extends STSDataManagementError {
|
|
@@ -33,7 +35,7 @@ class STSResourceMalformedError extends STSDataManagementError {
|
|
|
33
35
|
error,
|
|
34
36
|
extraDetail
|
|
35
37
|
};
|
|
36
|
-
this.status =
|
|
38
|
+
this.status = http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
class STSDatabaseAccessError extends STSDataManagementError {
|
|
@@ -44,7 +46,7 @@ class STSDatabaseAccessError extends STSDataManagementError {
|
|
|
44
46
|
resource,
|
|
45
47
|
error
|
|
46
48
|
};
|
|
47
|
-
this.status =
|
|
49
|
+
this.status = http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
class STSInvalidCredentials extends STSDataManagementError {
|
|
@@ -54,7 +56,7 @@ class STSInvalidCredentials extends STSDataManagementError {
|
|
|
54
56
|
resourceId,
|
|
55
57
|
resource,
|
|
56
58
|
};
|
|
57
|
-
this.status =
|
|
59
|
+
this.status = http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
class STSNotAuthorized extends STSDataManagementError {
|
|
@@ -64,7 +66,7 @@ class STSNotAuthorized extends STSDataManagementError {
|
|
|
64
66
|
clientId,
|
|
65
67
|
audience
|
|
66
68
|
};
|
|
67
|
-
this.status =
|
|
69
|
+
this.status = http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR;
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
module.exports = {
|
package/dist/dberrors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dberrors.js","sourceRoot":"","sources":["../dberrors.js"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"dberrors.js","sourceRoot":"","sources":["../dberrors.js"],"names":[],"mappings":";;AAAA,yDAAgD;AAEhD,0DAA0D;AAC1D,MAAM,sBAAuB,SAAQ,KAAK;IACzC,YAAY,OAAO;QAClB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,8DAA8D;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAElC,8DAA8D;QAC9D,kFAAkF;QAClF,mCAAmC;QACnC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,qBAAqB,CAAC;IACjD,CAAC;CACD;AAED,MAAM,wBAAyB,SAAQ,sBAAsB;IAC5D,YAAY,QAAQ,EAAE,UAAU;QAC/B,KAAK,CAAC,aAAa,QAAQ,0BAA0B,UAAU,GAAG,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,GAAG;YACb,UAAU;YACV,QAAQ;SACR,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,SAAS,CAAC;IACrC,CAAC;CACD;AAED,MAAM,yBAA0B,SAAQ,sBAAsB;IAC7D,YAAY,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW;QAChE,KAAK,CAAC,aAAa,QAAQ,IAAI,UAAU,iBAAiB,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG;YACb,UAAU;YACV,QAAQ;YACR,WAAW;YACX,KAAK;YACL,WAAW;SACX,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,qBAAqB,CAAC;IACjD,CAAC;CACD;AAED,MAAM,sBAAuB,SAAQ,sBAAsB;IAC1D,YAAY,QAAQ,EAAE,UAAU,EAAE,KAAK;QACtC,KAAK,CAAC,4CAA4C,QAAQ,IAAI,UAAU,GAAG,CAAC,CAAC;QAC7E,IAAI,CAAC,MAAM,GAAG;YACb,UAAU;YACV,QAAQ;YACR,KAAK;SACL,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,qBAAqB,CAAC;IACjD,CAAC;CACD;AAED,MAAM,qBAAsB,SAAQ,sBAAsB;IACzD,YAAY,QAAQ,EAAE,UAAU;QAC/B,KAAK,CAAC,sCAAsC,QAAQ,IAAI,UAAU,GAAG,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,GAAG;YACb,UAAU;YACV,QAAQ;SACR,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,qBAAqB,CAAC;IACjD,CAAC;CACD;AAED,MAAM,gBAAiB,SAAQ,sBAAsB;IACpD,YAAY,QAAQ,EAAE,QAAQ;QAC7B,KAAK,CAAC,oBAAoB,QAAQ,IAAI,QAAQ,GAAG,CAAC,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG;YACb,QAAQ;YACR,QAAQ;SACR,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,qBAAqB,CAAC;IACjD,CAAC;CACD;AAED,MAAM,CAAC,OAAO,GAAG;IAChB,sBAAsB,EAAE,wBAAwB,EAAE,yBAAyB;IAC3E,sBAAsB,EAAE,qBAAqB,EAAE,gBAAgB;CAC/D,CAAA"}
|
package/dist/pgaccesslayer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,7 +20,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
21
|
};
|
|
21
22
|
var _PGAccessLayer_instances, _PGAccessLayer_cache, _PGAccessLayer_pgpool, _PGAccessLayer_logger, _PGAccessLayer_poolManager, _PGAccessLayer_latestResourceVersion, _PGAccessLayer_buildQueryString;
|
|
22
|
-
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
23
25
|
const Redis = require('ioredis');
|
|
24
26
|
const { redisPort, redisServer, useRedis, endFlush, consoleLogErrors } = require('@nsshunt/stsconfig').$options;
|
|
25
27
|
const copyFrom = require('pg-copy-streams').from;
|
|
@@ -48,7 +50,7 @@ class PGAccessLayer {
|
|
|
48
50
|
saveResource(userid, resid, data) {
|
|
49
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
52
|
let retVal = yield this.getLatestResource(resid);
|
|
51
|
-
if (retVal.status !==
|
|
53
|
+
if (retVal.status !== http_status_codes_1.StatusCodes.OK) {
|
|
52
54
|
return yield this.createResource(userid, resid, data);
|
|
53
55
|
}
|
|
54
56
|
else {
|
|
@@ -79,10 +81,10 @@ class PGAccessLayer {
|
|
|
79
81
|
try {
|
|
80
82
|
const { rows } = yield client.query(createQuery);
|
|
81
83
|
const dbResponse = rows[0];
|
|
82
|
-
return { status:
|
|
84
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
83
85
|
}
|
|
84
86
|
catch (error) {
|
|
85
|
-
return { status:
|
|
87
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
86
88
|
}
|
|
87
89
|
finally {
|
|
88
90
|
client.release();
|
|
@@ -92,7 +94,7 @@ class PGAccessLayer {
|
|
|
92
94
|
// Error getting the client connection from the pool
|
|
93
95
|
if (consoleLogErrors)
|
|
94
96
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
95
|
-
return { status:
|
|
97
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
96
98
|
}
|
|
97
99
|
});
|
|
98
100
|
}
|
|
@@ -113,15 +115,15 @@ class PGAccessLayer {
|
|
|
113
115
|
const { rows } = yield client.query(createQuery, values);
|
|
114
116
|
const dbResponse = rows[0];
|
|
115
117
|
yield client.query('COMMIT');
|
|
116
|
-
return { status:
|
|
118
|
+
return { status: http_status_codes_1.StatusCodes.CREATED, detail: dbResponse };
|
|
117
119
|
}
|
|
118
120
|
catch (error) {
|
|
119
121
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
120
122
|
__classPrivateFieldGet(this, _PGAccessLayer_logger, "f").LogMessage(error);
|
|
121
123
|
yield client.query('ROLLBACK');
|
|
122
|
-
let err = { status:
|
|
124
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
123
125
|
if (error.code === '23505') {
|
|
124
|
-
err = { status:
|
|
126
|
+
err = { status: http_status_codes_1.StatusCodes.CONFLICT, error: `[${fname}: resourceid [${resourceid}] already exists`, detail: error };
|
|
125
127
|
}
|
|
126
128
|
return err;
|
|
127
129
|
}
|
|
@@ -133,7 +135,7 @@ class PGAccessLayer {
|
|
|
133
135
|
// Error getting the client connection from the pool
|
|
134
136
|
if (consoleLogErrors)
|
|
135
137
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
136
|
-
return { status:
|
|
138
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
137
139
|
}
|
|
138
140
|
});
|
|
139
141
|
}
|
|
@@ -149,7 +151,7 @@ class PGAccessLayer {
|
|
|
149
151
|
// Error getting the client connection from the pool
|
|
150
152
|
if (consoleLogErrors)
|
|
151
153
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
152
|
-
return { status:
|
|
154
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
153
155
|
}
|
|
154
156
|
});
|
|
155
157
|
}
|
|
@@ -164,7 +166,7 @@ class PGAccessLayer {
|
|
|
164
166
|
// Error getting the client connection from the pool
|
|
165
167
|
if (consoleLogErrors)
|
|
166
168
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
167
|
-
return { status:
|
|
169
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
168
170
|
}
|
|
169
171
|
});
|
|
170
172
|
}
|
|
@@ -179,7 +181,7 @@ class PGAccessLayer {
|
|
|
179
181
|
// Error getting the client connection from the pool
|
|
180
182
|
if (consoleLogErrors)
|
|
181
183
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
182
|
-
return { status:
|
|
184
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
183
185
|
}
|
|
184
186
|
});
|
|
185
187
|
}
|
|
@@ -195,14 +197,14 @@ class PGAccessLayer {
|
|
|
195
197
|
try {
|
|
196
198
|
const { rows } = yield client.query(createQuery, values);
|
|
197
199
|
const dbResponse = rows[0];
|
|
198
|
-
return { status:
|
|
200
|
+
return { status: http_status_codes_1.StatusCodes.CREATED, detail: dbResponse };
|
|
199
201
|
}
|
|
200
202
|
catch (error) {
|
|
201
203
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
202
204
|
__classPrivateFieldGet(this, _PGAccessLayer_logger, "f").LogMessage(error);
|
|
203
|
-
let err = { status:
|
|
205
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
204
206
|
if (error.code === '23505') {
|
|
205
|
-
err = { status:
|
|
207
|
+
err = { status: http_status_codes_1.StatusCodes.CONFLICT, error: `[${fname}: resourceid [${resourceid}] already exists`, detail: error };
|
|
206
208
|
}
|
|
207
209
|
return err;
|
|
208
210
|
}
|
|
@@ -230,7 +232,7 @@ class PGAccessLayer {
|
|
|
230
232
|
if (__classPrivateFieldGet(this, _PGAccessLayer_cache, "f") !== null) {
|
|
231
233
|
yield __classPrivateFieldGet(this, _PGAccessLayer_cache, "f").del(resourceid);
|
|
232
234
|
}
|
|
233
|
-
return { status:
|
|
235
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
234
236
|
}
|
|
235
237
|
catch (error) {
|
|
236
238
|
if (consoleLogErrors) {
|
|
@@ -238,9 +240,9 @@ class PGAccessLayer {
|
|
|
238
240
|
__classPrivateFieldGet(this, _PGAccessLayer_logger, "f").LogMessage(error);
|
|
239
241
|
}
|
|
240
242
|
yield client.query('ROLLBACK');
|
|
241
|
-
let err = { status:
|
|
243
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
242
244
|
if (error.code === 'P0002') {
|
|
243
|
-
err = { status:
|
|
245
|
+
err = { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}] and version [${resourcevnum}] not found or not current`, detail: error };
|
|
244
246
|
}
|
|
245
247
|
if (consoleLogErrors) {
|
|
246
248
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
@@ -256,7 +258,7 @@ class PGAccessLayer {
|
|
|
256
258
|
// Error getting the client connection from the pool
|
|
257
259
|
if (consoleLogErrors)
|
|
258
260
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
259
|
-
return { status:
|
|
261
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
260
262
|
}
|
|
261
263
|
});
|
|
262
264
|
}
|
|
@@ -264,7 +266,7 @@ class PGAccessLayer {
|
|
|
264
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
267
|
const fname = 'deleteLatestResource';
|
|
266
268
|
let retVal = yield this.getLatestResource(resid);
|
|
267
|
-
if (retVal.status !==
|
|
269
|
+
if (retVal.status !== http_status_codes_1.StatusCodes.OK) {
|
|
268
270
|
return { status: retVal.status, error: `[${fname}]: Operation was not successful: [${resid}]`, detail: retVal };
|
|
269
271
|
}
|
|
270
272
|
else {
|
|
@@ -294,13 +296,13 @@ class PGAccessLayer {
|
|
|
294
296
|
if (__classPrivateFieldGet(this, _PGAccessLayer_cache, "f") !== null) {
|
|
295
297
|
yield __classPrivateFieldGet(this, _PGAccessLayer_cache, "f").del(resourceid);
|
|
296
298
|
}
|
|
297
|
-
return { status:
|
|
299
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
298
300
|
}
|
|
299
301
|
catch (error) {
|
|
300
302
|
yield client.query('ROLLBACK');
|
|
301
|
-
let err = { status:
|
|
303
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
302
304
|
if (error.code === 'P0002') {
|
|
303
|
-
err = { status:
|
|
305
|
+
err = { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}] and version [${resourcevnum}] not found or not current`, detail: error };
|
|
304
306
|
}
|
|
305
307
|
if (consoleLogErrors) {
|
|
306
308
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
@@ -316,7 +318,7 @@ class PGAccessLayer {
|
|
|
316
318
|
// Error getting the client connection from the pool
|
|
317
319
|
if (consoleLogErrors)
|
|
318
320
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
319
|
-
return { status:
|
|
321
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
320
322
|
}
|
|
321
323
|
});
|
|
322
324
|
}
|
|
@@ -338,13 +340,13 @@ class PGAccessLayer {
|
|
|
338
340
|
const { rows } = yield client.query(createQuery, values);
|
|
339
341
|
const dbResponse = rows[0];
|
|
340
342
|
yield client.query('COMMIT');
|
|
341
|
-
return { status:
|
|
343
|
+
return { status: http_status_codes_1.StatusCodes.CREATED, detail: dbResponse };
|
|
342
344
|
}
|
|
343
345
|
catch (error) {
|
|
344
346
|
yield client.query('ROLLBACK');
|
|
345
|
-
let err = { status:
|
|
347
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
346
348
|
if (error.code === '23505') {
|
|
347
|
-
err = { status:
|
|
349
|
+
err = { status: http_status_codes_1.StatusCodes.CONFLICT, error: `[${fname}: entityid [${entityid}] already exists`, detail: error };
|
|
348
350
|
}
|
|
349
351
|
return err;
|
|
350
352
|
}
|
|
@@ -356,7 +358,7 @@ class PGAccessLayer {
|
|
|
356
358
|
// Error getting the client connection from the pool
|
|
357
359
|
if (consoleLogErrors)
|
|
358
360
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
359
|
-
return { status:
|
|
361
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
360
362
|
}
|
|
361
363
|
});
|
|
362
364
|
}
|
|
@@ -379,13 +381,13 @@ class PGAccessLayer {
|
|
|
379
381
|
const { rows } = yield client.query(createQuery, values);
|
|
380
382
|
const dbResponse = rows[0];
|
|
381
383
|
yield client.query('COMMIT');
|
|
382
|
-
return { status:
|
|
384
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
383
385
|
}
|
|
384
386
|
catch (error) {
|
|
385
387
|
yield client.query('ROLLBACK');
|
|
386
|
-
let err = { status:
|
|
388
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
387
389
|
if (error.code === 'P0002') {
|
|
388
|
-
err = { status:
|
|
390
|
+
err = { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}:${resourcevnum}], entityid [${entityid}:${entityvnum}] not found or not current`, detail: error };
|
|
389
391
|
}
|
|
390
392
|
if (consoleLogErrors) {
|
|
391
393
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
@@ -401,7 +403,7 @@ class PGAccessLayer {
|
|
|
401
403
|
// Error getting the client connection from the pool
|
|
402
404
|
if (consoleLogErrors)
|
|
403
405
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
404
|
-
return { status:
|
|
406
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
405
407
|
}
|
|
406
408
|
});
|
|
407
409
|
}
|
|
@@ -423,13 +425,13 @@ class PGAccessLayer {
|
|
|
423
425
|
const { rows } = yield client.query(createQuery, values);
|
|
424
426
|
const dbResponse = rows[0];
|
|
425
427
|
yield client.query('COMMIT');
|
|
426
|
-
return { status:
|
|
428
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
427
429
|
}
|
|
428
430
|
catch (error) {
|
|
429
431
|
yield client.query('ROLLBACK');
|
|
430
|
-
let err = { status:
|
|
432
|
+
let err = { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default
|
|
431
433
|
if (error.code === 'P0002') {
|
|
432
|
-
err = { status:
|
|
434
|
+
err = { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}:${resourcevnum}], entityid [${entityid}:${entityvnum}] not found or not current`, detail: error };
|
|
433
435
|
}
|
|
434
436
|
if (consoleLogErrors) {
|
|
435
437
|
if (__classPrivateFieldGet(this, _PGAccessLayer_logger, "f") !== null)
|
|
@@ -445,7 +447,7 @@ class PGAccessLayer {
|
|
|
445
447
|
// Error getting the client connection from the pool
|
|
446
448
|
if (consoleLogErrors)
|
|
447
449
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
448
|
-
return { status:
|
|
450
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
449
451
|
}
|
|
450
452
|
});
|
|
451
453
|
}
|
|
@@ -467,7 +469,7 @@ class PGAccessLayer {
|
|
|
467
469
|
let cacheVal = yield __classPrivateFieldGet(this, _PGAccessLayer_cache, "f").get(resourceid);
|
|
468
470
|
if (cacheVal !== null) {
|
|
469
471
|
let cacheResponse = JSON.parse(cacheVal);
|
|
470
|
-
return { status:
|
|
472
|
+
return { status: http_status_codes_1.StatusCodes.OK, usedcache: true, detail: cacheResponse };
|
|
471
473
|
}
|
|
472
474
|
}
|
|
473
475
|
}
|
|
@@ -476,19 +478,19 @@ class PGAccessLayer {
|
|
|
476
478
|
try {
|
|
477
479
|
const { rows } = yield client.query(query, values);
|
|
478
480
|
if (rows.length === 0) {
|
|
479
|
-
return { status:
|
|
481
|
+
return { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}] (current version) not found`, detail: null };
|
|
480
482
|
}
|
|
481
483
|
if (rows.length > 1) {
|
|
482
|
-
return { status:
|
|
484
|
+
return { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`, detail: null };
|
|
483
485
|
}
|
|
484
486
|
const dbResponse = rows[0];
|
|
485
487
|
if (__classPrivateFieldGet(this, _PGAccessLayer_cache, "f") !== null) {
|
|
486
488
|
__classPrivateFieldGet(this, _PGAccessLayer_cache, "f").set(resourceid, JSON.stringify(dbResponse));
|
|
487
489
|
}
|
|
488
|
-
return { status:
|
|
490
|
+
return { status: http_status_codes_1.StatusCodes.OK, usedcache: false, detail: dbResponse };
|
|
489
491
|
}
|
|
490
492
|
catch (error) {
|
|
491
|
-
return { status:
|
|
493
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default;
|
|
492
494
|
}
|
|
493
495
|
finally {
|
|
494
496
|
client.release();
|
|
@@ -498,7 +500,7 @@ class PGAccessLayer {
|
|
|
498
500
|
// Error getting the client connection from the pool
|
|
499
501
|
if (consoleLogErrors)
|
|
500
502
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
501
|
-
return { status:
|
|
503
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
502
504
|
}
|
|
503
505
|
});
|
|
504
506
|
}
|
|
@@ -521,16 +523,16 @@ class PGAccessLayer {
|
|
|
521
523
|
try {
|
|
522
524
|
const { rows } = yield client.query(query, values);
|
|
523
525
|
if (rows.length === 0) {
|
|
524
|
-
return { status:
|
|
526
|
+
return { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: resourceid [${resourceid}] (current version) not found`, detail: null };
|
|
525
527
|
}
|
|
526
528
|
if (rows.length > 1) {
|
|
527
|
-
return { status:
|
|
529
|
+
return { status: http_status_codes_1.StatusCodes.NOT_FOUND, error: `[${fname}: Multiple resourceid [${resourceid}](current version) exist within database. Invalid database state.`, detail: null };
|
|
528
530
|
}
|
|
529
531
|
const dbResponse = rows[0];
|
|
530
|
-
return { status:
|
|
532
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
531
533
|
}
|
|
532
534
|
catch (error) {
|
|
533
|
-
return { status:
|
|
535
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default;
|
|
534
536
|
}
|
|
535
537
|
finally {
|
|
536
538
|
client.release();
|
|
@@ -540,7 +542,7 @@ class PGAccessLayer {
|
|
|
540
542
|
// Error getting the client connection from the pool
|
|
541
543
|
if (consoleLogErrors)
|
|
542
544
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
543
|
-
return { status:
|
|
545
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
544
546
|
}
|
|
545
547
|
});
|
|
546
548
|
}
|
|
@@ -563,10 +565,10 @@ class PGAccessLayer {
|
|
|
563
565
|
try {
|
|
564
566
|
const { rows } = yield client.query(query, values);
|
|
565
567
|
const dbResponse = rows;
|
|
566
|
-
return { status:
|
|
568
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
567
569
|
}
|
|
568
570
|
catch (error) {
|
|
569
|
-
return { status:
|
|
571
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default;
|
|
570
572
|
}
|
|
571
573
|
finally {
|
|
572
574
|
client.release();
|
|
@@ -576,7 +578,7 @@ class PGAccessLayer {
|
|
|
576
578
|
// Error getting the client connection from the pool
|
|
577
579
|
if (consoleLogErrors)
|
|
578
580
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
579
|
-
return { status:
|
|
581
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
580
582
|
}
|
|
581
583
|
});
|
|
582
584
|
}
|
|
@@ -597,10 +599,10 @@ class PGAccessLayer {
|
|
|
597
599
|
try {
|
|
598
600
|
const { rows } = yield client.query(query, values);
|
|
599
601
|
const dbResponse = rows;
|
|
600
|
-
return { status:
|
|
602
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
601
603
|
}
|
|
602
604
|
catch (error) {
|
|
603
|
-
return { status:
|
|
605
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error }; // Set default;
|
|
604
606
|
}
|
|
605
607
|
finally {
|
|
606
608
|
client.release();
|
|
@@ -610,7 +612,7 @@ class PGAccessLayer {
|
|
|
610
612
|
// Error getting the client connection from the pool
|
|
611
613
|
if (consoleLogErrors)
|
|
612
614
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
613
|
-
return { status:
|
|
615
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
614
616
|
}
|
|
615
617
|
});
|
|
616
618
|
}
|
|
@@ -625,13 +627,13 @@ class PGAccessLayer {
|
|
|
625
627
|
yield client.query('BEGIN');
|
|
626
628
|
yield client.query(query, values);
|
|
627
629
|
yield client.query('COMMIT');
|
|
628
|
-
return { status:
|
|
630
|
+
return { status: http_status_codes_1.StatusCodes.OK };
|
|
629
631
|
}
|
|
630
632
|
catch (error) {
|
|
631
633
|
if (consoleLogErrors)
|
|
632
634
|
console.error(`[${fname}]: Failed to delete resources: ${error}`);
|
|
633
635
|
yield client.query('ROLLBACK');
|
|
634
|
-
return { status:
|
|
636
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
635
637
|
}
|
|
636
638
|
finally {
|
|
637
639
|
client.release();
|
|
@@ -641,7 +643,7 @@ class PGAccessLayer {
|
|
|
641
643
|
// Error getting the client connection from the pool
|
|
642
644
|
if (consoleLogErrors)
|
|
643
645
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
644
|
-
return { status:
|
|
646
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
645
647
|
}
|
|
646
648
|
});
|
|
647
649
|
}
|
|
@@ -656,13 +658,13 @@ class PGAccessLayer {
|
|
|
656
658
|
yield client.query('BEGIN');
|
|
657
659
|
yield client.query(query);
|
|
658
660
|
yield client.query('COMMIT');
|
|
659
|
-
return { status:
|
|
661
|
+
return { status: http_status_codes_1.StatusCodes.OK };
|
|
660
662
|
}
|
|
661
663
|
catch (error) {
|
|
662
664
|
if (consoleLogErrors)
|
|
663
665
|
console.error(`[${fname}]: Failed to truncate table(s): ${error}`);
|
|
664
666
|
yield client.query('ROLLBACK');
|
|
665
|
-
return { status:
|
|
667
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
666
668
|
}
|
|
667
669
|
finally {
|
|
668
670
|
client.release();
|
|
@@ -672,7 +674,7 @@ class PGAccessLayer {
|
|
|
672
674
|
// Error getting the client connection from the pool
|
|
673
675
|
if (consoleLogErrors)
|
|
674
676
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
675
|
-
return { status:
|
|
677
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
676
678
|
}
|
|
677
679
|
});
|
|
678
680
|
}
|
|
@@ -686,13 +688,13 @@ class PGAccessLayer {
|
|
|
686
688
|
const query = "select count(*) from stsresource";
|
|
687
689
|
const { rows } = yield client.query(query);
|
|
688
690
|
const dbResponse = rows[0];
|
|
689
|
-
return { status:
|
|
691
|
+
return { status: http_status_codes_1.StatusCodes.OK, detail: dbResponse };
|
|
690
692
|
}
|
|
691
693
|
catch (error) {
|
|
692
694
|
if (consoleLogErrors)
|
|
693
695
|
console.error(`[${fname}]: Could not get count from stsresource table: ${error}`);
|
|
694
696
|
yield client.query('ROLLBACK');
|
|
695
|
-
return { status:
|
|
697
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
696
698
|
}
|
|
697
699
|
finally {
|
|
698
700
|
client.release();
|
|
@@ -702,7 +704,7 @@ class PGAccessLayer {
|
|
|
702
704
|
// Error getting the client connection from the pool
|
|
703
705
|
if (consoleLogErrors)
|
|
704
706
|
console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
705
|
-
return { status:
|
|
707
|
+
return { status: http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
706
708
|
}
|
|
707
709
|
});
|
|
708
710
|
}
|