@storecraft/database-sql-base 1.0.22 → 1.0.24
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/migrate.js +3 -0
- package/migrations.shared/00003_alter_auth_users.js +6 -0
- package/package.json +2 -2
- package/src/con.auth_users.js +17 -13
- package/src/con.collections.js +24 -16
- package/src/con.customers.js +26 -19
- package/src/con.discounts.js +31 -20
- package/src/con.discounts.utils.js +52 -41
- package/src/con.images.js +18 -13
- package/src/con.notifications.js +26 -17
- package/src/con.orders.js +25 -18
- package/src/con.posts.js +28 -28
- package/src/con.products.js +80 -128
- package/src/con.search.js +12 -12
- package/src/con.shared.js +17 -35
- package/src/con.shipping.js +23 -16
- package/src/con.storefronts.js +23 -17
- package/src/con.tags.js +22 -14
- package/src/con.templates.js +21 -24
- package/src/utils.query.OLD.js +259 -0
- package/src/utils.query.js +217 -179
- package/tests/sandbox.js +5 -6
package/migrate.js
CHANGED
@@ -101,9 +101,12 @@ export async function migrateToLatest(db_driver, release_db_upon_completion=true
|
|
101
101
|
if (error) {
|
102
102
|
console.error('failed to migrate')
|
103
103
|
console.error(JSON.stringify(error, null, 2))
|
104
|
+
console.error(JSON.stringify(results, null, 2))
|
104
105
|
process.exit(1)
|
105
106
|
}
|
106
107
|
|
108
|
+
console.log('Resolving migrations COMPLETE.')
|
109
|
+
|
107
110
|
if(release_db_upon_completion)
|
108
111
|
await db.destroy();
|
109
112
|
}
|
@@ -9,6 +9,12 @@ import { Kysely } from 'kysely'
|
|
9
9
|
*/
|
10
10
|
export async function up(db) {
|
11
11
|
|
12
|
+
// console.log(
|
13
|
+
// db.schema.alterTable('auth_users')
|
14
|
+
// .addColumn('firstname', 'text')
|
15
|
+
// .compile()
|
16
|
+
// )
|
17
|
+
|
12
18
|
await db.schema
|
13
19
|
.alterTable('auth_users')
|
14
20
|
.addColumn('firstname', 'text')
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/database-sql-base",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.24",
|
4
4
|
"description": "Official SQL Database driver for storecraft",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Tomer Shalev (https://github.com/store-craft)",
|
@@ -38,7 +38,7 @@
|
|
38
38
|
},
|
39
39
|
"dependencies": {
|
40
40
|
"@storecraft/core": "^1.0.0",
|
41
|
-
"kysely": "^0.
|
41
|
+
"kysely": "^0.28.1"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
44
|
"@types/better-sqlite3": "^7.6.9",
|
package/src/con.auth_users.js
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
count_regular, delete_me, insert_search_of, insert_tags_of,
|
8
8
|
regular_upsert_me, where_id_or_handle_table, with_media, with_tags
|
9
9
|
} from './con.shared.js'
|
10
|
-
import {
|
10
|
+
import { withQuery } from './utils.query.js';
|
11
11
|
import { remove as remove_customer_and_auth_user } from './con.customers.js';
|
12
12
|
|
13
13
|
|
@@ -126,22 +126,26 @@ const removeByEmail = (driver) => {
|
|
126
126
|
const list = (driver) => {
|
127
127
|
return async (query) => {
|
128
128
|
|
129
|
-
const items = await
|
129
|
+
const items = await withQuery(
|
130
|
+
driver.client.selectFrom(table_name)
|
130
131
|
.selectAll()
|
131
132
|
.select(eb => [
|
132
133
|
with_tags(eb, eb.ref('auth_users.id'), driver.dialectType),
|
133
134
|
with_media(eb, eb.ref('auth_users.id'), driver.dialectType),
|
134
|
-
])
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
.
|
142
|
-
.
|
143
|
-
|
144
|
-
|
135
|
+
]),
|
136
|
+
query, table_name
|
137
|
+
// .where(
|
138
|
+
// (eb) => {
|
139
|
+
// return query_to_eb(eb, query, table_name);
|
140
|
+
// }
|
141
|
+
// )
|
142
|
+
// .orderBy(query_to_sort(query, 'auth_users'))
|
143
|
+
// .limit(query.limitToLast ?? query.limit ?? 10)
|
144
|
+
)
|
145
|
+
.execute();
|
146
|
+
|
147
|
+
if(query.limitToLast)
|
148
|
+
items.reverse();
|
145
149
|
|
146
150
|
return sanitize_array(items);
|
147
151
|
}
|
package/src/con.collections.js
CHANGED
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
with_search
|
14
14
|
} from './con.shared.js'
|
15
15
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
16
|
-
import { query_to_eb,
|
16
|
+
import { query_to_eb, withQuery, withSort } from './utils.query.js'
|
17
17
|
|
18
18
|
export const table_name = 'collections'
|
19
19
|
|
@@ -120,22 +120,26 @@ const remove = (driver) => {
|
|
120
120
|
const list = (driver) => {
|
121
121
|
return async (query) => {
|
122
122
|
|
123
|
-
const items = await
|
123
|
+
const items = await withQuery(
|
124
|
+
driver.client
|
124
125
|
.selectFrom(table_name)
|
125
126
|
.selectAll()
|
126
127
|
.select(eb => [
|
127
128
|
with_tags(eb, eb.ref('collections.id'), driver.dialectType),
|
128
129
|
with_media(eb, eb.ref('collections.id'), driver.dialectType),
|
129
130
|
with_search(eb, eb.ref('collections.id'), driver.dialectType),
|
130
|
-
])
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
)
|
136
|
-
|
137
|
-
|
138
|
-
|
131
|
+
]),
|
132
|
+
query, table_name
|
133
|
+
).execute();
|
134
|
+
|
135
|
+
// .where(
|
136
|
+
// (eb) => {
|
137
|
+
// return query_to_eb(eb, query, table_name);
|
138
|
+
// }
|
139
|
+
// )
|
140
|
+
// .orderBy(query_to_sort(query, 'collections'))
|
141
|
+
// .limit(query.limitToLast ?? query.limit ?? 10)
|
142
|
+
// .execute();
|
139
143
|
|
140
144
|
if(query.limitToLast) items.reverse();
|
141
145
|
|
@@ -150,7 +154,8 @@ const list = (driver) => {
|
|
150
154
|
const list_collection_products = (driver) => {
|
151
155
|
return async (handle_or_id, query={}) => {
|
152
156
|
|
153
|
-
const items = await
|
157
|
+
const items = await withSort(
|
158
|
+
driver.client
|
154
159
|
.selectFrom('products')
|
155
160
|
.innerJoin(
|
156
161
|
'products_to_collections',
|
@@ -177,14 +182,17 @@ const list_collection_products = (driver) => {
|
|
177
182
|
].filter(Boolean)
|
178
183
|
)
|
179
184
|
)
|
180
|
-
.
|
181
|
-
|
182
|
-
|
185
|
+
.limit(query.limitToLast ?? query.limit ?? 10),
|
186
|
+
query, 'products'
|
187
|
+
).execute()
|
188
|
+
// .orderBy(query_to_sort(query, 'products'))
|
189
|
+
// .execute();
|
183
190
|
|
184
191
|
// .compile();
|
185
192
|
// console.log(items[0])
|
186
193
|
|
187
|
-
if(query.limitToLast)
|
194
|
+
if(query.limitToLast)
|
195
|
+
items.reverse();
|
188
196
|
|
189
197
|
return sanitize_array(items);
|
190
198
|
}
|
package/src/con.customers.js
CHANGED
@@ -8,7 +8,7 @@ import { count_regular, delete_me, delete_media_of, delete_search_of,
|
|
8
8
|
insert_tags_of, regular_upsert_me, where_id_or_handle_table,
|
9
9
|
with_media, with_search, with_tags} from './con.shared.js'
|
10
10
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
11
|
-
import { query_to_eb,
|
11
|
+
import { query_to_eb, withQuery, withSort } from './utils.query.js'
|
12
12
|
|
13
13
|
export const table_name = 'customers'
|
14
14
|
|
@@ -130,22 +130,25 @@ export const remove = (driver) => {
|
|
130
130
|
const list = (driver) => {
|
131
131
|
return async (query) => {
|
132
132
|
|
133
|
-
const items = await
|
133
|
+
const items = await withQuery(
|
134
|
+
driver.client
|
134
135
|
.selectFrom(table_name)
|
135
136
|
.selectAll()
|
136
137
|
.select(eb => [
|
137
138
|
with_media(eb, eb.ref('customers.id'), driver.dialectType),
|
138
139
|
with_tags(eb, eb.ref('customers.id'), driver.dialectType),
|
139
140
|
with_search(eb, eb.ref('customers.id'), driver.dialectType),
|
140
|
-
].filter(Boolean))
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
141
|
+
].filter(Boolean)),
|
142
|
+
query, table_name
|
143
|
+
).execute();
|
144
|
+
|
145
|
+
// .where(
|
146
|
+
// (eb) => {
|
147
|
+
// return query_to_eb(eb, query, table_name);
|
148
|
+
// }
|
149
|
+
// .orderBy(query_to_sort(query, table_name))
|
150
|
+
// .limit(query.limitToLast ?? query.limit ?? 10)
|
151
|
+
// .execute();
|
149
152
|
|
150
153
|
if(query.limitToLast) items.reverse();
|
151
154
|
|
@@ -160,7 +163,8 @@ const list = (driver) => {
|
|
160
163
|
const list_customer_orders = (driver) => {
|
161
164
|
return async (id, query) => {
|
162
165
|
|
163
|
-
const items = await
|
166
|
+
const items = await withSort(
|
167
|
+
driver.client
|
164
168
|
.selectFrom('orders')
|
165
169
|
.selectAll()
|
166
170
|
.select(eb => [
|
@@ -180,11 +184,14 @@ const list_customer_orders = (driver) => {
|
|
180
184
|
].filter(Boolean)
|
181
185
|
)
|
182
186
|
)
|
183
|
-
.
|
184
|
-
|
185
|
-
|
187
|
+
.limit(query.limitToLast ?? query.limit ?? 10),
|
188
|
+
query, 'orders'
|
189
|
+
).execute();
|
190
|
+
// .orderBy(query_to_sort(query, 'orders'))
|
191
|
+
// .execute();
|
186
192
|
|
187
|
-
if(query.limitToLast)
|
193
|
+
if(query.limitToLast)
|
194
|
+
items.reverse();
|
188
195
|
|
189
196
|
return sanitize_array(items);
|
190
197
|
}
|
@@ -195,7 +202,7 @@ const list_customer_orders = (driver) => {
|
|
195
202
|
* @returns {db_col["count_customer_orders"]}
|
196
203
|
*/
|
197
204
|
const count_customer_orders = (driver) => {
|
198
|
-
return async (
|
205
|
+
return async (customer_id_or_email, query) => {
|
199
206
|
|
200
207
|
const result = await driver.client
|
201
208
|
.selectFrom('orders')
|
@@ -208,8 +215,8 @@ const count_customer_orders = (driver) => {
|
|
208
215
|
query_to_eb(eb, query, table_name),
|
209
216
|
eb.or(
|
210
217
|
[
|
211
|
-
eb('_customer_id', '=',
|
212
|
-
eb('_customer_email', '=',
|
218
|
+
eb('_customer_id', '=', customer_id_or_email),
|
219
|
+
eb('_customer_email', '=', customer_id_or_email),
|
213
220
|
]
|
214
221
|
)
|
215
222
|
].filter(Boolean)
|
package/src/con.discounts.js
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
helper_compute_product_extra_tags_because_of_discount_side_effect_for_db
|
8
8
|
} from '@storecraft/core/database'
|
9
9
|
import { SQL } from '../index.js'
|
10
|
-
import { discount_to_conjunctions } from './con.discounts.utils.js'
|
10
|
+
import { discount_to_conjunctions, is_order_discount } from './con.discounts.utils.js'
|
11
11
|
import {
|
12
12
|
delete_entity_values_by_value_or_reporter_and_context,
|
13
13
|
delete_me, delete_media_of, delete_search_of,
|
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
with_media, with_tags, count_regular, with_search,
|
17
17
|
} from './con.shared.js'
|
18
18
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
19
|
-
import { query_to_eb,
|
19
|
+
import { query_to_eb, withQuery, withSort } from './utils.query.js'
|
20
20
|
import { report_document_media } from './con.images.js'
|
21
21
|
|
22
22
|
export const table_name = 'discounts'
|
@@ -59,7 +59,13 @@ const upsert = (driver) => {
|
|
59
59
|
trx, extra_tag);
|
60
60
|
}
|
61
61
|
|
62
|
-
|
62
|
+
// make connections into `products_to_discounts`, only applicable for
|
63
|
+
// `product` discounts and automatic discounts
|
64
|
+
if(
|
65
|
+
item.active &&
|
66
|
+
item.application.id===enums.DiscountApplicationEnum.Auto.id &&
|
67
|
+
!is_order_discount(item)
|
68
|
+
) {
|
63
69
|
// make connections
|
64
70
|
await trx
|
65
71
|
.insertInto('products_to_discounts')
|
@@ -135,7 +141,7 @@ const upsert = (driver) => {
|
|
135
141
|
application: JSON.stringify(item.application),
|
136
142
|
info: JSON.stringify(item.info),
|
137
143
|
_application_id: item.application.id,
|
138
|
-
_discount_type_id: item
|
144
|
+
_discount_type_id: item?.info?.details?.meta?.id ?? -1,
|
139
145
|
});
|
140
146
|
}
|
141
147
|
);
|
@@ -243,24 +249,24 @@ const remove = (driver) => {
|
|
243
249
|
const list = (driver) => {
|
244
250
|
return async (query) => {
|
245
251
|
|
246
|
-
const items = await
|
252
|
+
const items = await withQuery(
|
253
|
+
driver.client
|
247
254
|
.selectFrom(table_name)
|
248
255
|
.selectAll()
|
249
256
|
.select(eb => [
|
250
257
|
with_media(eb, eb.ref('discounts.id'), driver.dialectType),
|
251
258
|
with_tags(eb, eb.ref('discounts.id'), driver.dialectType),
|
252
259
|
with_search(eb, eb.ref('discounts.id'), driver.dialectType),
|
253
|
-
].filter(Boolean))
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
)
|
259
|
-
.
|
260
|
-
.limit(query.limitToLast ?? query.limit ?? 10)
|
261
|
-
.execute();
|
260
|
+
].filter(Boolean)),
|
261
|
+
query, table_name
|
262
|
+
).execute();
|
263
|
+
|
264
|
+
// .orderBy(query_to_sort(query, table_name))
|
265
|
+
// .limit(query.limitToLast ?? query.limit ?? 10)
|
266
|
+
// .execute();
|
262
267
|
|
263
|
-
if(query.limitToLast)
|
268
|
+
if(query.limitToLast)
|
269
|
+
items.reverse();
|
264
270
|
|
265
271
|
return sanitize_array(items);
|
266
272
|
}
|
@@ -273,7 +279,8 @@ const list = (driver) => {
|
|
273
279
|
const list_discount_products = (driver) => {
|
274
280
|
return async (handle_or_id, query={}) => {
|
275
281
|
|
276
|
-
const items = await
|
282
|
+
const items = await withSort(
|
283
|
+
driver.client
|
277
284
|
.selectFrom('products')
|
278
285
|
.innerJoin(
|
279
286
|
'products_to_discounts',
|
@@ -298,11 +305,15 @@ const list_discount_products = (driver) => {
|
|
298
305
|
].filter(Boolean)
|
299
306
|
)
|
300
307
|
)
|
301
|
-
.
|
302
|
-
|
303
|
-
|
308
|
+
.limit(query.limitToLast ?? query.limit ?? 10),
|
309
|
+
query, 'products'
|
310
|
+
).execute();
|
311
|
+
|
312
|
+
// .orderBy(query_to_sort(query, 'products'))
|
313
|
+
// .execute();
|
304
314
|
|
305
|
-
if(query.limitToLast)
|
315
|
+
if(query.limitToLast)
|
316
|
+
items.reverse();
|
306
317
|
|
307
318
|
return sanitize_array(items);
|
308
319
|
}
|
@@ -1,21 +1,26 @@
|
|
1
1
|
/**
|
2
2
|
* @import {
|
3
|
-
* DiscountType,
|
4
|
-
*
|
5
|
-
*
|
3
|
+
* DiscountType, Filter_p_in_price_range, Filter_p_not_in_collections,
|
4
|
+
* Filter_p_in_collections, Filter_p_not_in_tags, Filter_p_in_tags,
|
5
|
+
* Filter_p_in_products, Filter_p_not_in_products
|
6
6
|
* } from '@storecraft/core/api'
|
7
7
|
* @import { Database } from '../types.sql.tables.js'
|
8
8
|
* @import { ExpressionBuilder, BinaryOperator } from 'kysely'
|
9
9
|
*/
|
10
10
|
import { enums } from "@storecraft/core/api";
|
11
|
+
import { assert } from "console";
|
11
12
|
|
12
13
|
/** @param {DiscountType} d */
|
13
|
-
const is_order_discount = d => {
|
14
|
-
return (
|
14
|
+
export const is_order_discount = d => {
|
15
|
+
return (
|
16
|
+
(d.info.details.type===enums.DiscountMetaEnum.order.type) ||
|
17
|
+
// @ts-ignore
|
18
|
+
(d.info.details.meta?.type===enums.DiscountMetaEnum.order.type)
|
19
|
+
);
|
15
20
|
}
|
16
21
|
|
17
22
|
/** @param {DiscountType} d */
|
18
|
-
const is_automatic_discount = d => {
|
23
|
+
export const is_automatic_discount = d => {
|
19
24
|
return (d.application.id===enums.DiscountApplicationEnum.Auto.id);
|
20
25
|
}
|
21
26
|
|
@@ -49,7 +54,7 @@ const eb_in = (eb, table, value) => {
|
|
49
54
|
}
|
50
55
|
|
51
56
|
/**
|
52
|
-
* create a
|
57
|
+
* @description create a filter conjunctions clauses from discount
|
53
58
|
* for filtering.
|
54
59
|
* @param {ExpressionBuilder<Database, 'products'>} eb
|
55
60
|
* @param {DiscountType} d
|
@@ -61,13 +66,16 @@ export const discount_to_conjunctions = (eb, d) => {
|
|
61
66
|
d.active && d?.info?.filters?.length
|
62
67
|
);
|
63
68
|
|
64
|
-
|
69
|
+
assert(
|
70
|
+
is_good,
|
71
|
+
`discount_to_conjunctions: discount is not a product discount`
|
72
|
+
);
|
65
73
|
|
66
74
|
const conjunctions = [];
|
67
75
|
const filters = d.info.filters;
|
68
76
|
|
69
77
|
for(const filter of filters) {
|
70
|
-
const op = filter.meta.op;
|
78
|
+
const op = filter.op ?? filter.meta.op;
|
71
79
|
|
72
80
|
switch (op) {
|
73
81
|
case enums.FilterMetaEnum.p_all.op:
|
@@ -75,60 +83,60 @@ export const discount_to_conjunctions = (eb, d) => {
|
|
75
83
|
break;
|
76
84
|
case enums.FilterMetaEnum.p_in_products.op:
|
77
85
|
{
|
78
|
-
|
79
|
-
|
80
|
-
Array.isArray(filter?.value) ? filter.value : []
|
86
|
+
const cast_filter = /** @type {Filter_p_in_products} */ (
|
87
|
+
filter
|
81
88
|
);
|
82
|
-
|
89
|
+
const value = cast_filter?.value ?? [];
|
83
90
|
conjunctions.push(
|
84
91
|
eb(
|
85
92
|
'products.handle', 'in',
|
86
|
-
|
93
|
+
value.map(item => item.handle).filter(Boolean)
|
87
94
|
)
|
88
95
|
);
|
89
96
|
}
|
90
97
|
break;
|
91
98
|
case enums.FilterMetaEnum.p_not_in_products.op:
|
92
99
|
{
|
93
|
-
|
94
|
-
|
95
|
-
Array.isArray(filter?.value) ? filter.value : []
|
100
|
+
const cast_filter = /** @type {Filter_p_not_in_products} */ (
|
101
|
+
filter
|
96
102
|
);
|
103
|
+
const value = cast_filter?.value ?? [];
|
97
104
|
|
98
105
|
conjunctions.push(
|
99
106
|
eb(
|
100
107
|
'products.handle', 'not in',
|
101
|
-
|
108
|
+
value.map(item => item.handle).filter(Boolean)
|
102
109
|
)
|
103
110
|
);
|
104
111
|
}
|
105
112
|
break;
|
106
113
|
case enums.FilterMetaEnum.p_in_tags.op:
|
107
114
|
{
|
108
|
-
|
109
|
-
|
110
|
-
Array.isArray(filter?.value) ? filter.value : []
|
115
|
+
const cast_filter = /** @type {Filter_p_in_tags} */ (
|
116
|
+
filter
|
111
117
|
);
|
112
|
-
|
118
|
+
const value = cast_filter?.value ?? [];
|
119
|
+
|
113
120
|
conjunctions.push(
|
114
121
|
eb_in(
|
115
122
|
eb, 'entity_to_tags_projections',
|
116
|
-
|
123
|
+
value
|
117
124
|
)
|
118
125
|
);
|
119
126
|
}
|
120
127
|
break;
|
121
128
|
case enums.FilterMetaEnum.p_not_in_tags.op:
|
122
129
|
{
|
123
|
-
const
|
124
|
-
|
130
|
+
const cast_filter = /** @type {Filter_p_not_in_tags} */ (
|
131
|
+
filter
|
125
132
|
);
|
133
|
+
const value = cast_filter?.value ?? [];
|
126
134
|
|
127
135
|
conjunctions.push(
|
128
136
|
eb.not(
|
129
137
|
eb_in(
|
130
138
|
eb, 'entity_to_tags_projections',
|
131
|
-
|
139
|
+
value
|
132
140
|
)
|
133
141
|
)
|
134
142
|
);
|
@@ -136,30 +144,32 @@ export const discount_to_conjunctions = (eb, d) => {
|
|
136
144
|
break;
|
137
145
|
case enums.FilterMetaEnum.p_in_collections.op:
|
138
146
|
{
|
139
|
-
const
|
140
|
-
|
147
|
+
const cast_filter = /** @type {Filter_p_in_collections} */ (
|
148
|
+
filter
|
141
149
|
);
|
150
|
+
const value = cast_filter?.value ?? [];
|
142
151
|
|
143
152
|
// PROBLEM: we only have ids, but use handles in the filters
|
144
153
|
conjunctions.push(
|
145
154
|
eb_in(
|
146
155
|
eb, 'products_to_collections',
|
147
|
-
|
156
|
+
value.map(c => c.id)
|
148
157
|
)
|
149
158
|
);
|
150
159
|
}
|
151
160
|
break;
|
152
161
|
case enums.FilterMetaEnum.p_not_in_collections.op:
|
153
162
|
{
|
154
|
-
const
|
155
|
-
|
163
|
+
const cast_filter = /** @type {Filter_p_not_in_collections} */ (
|
164
|
+
filter
|
156
165
|
);
|
166
|
+
const value = cast_filter?.value ?? [];
|
157
167
|
|
158
168
|
conjunctions.push(
|
159
169
|
eb.not(
|
160
170
|
eb_in(
|
161
171
|
eb, 'products_to_collections',
|
162
|
-
|
172
|
+
value.map(c => c.id)
|
163
173
|
)
|
164
174
|
)
|
165
175
|
);
|
@@ -167,16 +177,17 @@ export const discount_to_conjunctions = (eb, d) => {
|
|
167
177
|
break;
|
168
178
|
case enums.FilterMetaEnum.p_in_price_range.op:
|
169
179
|
{
|
170
|
-
const
|
171
|
-
|
172
|
-
from: 0,
|
173
|
-
to: Number.POSITIVE_INFINITY,
|
174
|
-
...(filter?.value ?? {}),
|
175
|
-
}
|
180
|
+
const cast_filter = /** @type {Filter_p_in_price_range} */ (
|
181
|
+
filter
|
176
182
|
);
|
177
|
-
|
178
|
-
|
179
|
-
|
183
|
+
const value = /** @type {Filter_p_in_price_range["value"]} */({
|
184
|
+
from: 0,
|
185
|
+
to: Number.POSITIVE_INFINITY,
|
186
|
+
...(cast_filter?.value ?? {}),
|
187
|
+
});
|
188
|
+
|
189
|
+
const from = extract_abs_number(value.from);
|
190
|
+
const to = extract_abs_number(value.to);
|
180
191
|
|
181
192
|
const conj = { price: { $and: [] } };
|
182
193
|
|
package/src/con.images.js
CHANGED
@@ -9,7 +9,7 @@ import { count_regular, delete_me, delete_search_of,
|
|
9
9
|
insert_search_of, regular_upsert_me, where_id_or_handle_table
|
10
10
|
} from './con.shared.js'
|
11
11
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
12
|
-
import {
|
12
|
+
import { withQuery } from './utils.query.js'
|
13
13
|
import { Transaction } from 'kysely'
|
14
14
|
import { ID } from '@storecraft/core/api/utils.func.js'
|
15
15
|
import {
|
@@ -196,19 +196,24 @@ export const report_document_media = (driver) => {
|
|
196
196
|
*/
|
197
197
|
const list = (driver) => {
|
198
198
|
return async (query) => {
|
199
|
-
const items = await
|
199
|
+
const items = await withQuery(
|
200
|
+
driver.client
|
200
201
|
.selectFrom(table_name)
|
201
|
-
.selectAll()
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
)
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
202
|
+
.selectAll(),
|
203
|
+
query, table_name
|
204
|
+
).execute()
|
205
|
+
|
206
|
+
// .where(
|
207
|
+
// (eb) => {
|
208
|
+
// return query_to_eb(eb, query, table_name);
|
209
|
+
// }
|
210
|
+
// )
|
211
|
+
// .orderBy(query_to_sort(query, 'images')) // ts complains because `usage` field is absent
|
212
|
+
// .limit(query.limitToLast ?? query.limit ?? 10)
|
213
|
+
// .execute();
|
214
|
+
|
215
|
+
if(query.limitToLast)
|
216
|
+
items.reverse();
|
212
217
|
|
213
218
|
return sanitize_array(items);
|
214
219
|
}
|