oradm-to-gql 35.0.11 → 35.0.12

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,6 +1,6 @@
1
1
  {
2
2
  "name": "oradm-to-gql",
3
- "version": "35.0.11",
3
+ "version": "35.0.12",
4
4
  "description": "Oracle Data Modeler CSV Export to Apollo GraphQL Endpoint Generator",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,7 +45,7 @@
45
45
  "express": "^4.15.3",
46
46
  "jest": "^23.2.0",
47
47
  "knex": "^0.95.11",
48
- "pg": "^6.4.0",
48
+ "pg": "^8.7.1",
49
49
  "require-from-string": "^1.2.1",
50
50
  "tg-client-query-builder": "^2.2.0",
51
51
  "tg-knex-query-resolver": "^4.1.0"
@@ -53,6 +53,12 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
53
53
 
54
54
 
55
55
  let createdTimestamp = new Date();
56
+ let modifiedUser = undefined;
57
+
58
+ if(this.context.req.user){
59
+ modifiedUser = this.context.req.user.id;
60
+ }
61
+
56
62
  records.forEach((rec) => {
57
63
  {% for propName, attrDef in table.attributes %}
58
64
  {% if attrDef.isPrimaryKey %}
@@ -68,6 +74,10 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
68
74
  //set timestamps
69
75
  rec.{{attrDef.name}} = createdTimestamp;
70
76
  {% endif %}
77
+ {% if attrDef.updatedBy == 'modified' %}
78
+ //set modified user
79
+ rec.{{attrDef.name}} = modifiedUser;
80
+ {% endif %}
71
81
  {% endfor %}
72
82
  });
73
83
 
@@ -55,6 +55,12 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
55
55
 
56
56
  let ids = [];
57
57
  let modifiedTimestamp = new Date();
58
+ let modifiedUser = undefined;
59
+
60
+ if(this.context.req.user){
61
+ modifiedUser = this.context.req.user.id;
62
+ }
63
+
58
64
  return Promise.each(records, async (updateRecord) =>
59
65
  {
60
66
  let recordId = updateRecord.{{table.primaryKeyField}};
@@ -118,6 +124,9 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
118
124
  {% if attrDef.timestamp == 'modified' %}
119
125
  values.{{attrDef.columnName}} = modifiedTimestamp;
120
126
  {% endif %}
127
+ {% if attrDef.updatedBy == 'modified' %}
128
+ values.{{attrDef.columnName}} = modifiedUser;
129
+ {% endif %}
121
130
  {% endfor %}
122
131
 
123
132
 
@@ -0,0 +1,44 @@
1
+ const { each } = require("lodash");
2
+
3
+ module.exports = function addUpdatedByColumn(tableMap, updatedBy, opts) {
4
+ opts = opts || {};
5
+ each(tableMap, (table, tableName) => {
6
+ if (table.type !== "view") {
7
+ if (updatedBy.modified) {
8
+ var modifiedColName = updatedBy.modified;
9
+ if (typeof table.attributes[modifiedColName] === "undefined") {
10
+ table.attributes[modifiedColName] = {
11
+ name: modifiedColName,
12
+ columnName: modifiedColName,
13
+ dataType: "UUID",
14
+ isPrimaryKey: false,
15
+ isForeignKey: true,
16
+ size: "",
17
+ precision: "",
18
+ scale: "",
19
+ nullable: true,
20
+ referenceName: "User",
21
+ relAttrName: "user",
22
+ referenceKey: "id",
23
+ referenceIdentifying: false,
24
+ referenceIsPlural: true,
25
+ fkName: "modifiedBy_usrId_fk",
26
+ updatedBy: "modified"
27
+ };
28
+ } else {
29
+ if (updatedBy.errorOnConflict) {
30
+ throw new Error(
31
+ `[DM GEN ERROR] updatedBy ${modifiedColName} field already exists on ${tableName}. Unset updatedBy.errorOnConflict to warn instead of throwing.`
32
+ );
33
+ } else {
34
+ console.warn(
35
+ `[DM GEN WARNING] updatedBy ${modifiedColName} field already exists on ${tableName}. Set updatedBy.errorOnConflict throw an error instead of warning`
36
+ );
37
+ }
38
+ }
39
+ }
40
+ }
41
+ });
42
+
43
+ return tableMap;
44
+ };
@@ -4,6 +4,7 @@ const applyNamingRules = require("./applyNamingRules");
4
4
  const populateRelationshipAttributes = require("./populateRelationshipAttributes");
5
5
  const extendTableMap = require("./extendTableMap");
6
6
  const addTimestampColumns = require("./addTimestampColumns");
7
+ const addUpdatedByColumn = require("./addUpdatedByColumn");
7
8
  const { addIndexes } = require("./addIndexes");
8
9
  const { processViews } = require("./views");
9
10
  const { mergeCommonTableMap } = require("./mergeCommonTableMap");
@@ -46,6 +47,10 @@ module.exports = function parseDatamodelCSV(
46
47
  tableMap = addTimestampColumns(tableMap, opts.timestamps, opts);
47
48
  }
48
49
 
50
+ if (opts.updatedBy) {
51
+ tableMap = addUpdatedByColumn(tableMap, opts.updatedBy, opts);
52
+ }
53
+
49
54
  tableMap = addIndexes(tableMap, opts);
50
55
  // tableMap = defaultBooleans(tableMap, opts);
51
56
  tableMap = applyNamingRules(tableMap, opts);