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.
Files changed (2) hide show
  1. package/dist/filters.js +34 -12
  2. 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 = (filters) => {
15
+ const buildQuery = (params) => {
16
16
  const parts = [];
17
- Object.entries(filters).forEach(([key, value]) => {
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.includes('Range') || key.includes('range'))) {
23
- // Range values like [min, max] or [startDate, endDate]
24
- const rangeString = value.map(v => v instanceof Date ? v.toISOString().split('T')[0] : v).join(',');
25
- parts.push(`${key}=${rangeString}`);
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
- // Regular arrays like tags, categories
29
- parts.push(`${key}=${value.join(',')}`);
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
- // Handle primitives
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
- parts.push(`${key}=${encodeURIComponent(value)}`);
60
+ addKeyValue(key, value);
39
61
  }
40
62
  });
41
63
  return parts.join('&');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopoflex-types",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
4
4
  "description": "Shared TypeScript types for Shopoflex applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",