zet-lib 3.3.5 → 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/zRoute.js +45 -5
- package/package.json +1 -1
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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":
|