zet-lib 1.2.57 → 1.2.58
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/lib/Util.js +14 -0
- package/lib/zRoute.js +24 -7
- package/package.json +1 -1
package/lib/Util.js
CHANGED
|
@@ -1137,6 +1137,9 @@ Util.attributeOptions = (obj = {}, defaultObj = {}) => {
|
|
|
1137
1137
|
return html
|
|
1138
1138
|
}
|
|
1139
1139
|
|
|
1140
|
+
/*
|
|
1141
|
+
array to update json array at postgresql
|
|
1142
|
+
*/
|
|
1140
1143
|
Util.array_to_jsonb = (arr = []) => {
|
|
1141
1144
|
let value = ''
|
|
1142
1145
|
let myarr = []
|
|
@@ -1149,6 +1152,17 @@ Util.array_to_jsonb = (arr = []) => {
|
|
|
1149
1152
|
return value
|
|
1150
1153
|
}
|
|
1151
1154
|
|
|
1155
|
+
/*
|
|
1156
|
+
array to update array at postgresql
|
|
1157
|
+
*/
|
|
1158
|
+
Util.array_to_arraypg = (arr = []) => {
|
|
1159
|
+
let value = null
|
|
1160
|
+
if (arr.length > 0) {
|
|
1161
|
+
value = JSON.stringify(arr).replace('[', '{').replaceAll(']', '}')
|
|
1162
|
+
}
|
|
1163
|
+
return value
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1152
1166
|
Util.userAvatar = (img = '') => {
|
|
1153
1167
|
return img ? (img.includes('http') ? img : `/uploads/user/${img}`) : `/img/user.png`
|
|
1154
1168
|
}
|
package/lib/zRoute.js
CHANGED
|
@@ -147,6 +147,7 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
147
147
|
let widgets = MYMODEL.widgets
|
|
148
148
|
let tags = []
|
|
149
149
|
let val
|
|
150
|
+
let myval
|
|
150
151
|
for (let key in post[routeName]) {
|
|
151
152
|
let widgetName = widgets[key].name
|
|
152
153
|
val = post[routeName][key]
|
|
@@ -295,8 +296,9 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
295
296
|
case 'numeric':
|
|
296
297
|
post[routeName][key] = val ? val : null
|
|
297
298
|
break
|
|
299
|
+
|
|
298
300
|
case 'json_array':
|
|
299
|
-
|
|
301
|
+
myval = null
|
|
300
302
|
if (val) {
|
|
301
303
|
let myarr = JSON.parse(val) || []
|
|
302
304
|
if (myarr.length > 0) {
|
|
@@ -305,6 +307,17 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
305
307
|
}
|
|
306
308
|
post[routeName][key] = myval
|
|
307
309
|
break
|
|
310
|
+
|
|
311
|
+
case 'array':
|
|
312
|
+
myval = null
|
|
313
|
+
if (val) {
|
|
314
|
+
let myarr = JSON.parse(val) || []
|
|
315
|
+
if (myarr.length > 0) {
|
|
316
|
+
myval = Util.array_to_arraypg(myarr)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
post[routeName][key] = myval
|
|
320
|
+
break
|
|
308
321
|
}
|
|
309
322
|
}
|
|
310
323
|
//check if widget have a tag default null
|
|
@@ -941,6 +954,10 @@ zRoute.dataTableData = (key, value, MYMODEL, relations, myid = '') => {
|
|
|
941
954
|
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
942
955
|
break
|
|
943
956
|
|
|
957
|
+
case 'array':
|
|
958
|
+
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
959
|
+
break
|
|
960
|
+
|
|
944
961
|
default:
|
|
945
962
|
value = value || ''
|
|
946
963
|
myvalue = value.length > 50 ? value.substring(0, 50) : value
|
|
@@ -1856,7 +1873,7 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1856
1873
|
const select = Util.selectParser(fields, MYMODEL)
|
|
1857
1874
|
const asDate = []
|
|
1858
1875
|
const asJSONb = []
|
|
1859
|
-
const
|
|
1876
|
+
const asArray = []
|
|
1860
1877
|
for (let key in MYMODEL.widgets) {
|
|
1861
1878
|
if (MYMODEL.widgets[key].name == 'datetime') {
|
|
1862
1879
|
asDate.push(key)
|
|
@@ -1870,8 +1887,8 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1870
1887
|
if (MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
1871
1888
|
asJSONb.push(key)
|
|
1872
1889
|
}
|
|
1873
|
-
if (MYMODEL.widgets[key].name == 'json_array') {
|
|
1874
|
-
|
|
1890
|
+
if (MYMODEL.widgets[key].name == 'json_array' || MYMODEL.widgets[key].name == 'array') {
|
|
1891
|
+
asArray.push(key)
|
|
1875
1892
|
}
|
|
1876
1893
|
}
|
|
1877
1894
|
let whereArray = []
|
|
@@ -1893,8 +1910,8 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1893
1910
|
if (asJSONb.includes(fields[item.data])) {
|
|
1894
1911
|
astype = 'jsonb'
|
|
1895
1912
|
}
|
|
1896
|
-
if (
|
|
1897
|
-
astype = '
|
|
1913
|
+
if (asArray.includes(fields[item.data])) {
|
|
1914
|
+
astype = 'array'
|
|
1898
1915
|
}
|
|
1899
1916
|
if (astype === 'jsonb') {
|
|
1900
1917
|
whereArray.push({
|
|
@@ -1904,7 +1921,7 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1904
1921
|
operator: 'AND',
|
|
1905
1922
|
type: 'inline',
|
|
1906
1923
|
})
|
|
1907
|
-
} else if (astype === '
|
|
1924
|
+
} else if (astype === 'array') {
|
|
1908
1925
|
whereArray.push({
|
|
1909
1926
|
field: '',
|
|
1910
1927
|
option: '',
|