shopoflex-types 1.0.60 → 1.0.62
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/dist/filters.js +34 -12
- package/package.json +1 -1
package/dist/filters.js
CHANGED
|
@@ -12,30 +12,52 @@ exports.buildDiscountQuery = exports.buildCustomerQuery = exports.buildOrderQuer
|
|
|
12
12
|
* @param filters - Any filter object
|
|
13
13
|
* @returns Query parameters string (without ?)
|
|
14
14
|
*/
|
|
15
|
-
const buildQuery = (
|
|
15
|
+
const buildQuery = (params) => {
|
|
16
16
|
const parts = [];
|
|
17
|
-
|
|
17
|
+
const addKeyValue = (key, value) => {
|
|
18
18
|
if (value === undefined || value === null || value === '')
|
|
19
19
|
return;
|
|
20
|
-
// Handle arrays (convert to comma-separated string)
|
|
21
20
|
if (Array.isArray(value)) {
|
|
22
|
-
if (value.length === 2 && (key.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (value.length === 2 && (key.toLowerCase().includes('range'))) {
|
|
22
|
+
const rangeString = value.map(v => {
|
|
23
|
+
if (v instanceof Date)
|
|
24
|
+
return v.toISOString().split('T')[0];
|
|
25
|
+
if (typeof v === 'object' && v !== null) {
|
|
26
|
+
return v._id || v.id || JSON.stringify(v);
|
|
27
|
+
}
|
|
28
|
+
return String(v);
|
|
29
|
+
}).join(',');
|
|
30
|
+
parts.push(`${key}=${encodeURIComponent(rangeString)}`);
|
|
26
31
|
}
|
|
27
32
|
else {
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const arrayString = value.map(v => {
|
|
34
|
+
if (typeof v === 'object' && v !== null) {
|
|
35
|
+
return v._id || v.id || v.value || JSON.stringify(v);
|
|
36
|
+
}
|
|
37
|
+
return String(v);
|
|
38
|
+
}).join(',');
|
|
39
|
+
parts.push(`${key}=${encodeURIComponent(arrayString)}`);
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
// Handle dates
|
|
33
42
|
else if (value instanceof Date) {
|
|
34
43
|
parts.push(`${key}=${value.toISOString().split('T')[0]}`);
|
|
35
44
|
}
|
|
36
|
-
|
|
45
|
+
else if (typeof value === 'object') {
|
|
46
|
+
const objectValue = value._id || value.id || value.value || JSON.stringify(value);
|
|
47
|
+
parts.push(`${key}=${encodeURIComponent(objectValue)}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
parts.push(`${key}=${encodeURIComponent(String(value))}`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
54
|
+
if (key === 'filters' && typeof value === 'object' && value !== null) {
|
|
55
|
+
Object.entries(value).forEach(([filterKey, filterValue]) => {
|
|
56
|
+
addKeyValue(filterKey, filterValue);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
37
59
|
else {
|
|
38
|
-
|
|
60
|
+
addKeyValue(key, value);
|
|
39
61
|
}
|
|
40
62
|
});
|
|
41
63
|
return parts.join('&');
|