@itleanchatbot/shared-models-js-postgres 1.1.31 → 1.1.33

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/dialogNodes.js +29 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itleanchatbot/shared-models-js-postgres",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
4
4
  "description": "Shared Models JS Postgres",
5
5
  "main": "index.js",
6
6
  "license": "ISC",
@@ -80,13 +80,17 @@ const DialogNodesModel = (sequelize, Sequelize) => {
80
80
  defaultValue: '',
81
81
  set(value, field) {
82
82
  try {
83
- const string = JSON.stringify(value.map(item => {
84
- if(typeof string === 'object') {
85
- return JSON.stringify(item)
86
- } else {
87
- return JSON.stringify({ error: 'Parse error' })
88
- }
89
- }))
83
+ let string = JSON.stringify([])
84
+
85
+ if(Array.isArray(value) && value.length) {
86
+ string = JSON.stringify(value.map(item => {
87
+ if(typeof string === 'object') {
88
+ return JSON.stringify(item)
89
+ } else {
90
+ return JSON.stringify({ error: 'Parse error' })
91
+ }
92
+ }))
93
+ }
90
94
 
91
95
  this.setDataValue(field, string)
92
96
  } catch (error) {
@@ -95,23 +99,27 @@ const DialogNodesModel = (sequelize, Sequelize) => {
95
99
  }
96
100
  },
97
101
  get(field) {
98
- let value = this.getDataValue(field)
99
- value = JSON.parse(value)
100
- if (value.length) {
101
- return value.map(item => {
102
- try {
103
- if(typeof item === 'string') {
104
- return JSON.parse(item)
105
- } else {
102
+ try {
103
+ let value = this.getDataValue(field)
104
+ value = JSON.parse(value)
105
+ if (value.length) {
106
+ return value.map(item => {
107
+ try {
108
+ if(typeof item === 'string') {
109
+ return JSON.parse(item)
110
+ } else {
111
+ return item
112
+ }
113
+ } catch (error) {
114
+ console.error(error)
106
115
  return item
107
116
  }
108
- } catch (error) {
109
- console.error(error)
110
- return item
111
- }
112
- })
117
+ })
118
+ }
119
+ return value
120
+ } catch (error) {
121
+ return this.getDataValue(field)
113
122
  }
114
- return value
115
123
  },
116
124
  },
117
125
  })