@ejfdelgado/ejflab-common 1.7.2 → 1.7.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.7.2",
4
+ "version": "1.7.4",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
@@ -8,12 +8,18 @@ class CommandPostgres extends CommandBasic {
8
8
  const bodyPath = this.args[2];
9
9
  //srv/wideSight/sql/writes/object.sql
10
10
  const script = this.args[3];
11
+ const destination = this.args[4];
11
12
  const postgresSrv = this.context.getSuperContext().getPostgresClient();
12
13
  if (action == "execute") {
13
14
  //console.log("Starting execute...");
14
15
  const dbIdData = SimpleObj.getValue(this.context.data, dbIdPath, null);
15
- let bodyData = SimpleObj.getValue(this.context.data, bodyPath, null);
16
- bodyData = JSON.parse(JSON.stringify(bodyData));
16
+ let bodyData = {};
17
+ if (typeof bodyPath == "string") {
18
+ bodyData = SimpleObj.getValue(this.context.data, bodyPath, {});
19
+ bodyData = JSON.parse(JSON.stringify(bodyData));
20
+ } else if (typeof bodyPath == "object" && bodyPath !== null) {
21
+ bodyData = bodyPath;
22
+ }
17
23
  if (!(bodyData instanceof Array)) {
18
24
  bodyData = [bodyData]
19
25
  }
@@ -40,7 +46,35 @@ class CommandPostgres extends CommandBasic {
40
46
  client.release();
41
47
  }
42
48
  //console.log("Finishing execute...");
43
- //console.log(JSON.stringify(response));
49
+ if (typeof destination == "string" && destination.trim().length > 0) {
50
+ let generalResponse = null;
51
+ if (response.length == 1) {
52
+ const rows = response[0].rows;
53
+ if (rows) {
54
+ const noList = !!this.args[5];
55
+ if (rows.length == 1 && noList) {
56
+ generalResponse = rows[0];
57
+ } else {
58
+ const first = response[0];
59
+ generalResponse = {
60
+ command: first.command,
61
+ rowCount: first.rowCount,
62
+ rows: first.rows,
63
+ };
64
+ }
65
+ }
66
+ SimpleObj.recreate(this.context.data, destination, generalResponse);
67
+ } else if (response.length > 1) {
68
+ generalResponse = response.map((elem) => {
69
+ return {
70
+ command: elem.command,
71
+ rowCount: elem.rowCount,
72
+ rows: elem.rows,
73
+ }
74
+ });
75
+ SimpleObj.recreate(this.context.data, destination, generalResponse);
76
+ }
77
+ }
44
78
  }
45
79
  }
46
80
  }