zet-lib 3.3.4 → 3.3.6

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/Form.js CHANGED
@@ -508,7 +508,9 @@ Form.field = (obj) => {
508
508
  });
509
509
  value = value || [];
510
510
  value.map((item, index) => {
511
- leftButtons += `<li><button class="btn btn-primary boxy" type="button">${obj.dataObject[item]}<input type="hidden" name='${obj.name}[]' value="${item}"></button></li>`;
511
+ if (obj.dataObject && item in obj.dataObject) {
512
+ leftButtons += `<li><button class="btn btn-primary boxy" type="button">${obj.dataObject[item]}<input type="hidden" name='${obj.name}[]' value="${item}"></button></li>`;
513
+ }
512
514
  });
513
515
 
514
516
  displayForm += `<div id="dragdrop_${obj.id}" class="row contentfields">
package/lib/zRoute.js CHANGED
@@ -205,12 +205,52 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
205
205
 
206
206
  case "dragdrop":
207
207
  let cleaning2;
208
- if (Array.isArray(post[routeName][key])) {
209
- cleaning2 = post[routeName][key]
210
- ? post[routeName][key].filter((item) => item)
211
- : null;
208
+ let dragdropValue = post[routeName] && post[routeName][key] !== undefined ? post[routeName][key] : null;
209
+
210
+ // Helper function to convert object with numeric keys to array
211
+ const convertToArray = (value) => {
212
+ if (Array.isArray(value)) {
213
+ return value;
214
+ }
215
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
216
+ // Check if it's an object with numeric keys (like {"0":"111","1":"138"})
217
+ const keys = Object.keys(value);
218
+ const numericKeys = keys.filter(k => /^\d+$/.test(k));
219
+ if (numericKeys.length === keys.length && numericKeys.length > 0) {
220
+ // Convert object with numeric keys to array
221
+ return numericKeys.map(k => value[k]).filter(item => item !== null && item !== undefined && item !== '');
222
+ }
223
+ }
224
+ return null;
225
+ };
226
+
227
+ // Handle case where value might be string (JSON) or already an array
228
+ if (dragdropValue === null || dragdropValue === undefined) {
229
+ cleaning2 = null;
230
+ } else if (typeof dragdropValue === 'string') {
231
+ try {
232
+ dragdropValue = JSON.parse(dragdropValue);
233
+ let arr = convertToArray(dragdropValue);
234
+ if (arr) {
235
+ cleaning2 = arr.filter((item) => item !== null && item !== undefined && item !== '');
236
+ } else {
237
+ cleaning2 = dragdropValue ? [dragdropValue] : null;
238
+ }
239
+ } catch (e) {
240
+ // If not valid JSON, treat as single value array
241
+ cleaning2 = dragdropValue ? [dragdropValue] : null;
242
+ }
243
+ } else if (Array.isArray(dragdropValue)) {
244
+ cleaning2 = dragdropValue.filter((item) => item !== null && item !== undefined && item !== '');
245
+ } else if (dragdropValue && typeof dragdropValue === 'object') {
246
+ // Handle object with numeric keys (converted by qs.parse for large arrays)
247
+ let arr = convertToArray(dragdropValue);
248
+ cleaning2 = arr ? arr.filter((item) => item !== null && item !== undefined && item !== '') : null;
249
+ } else {
250
+ // Single value, convert to array
251
+ cleaning2 = dragdropValue ? [dragdropValue] : null;
212
252
  }
213
- post[routeName][key] = cleaning2 ? JSON.stringify(cleaning2) : null;
253
+ post[routeName][key] = cleaning2 && cleaning2.length > 0 ? JSON.stringify(cleaning2) : null;
214
254
  break;
215
255
 
216
256
  case "lexical":
@@ -5321,22 +5361,26 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
5321
5361
  data: data,
5322
5362
  });
5323
5363
  //save to history
5324
- connection.insert({
5325
- table: "zhistory",
5326
- data: {
5327
- module_id: result.id,
5328
- module: MYMODEL.table,
5329
- data_1: JSON.stringify(result),
5330
- data_2: JSON.stringify(myresult),
5331
- data_1_date: result.updated_at,
5332
- data_2_date: data.updated_at,
5333
- created_by: userId,
5334
- updated_by: userId,
5335
- created_at: Util.now(),
5336
- updated_at: Util.now(),
5337
- company_id: res.locals.companyId,
5338
- },
5339
- });
5364
+ try {
5365
+ connection.insert({
5366
+ table: "zhistory",
5367
+ data: {
5368
+ module_id: result.id,
5369
+ module: MYMODEL.table,
5370
+ data_1: JSON.stringify(result),
5371
+ data_2: JSON.stringify(myresult),
5372
+ data_1_date: result.updated_at,
5373
+ data_2_date: data.updated_at,
5374
+ created_by: userId,
5375
+ updated_by: userId,
5376
+ created_at: Util.now(),
5377
+ updated_at: Util.now(),
5378
+ company_id: res.locals.companyId,
5379
+ },
5380
+ });
5381
+ } catch (e) {
5382
+ console.log(e)
5383
+ }
5340
5384
  zRoute.modelsCacheRenew(table, res.locals.companyId);
5341
5385
  return myresult;
5342
5386
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"