@ejfdelgado/ejflab-common 1.6.0 → 1.7.0

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.6.0",
4
+ "version": "1.7.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
@@ -27,6 +27,7 @@ const { CommandPrint } = require('./steps/CommandPrint');
27
27
  const { CommandMongo } = require('./steps/CommandMongo');
28
28
  const { CommandMinio } = require('./steps/CommandMinio');
29
29
  const { CommandPostgres } = require('./steps/CommandPostgres.js');
30
+ const { StepMultiple } = require('./steps/StepMultiple.js');
30
31
 
31
32
  class FlowChartExec {
32
33
  executionPromise = null;
@@ -59,6 +60,7 @@ class FlowChartExec {
59
60
  this.registry["timelineHasMore"] = StepTimeLineHasMore;
60
61
  this.registry["process"] = StepProcess;
61
62
  this.registry["require"] = StepCheckProcessor;
63
+ this.registry["multiple"] = StepMultiple;
62
64
 
63
65
  // Nodes
64
66
  this.registry["inc"] = CommandInc;
@@ -10,18 +10,37 @@ class CommandPostgres extends CommandBasic {
10
10
  const script = this.args[3];
11
11
  const postgresSrv = this.context.getSuperContext().getPostgresClient();
12
12
  if (action == "execute") {
13
+ //console.log("Starting execute...");
13
14
  const dbIdData = SimpleObj.getValue(this.context.data, dbIdPath, null);
14
15
  let bodyData = SimpleObj.getValue(this.context.data, bodyPath, null);
15
16
  bodyData = JSON.parse(JSON.stringify(bodyData));
16
17
  if (!(bodyData instanceof Array)) {
17
18
  bodyData = [bodyData]
18
19
  }
19
- for (let i = 0; i < bodyData.length; i++) {
20
- const payload = JSON.parse(JSON.stringify(dbIdData));
21
- payload.object = bodyData[i];
22
- console.log(`script=${script}`);
23
- console.log(JSON.stringify(payload, null, 4));
20
+ const now = new Date().getTime();
21
+
22
+ const pool = postgresSrv.getPool();
23
+ const client = await pool.connect();
24
+ await client.query("BEGIN");
25
+ const response = [];
26
+ try {
27
+ // Insert into media
28
+ for (let i = 0; i < bodyData.length; i++) {
29
+ const payload = JSON.parse(JSON.stringify(dbIdData));
30
+ payload.object = bodyData[i];
31
+ payload.now = now;
32
+ const result = await postgresSrv.executeFile(script, payload, client);
33
+ response.push(result);
34
+ }
35
+ await client.query("COMMIT");
36
+ } catch (e) {
37
+ await client.query("ROLLBACK");
38
+ throw e;
39
+ } finally {
40
+ client.release();
24
41
  }
42
+ //console.log("Finishing execute...");
43
+ //console.log(JSON.stringify(response));
25
44
  }
26
45
  }
27
46
  }
@@ -0,0 +1,21 @@
1
+ const { StepBasic } = require("./StepBasic");
2
+
3
+ class StepMultiple extends StepBasic {
4
+ list = [];
5
+ constructor(context, id, commandName, argsTxt) {
6
+ super(context, id, commandName, argsTxt);
7
+ super.alwaysEvaluateCanContinue = true;
8
+ }
9
+ async execFirst() {
10
+ const flowChartTemplateName = this.args[0];
11
+ this.list = this.args[1];
12
+ }
13
+
14
+ async canContinue() {
15
+ return true;
16
+ }
17
+ }
18
+
19
+ module.exports = {
20
+ StepMultiple
21
+ };