@voyantjs/pricing 0.2.0 → 0.3.1
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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/routes-core.d.ts +981 -0
- package/dist/routes-core.d.ts.map +1 -0
- package/dist/routes-core.js +101 -0
- package/dist/routes-public.d.ts +136 -0
- package/dist/routes-public.d.ts.map +1 -0
- package/dist/routes-public.js +13 -0
- package/dist/routes-rules.d.ts +1176 -0
- package/dist/routes-rules.d.ts.map +1 -0
- package/dist/routes-rules.js +117 -0
- package/dist/routes-shared.d.ts +12 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +3 -0
- package/dist/routes.d.ts +5 -2160
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +5 -354
- package/dist/schema-catalogs.d.ts +467 -0
- package/dist/schema-catalogs.d.ts.map +1 -0
- package/dist/schema-catalogs.js +44 -0
- package/dist/schema-categories.d.ts +497 -0
- package/dist/schema-categories.d.ts.map +1 -0
- package/dist/schema-categories.js +50 -0
- package/dist/schema-option-rules.d.ts +1770 -0
- package/dist/schema-option-rules.d.ts.map +1 -0
- package/dist/schema-option-rules.js +174 -0
- package/dist/schema-policies.d.ts +395 -0
- package/dist/schema-policies.d.ts.map +1 -0
- package/dist/schema-policies.js +38 -0
- package/dist/schema-relations.d.ts +55 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +103 -0
- package/dist/schema-shared.d.ts +11 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +67 -0
- package/dist/schema.d.ts +6 -3189
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +6 -458
- package/dist/service-catalogs.d.ts +139 -0
- package/dist/service-catalogs.d.ts.map +1 -0
- package/dist/service-catalogs.js +89 -0
- package/dist/service-categories.d.ts +147 -0
- package/dist/service-categories.d.ts.map +1 -0
- package/dist/service-categories.js +105 -0
- package/dist/service-option-rules.d.ts +307 -0
- package/dist/service-option-rules.d.ts.map +1 -0
- package/dist/service-option-rules.js +188 -0
- package/dist/service-policies.d.ts +123 -0
- package/dist/service-policies.d.ts.map +1 -0
- package/dist/service-policies.js +95 -0
- package/dist/service-public.d.ts +89 -0
- package/dist/service-public.d.ts.map +1 -0
- package/dist/service-public.js +355 -0
- package/dist/service-shared.d.ts +50 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +4 -0
- package/dist/service-transfer-rules.d.ts +211 -0
- package/dist/service-transfer-rules.d.ts.map +1 -0
- package/dist/service-transfer-rules.js +139 -0
- package/dist/service.d.ts +70 -955
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +70 -595
- package/dist/validation-public.d.ts +410 -0
- package/dist/validation-public.d.ts.map +1 -0
- package/dist/validation-public.js +109 -0
- package/dist/validation-shared.d.ts +71 -0
- package/dist/validation-shared.d.ts.map +1 -0
- package/dist/validation-shared.js +63 -0
- package/dist/validation.d.ts +4 -69
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +5 -62
- package/package.json +16 -8
package/dist/service.js
CHANGED
|
@@ -1,597 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { createPriceCatalog, createPriceSchedule, deletePriceCatalog, deletePriceSchedule, getPriceCatalogById, getPriceScheduleById, listPriceCatalogs, listPriceSchedules, updatePriceCatalog, updatePriceSchedule, } from "./service-catalogs.js";
|
|
2
|
+
import { createPricingCategory, createPricingCategoryDependency, deletePricingCategory, deletePricingCategoryDependency, getPricingCategoryById, getPricingCategoryDependencyById, listPricingCategories, listPricingCategoryDependencies, updatePricingCategory, updatePricingCategoryDependency, } from "./service-categories.js";
|
|
3
|
+
import { createOptionPriceRule, createOptionStartTimeRule, createOptionUnitPriceRule, createOptionUnitTier, deleteOptionPriceRule, deleteOptionStartTimeRule, deleteOptionUnitPriceRule, deleteOptionUnitTier, getOptionPriceRuleById, getOptionStartTimeRuleById, getOptionUnitPriceRuleById, getOptionUnitTierById, listOptionPriceRules, listOptionStartTimeRules, listOptionUnitPriceRules, listOptionUnitTiers, updateOptionPriceRule, updateOptionStartTimeRule, updateOptionUnitPriceRule, updateOptionUnitTier, } from "./service-option-rules.js";
|
|
4
|
+
import { createCancellationPolicy, createCancellationPolicyRule, deleteCancellationPolicy, deleteCancellationPolicyRule, getCancellationPolicyById, getCancellationPolicyRuleById, listCancellationPolicies, listCancellationPolicyRules, updateCancellationPolicy, updateCancellationPolicyRule, } from "./service-policies.js";
|
|
5
|
+
import { createDropoffPriceRule, createExtraPriceRule, createPickupPriceRule, deleteDropoffPriceRule, deleteExtraPriceRule, deletePickupPriceRule, getDropoffPriceRuleById, getExtraPriceRuleById, getPickupPriceRuleById, listDropoffPriceRules, listExtraPriceRules, listPickupPriceRules, updateDropoffPriceRule, updateExtraPriceRule, updatePickupPriceRule, } from "./service-transfer-rules.js";
|
|
7
6
|
export const pricingService = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.orderBy(asc(pricingCategoryDependencies.createdAt)), db
|
|
74
|
-
.select({ count: sql `count(*)::int` })
|
|
75
|
-
.from(pricingCategoryDependencies)
|
|
76
|
-
.where(where), query.limit, query.offset);
|
|
77
|
-
},
|
|
78
|
-
async getPricingCategoryDependencyById(db, id) {
|
|
79
|
-
const [row] = await db
|
|
80
|
-
.select()
|
|
81
|
-
.from(pricingCategoryDependencies)
|
|
82
|
-
.where(eq(pricingCategoryDependencies.id, id))
|
|
83
|
-
.limit(1);
|
|
84
|
-
return row ?? null;
|
|
85
|
-
},
|
|
86
|
-
async createPricingCategoryDependency(db, data) {
|
|
87
|
-
const [row] = await db.insert(pricingCategoryDependencies).values(data).returning();
|
|
88
|
-
return row ?? null;
|
|
89
|
-
},
|
|
90
|
-
async updatePricingCategoryDependency(db, id, data) {
|
|
91
|
-
const [row] = await db
|
|
92
|
-
.update(pricingCategoryDependencies)
|
|
93
|
-
.set({ ...data, updatedAt: new Date() })
|
|
94
|
-
.where(eq(pricingCategoryDependencies.id, id))
|
|
95
|
-
.returning();
|
|
96
|
-
return row ?? null;
|
|
97
|
-
},
|
|
98
|
-
async deletePricingCategoryDependency(db, id) {
|
|
99
|
-
const [row] = await db
|
|
100
|
-
.delete(pricingCategoryDependencies)
|
|
101
|
-
.where(eq(pricingCategoryDependencies.id, id))
|
|
102
|
-
.returning({ id: pricingCategoryDependencies.id });
|
|
103
|
-
return row ?? null;
|
|
104
|
-
},
|
|
105
|
-
async listCancellationPolicies(db, query) {
|
|
106
|
-
const conditions = [];
|
|
107
|
-
if (query.policyType)
|
|
108
|
-
conditions.push(eq(cancellationPolicies.policyType, query.policyType));
|
|
109
|
-
if (query.active !== undefined)
|
|
110
|
-
conditions.push(eq(cancellationPolicies.active, query.active));
|
|
111
|
-
if (query.isDefault !== undefined)
|
|
112
|
-
conditions.push(eq(cancellationPolicies.isDefault, query.isDefault));
|
|
113
|
-
if (query.search) {
|
|
114
|
-
const term = `%${query.search}%`;
|
|
115
|
-
conditions.push(or(ilike(cancellationPolicies.name, term), ilike(cancellationPolicies.code, term)));
|
|
116
|
-
}
|
|
117
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
118
|
-
return paginate(db
|
|
119
|
-
.select()
|
|
120
|
-
.from(cancellationPolicies)
|
|
121
|
-
.where(where)
|
|
122
|
-
.limit(query.limit)
|
|
123
|
-
.offset(query.offset)
|
|
124
|
-
.orderBy(desc(cancellationPolicies.updatedAt)), db.select({ count: sql `count(*)::int` }).from(cancellationPolicies).where(where), query.limit, query.offset);
|
|
125
|
-
},
|
|
126
|
-
async getCancellationPolicyById(db, id) {
|
|
127
|
-
const [row] = await db
|
|
128
|
-
.select()
|
|
129
|
-
.from(cancellationPolicies)
|
|
130
|
-
.where(eq(cancellationPolicies.id, id))
|
|
131
|
-
.limit(1);
|
|
132
|
-
return row ?? null;
|
|
133
|
-
},
|
|
134
|
-
async createCancellationPolicy(db, data) {
|
|
135
|
-
const [row] = await db.insert(cancellationPolicies).values(data).returning();
|
|
136
|
-
return row ?? null;
|
|
137
|
-
},
|
|
138
|
-
async updateCancellationPolicy(db, id, data) {
|
|
139
|
-
const [row] = await db
|
|
140
|
-
.update(cancellationPolicies)
|
|
141
|
-
.set({ ...data, updatedAt: new Date() })
|
|
142
|
-
.where(eq(cancellationPolicies.id, id))
|
|
143
|
-
.returning();
|
|
144
|
-
return row ?? null;
|
|
145
|
-
},
|
|
146
|
-
async deleteCancellationPolicy(db, id) {
|
|
147
|
-
const [row] = await db
|
|
148
|
-
.delete(cancellationPolicies)
|
|
149
|
-
.where(eq(cancellationPolicies.id, id))
|
|
150
|
-
.returning({ id: cancellationPolicies.id });
|
|
151
|
-
return row ?? null;
|
|
152
|
-
},
|
|
153
|
-
async listCancellationPolicyRules(db, query) {
|
|
154
|
-
const conditions = [];
|
|
155
|
-
if (query.cancellationPolicyId)
|
|
156
|
-
conditions.push(eq(cancellationPolicyRules.cancellationPolicyId, query.cancellationPolicyId));
|
|
157
|
-
if (query.active !== undefined)
|
|
158
|
-
conditions.push(eq(cancellationPolicyRules.active, query.active));
|
|
159
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
160
|
-
return paginate(db
|
|
161
|
-
.select()
|
|
162
|
-
.from(cancellationPolicyRules)
|
|
163
|
-
.where(where)
|
|
164
|
-
.limit(query.limit)
|
|
165
|
-
.offset(query.offset)
|
|
166
|
-
.orderBy(asc(cancellationPolicyRules.sortOrder), asc(cancellationPolicyRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(cancellationPolicyRules).where(where), query.limit, query.offset);
|
|
167
|
-
},
|
|
168
|
-
async getCancellationPolicyRuleById(db, id) {
|
|
169
|
-
const [row] = await db
|
|
170
|
-
.select()
|
|
171
|
-
.from(cancellationPolicyRules)
|
|
172
|
-
.where(eq(cancellationPolicyRules.id, id))
|
|
173
|
-
.limit(1);
|
|
174
|
-
return row ?? null;
|
|
175
|
-
},
|
|
176
|
-
async createCancellationPolicyRule(db, data) {
|
|
177
|
-
const [row] = await db.insert(cancellationPolicyRules).values(data).returning();
|
|
178
|
-
return row ?? null;
|
|
179
|
-
},
|
|
180
|
-
async updateCancellationPolicyRule(db, id, data) {
|
|
181
|
-
const [row] = await db
|
|
182
|
-
.update(cancellationPolicyRules)
|
|
183
|
-
.set({ ...data, updatedAt: new Date() })
|
|
184
|
-
.where(eq(cancellationPolicyRules.id, id))
|
|
185
|
-
.returning();
|
|
186
|
-
return row ?? null;
|
|
187
|
-
},
|
|
188
|
-
async deleteCancellationPolicyRule(db, id) {
|
|
189
|
-
const [row] = await db
|
|
190
|
-
.delete(cancellationPolicyRules)
|
|
191
|
-
.where(eq(cancellationPolicyRules.id, id))
|
|
192
|
-
.returning({ id: cancellationPolicyRules.id });
|
|
193
|
-
return row ?? null;
|
|
194
|
-
},
|
|
195
|
-
async listPriceCatalogs(db, query) {
|
|
196
|
-
const conditions = [];
|
|
197
|
-
if (query.currencyCode)
|
|
198
|
-
conditions.push(eq(priceCatalogs.currencyCode, query.currencyCode));
|
|
199
|
-
if (query.catalogType)
|
|
200
|
-
conditions.push(eq(priceCatalogs.catalogType, query.catalogType));
|
|
201
|
-
if (query.active !== undefined)
|
|
202
|
-
conditions.push(eq(priceCatalogs.active, query.active));
|
|
203
|
-
if (query.search) {
|
|
204
|
-
const term = `%${query.search}%`;
|
|
205
|
-
conditions.push(or(ilike(priceCatalogs.name, term), ilike(priceCatalogs.code, term)));
|
|
206
|
-
}
|
|
207
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
208
|
-
return paginate(db
|
|
209
|
-
.select()
|
|
210
|
-
.from(priceCatalogs)
|
|
211
|
-
.where(where)
|
|
212
|
-
.limit(query.limit)
|
|
213
|
-
.offset(query.offset)
|
|
214
|
-
.orderBy(asc(priceCatalogs.name)), db.select({ count: sql `count(*)::int` }).from(priceCatalogs).where(where), query.limit, query.offset);
|
|
215
|
-
},
|
|
216
|
-
async getPriceCatalogById(db, id) {
|
|
217
|
-
const [row] = await db.select().from(priceCatalogs).where(eq(priceCatalogs.id, id)).limit(1);
|
|
218
|
-
return row ?? null;
|
|
219
|
-
},
|
|
220
|
-
async createPriceCatalog(db, data) {
|
|
221
|
-
const [row] = await db.insert(priceCatalogs).values(data).returning();
|
|
222
|
-
return row ?? null;
|
|
223
|
-
},
|
|
224
|
-
async updatePriceCatalog(db, id, data) {
|
|
225
|
-
const [row] = await db
|
|
226
|
-
.update(priceCatalogs)
|
|
227
|
-
.set({ ...data, updatedAt: new Date() })
|
|
228
|
-
.where(eq(priceCatalogs.id, id))
|
|
229
|
-
.returning();
|
|
230
|
-
return row ?? null;
|
|
231
|
-
},
|
|
232
|
-
async deletePriceCatalog(db, id) {
|
|
233
|
-
const [row] = await db
|
|
234
|
-
.delete(priceCatalogs)
|
|
235
|
-
.where(eq(priceCatalogs.id, id))
|
|
236
|
-
.returning({ id: priceCatalogs.id });
|
|
237
|
-
return row ?? null;
|
|
238
|
-
},
|
|
239
|
-
async listPriceSchedules(db, query) {
|
|
240
|
-
const conditions = [];
|
|
241
|
-
if (query.priceCatalogId)
|
|
242
|
-
conditions.push(eq(priceSchedules.priceCatalogId, query.priceCatalogId));
|
|
243
|
-
if (query.active !== undefined)
|
|
244
|
-
conditions.push(eq(priceSchedules.active, query.active));
|
|
245
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
246
|
-
return paginate(db
|
|
247
|
-
.select()
|
|
248
|
-
.from(priceSchedules)
|
|
249
|
-
.where(where)
|
|
250
|
-
.limit(query.limit)
|
|
251
|
-
.offset(query.offset)
|
|
252
|
-
.orderBy(desc(priceSchedules.priority), asc(priceSchedules.name)), db.select({ count: sql `count(*)::int` }).from(priceSchedules).where(where), query.limit, query.offset);
|
|
253
|
-
},
|
|
254
|
-
async getPriceScheduleById(db, id) {
|
|
255
|
-
const [row] = await db.select().from(priceSchedules).where(eq(priceSchedules.id, id)).limit(1);
|
|
256
|
-
return row ?? null;
|
|
257
|
-
},
|
|
258
|
-
async createPriceSchedule(db, data) {
|
|
259
|
-
const [row] = await db.insert(priceSchedules).values(data).returning();
|
|
260
|
-
return row ?? null;
|
|
261
|
-
},
|
|
262
|
-
async updatePriceSchedule(db, id, data) {
|
|
263
|
-
const [row] = await db
|
|
264
|
-
.update(priceSchedules)
|
|
265
|
-
.set({ ...data, updatedAt: new Date() })
|
|
266
|
-
.where(eq(priceSchedules.id, id))
|
|
267
|
-
.returning();
|
|
268
|
-
return row ?? null;
|
|
269
|
-
},
|
|
270
|
-
async deletePriceSchedule(db, id) {
|
|
271
|
-
const [row] = await db
|
|
272
|
-
.delete(priceSchedules)
|
|
273
|
-
.where(eq(priceSchedules.id, id))
|
|
274
|
-
.returning({ id: priceSchedules.id });
|
|
275
|
-
return row ?? null;
|
|
276
|
-
},
|
|
277
|
-
async listOptionPriceRules(db, query) {
|
|
278
|
-
const conditions = [];
|
|
279
|
-
if (query.productId)
|
|
280
|
-
conditions.push(eq(optionPriceRules.productId, query.productId));
|
|
281
|
-
if (query.optionId)
|
|
282
|
-
conditions.push(eq(optionPriceRules.optionId, query.optionId));
|
|
283
|
-
if (query.priceCatalogId)
|
|
284
|
-
conditions.push(eq(optionPriceRules.priceCatalogId, query.priceCatalogId));
|
|
285
|
-
if (query.priceScheduleId)
|
|
286
|
-
conditions.push(eq(optionPriceRules.priceScheduleId, query.priceScheduleId));
|
|
287
|
-
if (query.cancellationPolicyId)
|
|
288
|
-
conditions.push(eq(optionPriceRules.cancellationPolicyId, query.cancellationPolicyId));
|
|
289
|
-
if (query.pricingMode)
|
|
290
|
-
conditions.push(eq(optionPriceRules.pricingMode, query.pricingMode));
|
|
291
|
-
if (query.active !== undefined)
|
|
292
|
-
conditions.push(eq(optionPriceRules.active, query.active));
|
|
293
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
294
|
-
return paginate(db
|
|
295
|
-
.select()
|
|
296
|
-
.from(optionPriceRules)
|
|
297
|
-
.where(where)
|
|
298
|
-
.limit(query.limit)
|
|
299
|
-
.offset(query.offset)
|
|
300
|
-
.orderBy(desc(optionPriceRules.updatedAt)), db.select({ count: sql `count(*)::int` }).from(optionPriceRules).where(where), query.limit, query.offset);
|
|
301
|
-
},
|
|
302
|
-
async getOptionPriceRuleById(db, id) {
|
|
303
|
-
const [row] = await db
|
|
304
|
-
.select()
|
|
305
|
-
.from(optionPriceRules)
|
|
306
|
-
.where(eq(optionPriceRules.id, id))
|
|
307
|
-
.limit(1);
|
|
308
|
-
return row ?? null;
|
|
309
|
-
},
|
|
310
|
-
async createOptionPriceRule(db, data) {
|
|
311
|
-
const [row] = await db.insert(optionPriceRules).values(data).returning();
|
|
312
|
-
return row ?? null;
|
|
313
|
-
},
|
|
314
|
-
async updateOptionPriceRule(db, id, data) {
|
|
315
|
-
const [row] = await db
|
|
316
|
-
.update(optionPriceRules)
|
|
317
|
-
.set({ ...data, updatedAt: new Date() })
|
|
318
|
-
.where(eq(optionPriceRules.id, id))
|
|
319
|
-
.returning();
|
|
320
|
-
return row ?? null;
|
|
321
|
-
},
|
|
322
|
-
async deleteOptionPriceRule(db, id) {
|
|
323
|
-
const [row] = await db
|
|
324
|
-
.delete(optionPriceRules)
|
|
325
|
-
.where(eq(optionPriceRules.id, id))
|
|
326
|
-
.returning({ id: optionPriceRules.id });
|
|
327
|
-
return row ?? null;
|
|
328
|
-
},
|
|
329
|
-
async listOptionUnitPriceRules(db, query) {
|
|
330
|
-
const conditions = [];
|
|
331
|
-
if (query.optionPriceRuleId)
|
|
332
|
-
conditions.push(eq(optionUnitPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
333
|
-
if (query.optionId)
|
|
334
|
-
conditions.push(eq(optionUnitPriceRules.optionId, query.optionId));
|
|
335
|
-
if (query.unitId)
|
|
336
|
-
conditions.push(eq(optionUnitPriceRules.unitId, query.unitId));
|
|
337
|
-
if (query.pricingCategoryId)
|
|
338
|
-
conditions.push(eq(optionUnitPriceRules.pricingCategoryId, query.pricingCategoryId));
|
|
339
|
-
if (query.active !== undefined)
|
|
340
|
-
conditions.push(eq(optionUnitPriceRules.active, query.active));
|
|
341
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
342
|
-
return paginate(db
|
|
343
|
-
.select()
|
|
344
|
-
.from(optionUnitPriceRules)
|
|
345
|
-
.where(where)
|
|
346
|
-
.limit(query.limit)
|
|
347
|
-
.offset(query.offset)
|
|
348
|
-
.orderBy(asc(optionUnitPriceRules.sortOrder), asc(optionUnitPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(optionUnitPriceRules).where(where), query.limit, query.offset);
|
|
349
|
-
},
|
|
350
|
-
async getOptionUnitPriceRuleById(db, id) {
|
|
351
|
-
const [row] = await db
|
|
352
|
-
.select()
|
|
353
|
-
.from(optionUnitPriceRules)
|
|
354
|
-
.where(eq(optionUnitPriceRules.id, id))
|
|
355
|
-
.limit(1);
|
|
356
|
-
return row ?? null;
|
|
357
|
-
},
|
|
358
|
-
async createOptionUnitPriceRule(db, data) {
|
|
359
|
-
const [row] = await db.insert(optionUnitPriceRules).values(data).returning();
|
|
360
|
-
return row ?? null;
|
|
361
|
-
},
|
|
362
|
-
async updateOptionUnitPriceRule(db, id, data) {
|
|
363
|
-
const [row] = await db
|
|
364
|
-
.update(optionUnitPriceRules)
|
|
365
|
-
.set({ ...data, updatedAt: new Date() })
|
|
366
|
-
.where(eq(optionUnitPriceRules.id, id))
|
|
367
|
-
.returning();
|
|
368
|
-
return row ?? null;
|
|
369
|
-
},
|
|
370
|
-
async deleteOptionUnitPriceRule(db, id) {
|
|
371
|
-
const [row] = await db
|
|
372
|
-
.delete(optionUnitPriceRules)
|
|
373
|
-
.where(eq(optionUnitPriceRules.id, id))
|
|
374
|
-
.returning({ id: optionUnitPriceRules.id });
|
|
375
|
-
return row ?? null;
|
|
376
|
-
},
|
|
377
|
-
async listOptionStartTimeRules(db, query) {
|
|
378
|
-
const conditions = [];
|
|
379
|
-
if (query.optionPriceRuleId)
|
|
380
|
-
conditions.push(eq(optionStartTimeRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
381
|
-
if (query.optionId)
|
|
382
|
-
conditions.push(eq(optionStartTimeRules.optionId, query.optionId));
|
|
383
|
-
if (query.startTimeId)
|
|
384
|
-
conditions.push(eq(optionStartTimeRules.startTimeId, query.startTimeId));
|
|
385
|
-
if (query.active !== undefined)
|
|
386
|
-
conditions.push(eq(optionStartTimeRules.active, query.active));
|
|
387
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
388
|
-
return paginate(db
|
|
389
|
-
.select()
|
|
390
|
-
.from(optionStartTimeRules)
|
|
391
|
-
.where(where)
|
|
392
|
-
.limit(query.limit)
|
|
393
|
-
.offset(query.offset)
|
|
394
|
-
.orderBy(asc(optionStartTimeRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(optionStartTimeRules).where(where), query.limit, query.offset);
|
|
395
|
-
},
|
|
396
|
-
async getOptionStartTimeRuleById(db, id) {
|
|
397
|
-
const [row] = await db
|
|
398
|
-
.select()
|
|
399
|
-
.from(optionStartTimeRules)
|
|
400
|
-
.where(eq(optionStartTimeRules.id, id))
|
|
401
|
-
.limit(1);
|
|
402
|
-
return row ?? null;
|
|
403
|
-
},
|
|
404
|
-
async createOptionStartTimeRule(db, data) {
|
|
405
|
-
const [row] = await db.insert(optionStartTimeRules).values(data).returning();
|
|
406
|
-
return row ?? null;
|
|
407
|
-
},
|
|
408
|
-
async updateOptionStartTimeRule(db, id, data) {
|
|
409
|
-
const [row] = await db
|
|
410
|
-
.update(optionStartTimeRules)
|
|
411
|
-
.set({ ...data, updatedAt: new Date() })
|
|
412
|
-
.where(eq(optionStartTimeRules.id, id))
|
|
413
|
-
.returning();
|
|
414
|
-
return row ?? null;
|
|
415
|
-
},
|
|
416
|
-
async deleteOptionStartTimeRule(db, id) {
|
|
417
|
-
const [row] = await db
|
|
418
|
-
.delete(optionStartTimeRules)
|
|
419
|
-
.where(eq(optionStartTimeRules.id, id))
|
|
420
|
-
.returning({ id: optionStartTimeRules.id });
|
|
421
|
-
return row ?? null;
|
|
422
|
-
},
|
|
423
|
-
async listOptionUnitTiers(db, query) {
|
|
424
|
-
const conditions = [];
|
|
425
|
-
if (query.optionUnitPriceRuleId)
|
|
426
|
-
conditions.push(eq(optionUnitTiers.optionUnitPriceRuleId, query.optionUnitPriceRuleId));
|
|
427
|
-
if (query.active !== undefined)
|
|
428
|
-
conditions.push(eq(optionUnitTiers.active, query.active));
|
|
429
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
430
|
-
return paginate(db
|
|
431
|
-
.select()
|
|
432
|
-
.from(optionUnitTiers)
|
|
433
|
-
.where(where)
|
|
434
|
-
.limit(query.limit)
|
|
435
|
-
.offset(query.offset)
|
|
436
|
-
.orderBy(asc(optionUnitTiers.sortOrder), asc(optionUnitTiers.minQuantity)), db.select({ count: sql `count(*)::int` }).from(optionUnitTiers).where(where), query.limit, query.offset);
|
|
437
|
-
},
|
|
438
|
-
async getOptionUnitTierById(db, id) {
|
|
439
|
-
const [row] = await db.select().from(optionUnitTiers).where(eq(optionUnitTiers.id, id)).limit(1);
|
|
440
|
-
return row ?? null;
|
|
441
|
-
},
|
|
442
|
-
async createOptionUnitTier(db, data) {
|
|
443
|
-
const [row] = await db.insert(optionUnitTiers).values(data).returning();
|
|
444
|
-
return row ?? null;
|
|
445
|
-
},
|
|
446
|
-
async updateOptionUnitTier(db, id, data) {
|
|
447
|
-
const [row] = await db
|
|
448
|
-
.update(optionUnitTiers)
|
|
449
|
-
.set({ ...data, updatedAt: new Date() })
|
|
450
|
-
.where(eq(optionUnitTiers.id, id))
|
|
451
|
-
.returning();
|
|
452
|
-
return row ?? null;
|
|
453
|
-
},
|
|
454
|
-
async deleteOptionUnitTier(db, id) {
|
|
455
|
-
const [row] = await db
|
|
456
|
-
.delete(optionUnitTiers)
|
|
457
|
-
.where(eq(optionUnitTiers.id, id))
|
|
458
|
-
.returning({ id: optionUnitTiers.id });
|
|
459
|
-
return row ?? null;
|
|
460
|
-
},
|
|
461
|
-
async listPickupPriceRules(db, query) {
|
|
462
|
-
const conditions = [];
|
|
463
|
-
if (query.optionPriceRuleId)
|
|
464
|
-
conditions.push(eq(pickupPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
465
|
-
if (query.optionId)
|
|
466
|
-
conditions.push(eq(pickupPriceRules.optionId, query.optionId));
|
|
467
|
-
if (query.pickupPointId)
|
|
468
|
-
conditions.push(eq(pickupPriceRules.pickupPointId, query.pickupPointId));
|
|
469
|
-
if (query.active !== undefined)
|
|
470
|
-
conditions.push(eq(pickupPriceRules.active, query.active));
|
|
471
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
472
|
-
return paginate(db
|
|
473
|
-
.select()
|
|
474
|
-
.from(pickupPriceRules)
|
|
475
|
-
.where(where)
|
|
476
|
-
.limit(query.limit)
|
|
477
|
-
.offset(query.offset)
|
|
478
|
-
.orderBy(asc(pickupPriceRules.sortOrder), asc(pickupPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(pickupPriceRules).where(where), query.limit, query.offset);
|
|
479
|
-
},
|
|
480
|
-
async getPickupPriceRuleById(db, id) {
|
|
481
|
-
const [row] = await db
|
|
482
|
-
.select()
|
|
483
|
-
.from(pickupPriceRules)
|
|
484
|
-
.where(eq(pickupPriceRules.id, id))
|
|
485
|
-
.limit(1);
|
|
486
|
-
return row ?? null;
|
|
487
|
-
},
|
|
488
|
-
async createPickupPriceRule(db, data) {
|
|
489
|
-
const [row] = await db.insert(pickupPriceRules).values(data).returning();
|
|
490
|
-
return row ?? null;
|
|
491
|
-
},
|
|
492
|
-
async updatePickupPriceRule(db, id, data) {
|
|
493
|
-
const [row] = await db
|
|
494
|
-
.update(pickupPriceRules)
|
|
495
|
-
.set({ ...data, updatedAt: new Date() })
|
|
496
|
-
.where(eq(pickupPriceRules.id, id))
|
|
497
|
-
.returning();
|
|
498
|
-
return row ?? null;
|
|
499
|
-
},
|
|
500
|
-
async deletePickupPriceRule(db, id) {
|
|
501
|
-
const [row] = await db
|
|
502
|
-
.delete(pickupPriceRules)
|
|
503
|
-
.where(eq(pickupPriceRules.id, id))
|
|
504
|
-
.returning({ id: pickupPriceRules.id });
|
|
505
|
-
return row ?? null;
|
|
506
|
-
},
|
|
507
|
-
async listDropoffPriceRules(db, query) {
|
|
508
|
-
const conditions = [];
|
|
509
|
-
if (query.optionPriceRuleId)
|
|
510
|
-
conditions.push(eq(dropoffPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
511
|
-
if (query.optionId)
|
|
512
|
-
conditions.push(eq(dropoffPriceRules.optionId, query.optionId));
|
|
513
|
-
if (query.facilityId)
|
|
514
|
-
conditions.push(eq(dropoffPriceRules.facilityId, query.facilityId));
|
|
515
|
-
if (query.active !== undefined)
|
|
516
|
-
conditions.push(eq(dropoffPriceRules.active, query.active));
|
|
517
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
518
|
-
return paginate(db
|
|
519
|
-
.select()
|
|
520
|
-
.from(dropoffPriceRules)
|
|
521
|
-
.where(where)
|
|
522
|
-
.limit(query.limit)
|
|
523
|
-
.offset(query.offset)
|
|
524
|
-
.orderBy(asc(dropoffPriceRules.sortOrder), asc(dropoffPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(dropoffPriceRules).where(where), query.limit, query.offset);
|
|
525
|
-
},
|
|
526
|
-
async getDropoffPriceRuleById(db, id) {
|
|
527
|
-
const [row] = await db
|
|
528
|
-
.select()
|
|
529
|
-
.from(dropoffPriceRules)
|
|
530
|
-
.where(eq(dropoffPriceRules.id, id))
|
|
531
|
-
.limit(1);
|
|
532
|
-
return row ?? null;
|
|
533
|
-
},
|
|
534
|
-
async createDropoffPriceRule(db, data) {
|
|
535
|
-
const [row] = await db.insert(dropoffPriceRules).values(data).returning();
|
|
536
|
-
return row ?? null;
|
|
537
|
-
},
|
|
538
|
-
async updateDropoffPriceRule(db, id, data) {
|
|
539
|
-
const [row] = await db
|
|
540
|
-
.update(dropoffPriceRules)
|
|
541
|
-
.set({ ...data, updatedAt: new Date() })
|
|
542
|
-
.where(eq(dropoffPriceRules.id, id))
|
|
543
|
-
.returning();
|
|
544
|
-
return row ?? null;
|
|
545
|
-
},
|
|
546
|
-
async deleteDropoffPriceRule(db, id) {
|
|
547
|
-
const [row] = await db
|
|
548
|
-
.delete(dropoffPriceRules)
|
|
549
|
-
.where(eq(dropoffPriceRules.id, id))
|
|
550
|
-
.returning({ id: dropoffPriceRules.id });
|
|
551
|
-
return row ?? null;
|
|
552
|
-
},
|
|
553
|
-
async listExtraPriceRules(db, query) {
|
|
554
|
-
const conditions = [];
|
|
555
|
-
if (query.optionPriceRuleId)
|
|
556
|
-
conditions.push(eq(extraPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
557
|
-
if (query.optionId)
|
|
558
|
-
conditions.push(eq(extraPriceRules.optionId, query.optionId));
|
|
559
|
-
if (query.productExtraId)
|
|
560
|
-
conditions.push(eq(extraPriceRules.productExtraId, query.productExtraId));
|
|
561
|
-
if (query.optionExtraConfigId)
|
|
562
|
-
conditions.push(eq(extraPriceRules.optionExtraConfigId, query.optionExtraConfigId));
|
|
563
|
-
if (query.active !== undefined)
|
|
564
|
-
conditions.push(eq(extraPriceRules.active, query.active));
|
|
565
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
566
|
-
return paginate(db
|
|
567
|
-
.select()
|
|
568
|
-
.from(extraPriceRules)
|
|
569
|
-
.where(where)
|
|
570
|
-
.limit(query.limit)
|
|
571
|
-
.offset(query.offset)
|
|
572
|
-
.orderBy(asc(extraPriceRules.sortOrder), asc(extraPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(extraPriceRules).where(where), query.limit, query.offset);
|
|
573
|
-
},
|
|
574
|
-
async getExtraPriceRuleById(db, id) {
|
|
575
|
-
const [row] = await db.select().from(extraPriceRules).where(eq(extraPriceRules.id, id)).limit(1);
|
|
576
|
-
return row ?? null;
|
|
577
|
-
},
|
|
578
|
-
async createExtraPriceRule(db, data) {
|
|
579
|
-
const [row] = await db.insert(extraPriceRules).values(data).returning();
|
|
580
|
-
return row ?? null;
|
|
581
|
-
},
|
|
582
|
-
async updateExtraPriceRule(db, id, data) {
|
|
583
|
-
const [row] = await db
|
|
584
|
-
.update(extraPriceRules)
|
|
585
|
-
.set({ ...data, updatedAt: new Date() })
|
|
586
|
-
.where(eq(extraPriceRules.id, id))
|
|
587
|
-
.returning();
|
|
588
|
-
return row ?? null;
|
|
589
|
-
},
|
|
590
|
-
async deleteExtraPriceRule(db, id) {
|
|
591
|
-
const [row] = await db
|
|
592
|
-
.delete(extraPriceRules)
|
|
593
|
-
.where(eq(extraPriceRules.id, id))
|
|
594
|
-
.returning({ id: extraPriceRules.id });
|
|
595
|
-
return row ?? null;
|
|
596
|
-
},
|
|
7
|
+
listPricingCategories,
|
|
8
|
+
getPricingCategoryById,
|
|
9
|
+
createPricingCategory,
|
|
10
|
+
updatePricingCategory,
|
|
11
|
+
deletePricingCategory,
|
|
12
|
+
listPricingCategoryDependencies,
|
|
13
|
+
getPricingCategoryDependencyById,
|
|
14
|
+
createPricingCategoryDependency,
|
|
15
|
+
updatePricingCategoryDependency,
|
|
16
|
+
deletePricingCategoryDependency,
|
|
17
|
+
listCancellationPolicies,
|
|
18
|
+
getCancellationPolicyById,
|
|
19
|
+
createCancellationPolicy,
|
|
20
|
+
updateCancellationPolicy,
|
|
21
|
+
deleteCancellationPolicy,
|
|
22
|
+
listCancellationPolicyRules,
|
|
23
|
+
getCancellationPolicyRuleById,
|
|
24
|
+
createCancellationPolicyRule,
|
|
25
|
+
updateCancellationPolicyRule,
|
|
26
|
+
deleteCancellationPolicyRule,
|
|
27
|
+
listPriceCatalogs,
|
|
28
|
+
getPriceCatalogById,
|
|
29
|
+
createPriceCatalog,
|
|
30
|
+
updatePriceCatalog,
|
|
31
|
+
deletePriceCatalog,
|
|
32
|
+
listPriceSchedules,
|
|
33
|
+
getPriceScheduleById,
|
|
34
|
+
createPriceSchedule,
|
|
35
|
+
updatePriceSchedule,
|
|
36
|
+
deletePriceSchedule,
|
|
37
|
+
listOptionPriceRules,
|
|
38
|
+
getOptionPriceRuleById,
|
|
39
|
+
createOptionPriceRule,
|
|
40
|
+
updateOptionPriceRule,
|
|
41
|
+
deleteOptionPriceRule,
|
|
42
|
+
listOptionUnitPriceRules,
|
|
43
|
+
getOptionUnitPriceRuleById,
|
|
44
|
+
createOptionUnitPriceRule,
|
|
45
|
+
updateOptionUnitPriceRule,
|
|
46
|
+
deleteOptionUnitPriceRule,
|
|
47
|
+
listOptionStartTimeRules,
|
|
48
|
+
getOptionStartTimeRuleById,
|
|
49
|
+
createOptionStartTimeRule,
|
|
50
|
+
updateOptionStartTimeRule,
|
|
51
|
+
deleteOptionStartTimeRule,
|
|
52
|
+
listOptionUnitTiers,
|
|
53
|
+
getOptionUnitTierById,
|
|
54
|
+
createOptionUnitTier,
|
|
55
|
+
updateOptionUnitTier,
|
|
56
|
+
deleteOptionUnitTier,
|
|
57
|
+
listPickupPriceRules,
|
|
58
|
+
getPickupPriceRuleById,
|
|
59
|
+
createPickupPriceRule,
|
|
60
|
+
updatePickupPriceRule,
|
|
61
|
+
deletePickupPriceRule,
|
|
62
|
+
listDropoffPriceRules,
|
|
63
|
+
getDropoffPriceRuleById,
|
|
64
|
+
createDropoffPriceRule,
|
|
65
|
+
updateDropoffPriceRule,
|
|
66
|
+
deleteDropoffPriceRule,
|
|
67
|
+
listExtraPriceRules,
|
|
68
|
+
getExtraPriceRuleById,
|
|
69
|
+
createExtraPriceRule,
|
|
70
|
+
updateExtraPriceRule,
|
|
71
|
+
deleteExtraPriceRule,
|
|
597
72
|
};
|