@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { and, asc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { dropoffPriceRules, extraPriceRules, pickupPriceRules } from "./schema.js";
|
|
3
|
+
import { paginate } from "./service-shared.js";
|
|
4
|
+
export async function listPickupPriceRules(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.optionPriceRuleId) {
|
|
7
|
+
conditions.push(eq(pickupPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
8
|
+
}
|
|
9
|
+
if (query.optionId)
|
|
10
|
+
conditions.push(eq(pickupPriceRules.optionId, query.optionId));
|
|
11
|
+
if (query.pickupPointId)
|
|
12
|
+
conditions.push(eq(pickupPriceRules.pickupPointId, query.pickupPointId));
|
|
13
|
+
if (query.active !== undefined)
|
|
14
|
+
conditions.push(eq(pickupPriceRules.active, query.active));
|
|
15
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
16
|
+
return paginate(db
|
|
17
|
+
.select()
|
|
18
|
+
.from(pickupPriceRules)
|
|
19
|
+
.where(where)
|
|
20
|
+
.limit(query.limit)
|
|
21
|
+
.offset(query.offset)
|
|
22
|
+
.orderBy(asc(pickupPriceRules.sortOrder), asc(pickupPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(pickupPriceRules).where(where), query.limit, query.offset);
|
|
23
|
+
}
|
|
24
|
+
export async function getPickupPriceRuleById(db, id) {
|
|
25
|
+
const [row] = await db.select().from(pickupPriceRules).where(eq(pickupPriceRules.id, id)).limit(1);
|
|
26
|
+
return row ?? null;
|
|
27
|
+
}
|
|
28
|
+
export async function createPickupPriceRule(db, data) {
|
|
29
|
+
const [row] = await db.insert(pickupPriceRules).values(data).returning();
|
|
30
|
+
return row ?? null;
|
|
31
|
+
}
|
|
32
|
+
export async function updatePickupPriceRule(db, id, data) {
|
|
33
|
+
const [row] = await db
|
|
34
|
+
.update(pickupPriceRules)
|
|
35
|
+
.set({ ...data, updatedAt: new Date() })
|
|
36
|
+
.where(eq(pickupPriceRules.id, id))
|
|
37
|
+
.returning();
|
|
38
|
+
return row ?? null;
|
|
39
|
+
}
|
|
40
|
+
export async function deletePickupPriceRule(db, id) {
|
|
41
|
+
const [row] = await db
|
|
42
|
+
.delete(pickupPriceRules)
|
|
43
|
+
.where(eq(pickupPriceRules.id, id))
|
|
44
|
+
.returning({ id: pickupPriceRules.id });
|
|
45
|
+
return row ?? null;
|
|
46
|
+
}
|
|
47
|
+
export async function listDropoffPriceRules(db, query) {
|
|
48
|
+
const conditions = [];
|
|
49
|
+
if (query.optionPriceRuleId) {
|
|
50
|
+
conditions.push(eq(dropoffPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
51
|
+
}
|
|
52
|
+
if (query.optionId)
|
|
53
|
+
conditions.push(eq(dropoffPriceRules.optionId, query.optionId));
|
|
54
|
+
if (query.facilityId)
|
|
55
|
+
conditions.push(eq(dropoffPriceRules.facilityId, query.facilityId));
|
|
56
|
+
if (query.active !== undefined)
|
|
57
|
+
conditions.push(eq(dropoffPriceRules.active, query.active));
|
|
58
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
59
|
+
return paginate(db
|
|
60
|
+
.select()
|
|
61
|
+
.from(dropoffPriceRules)
|
|
62
|
+
.where(where)
|
|
63
|
+
.limit(query.limit)
|
|
64
|
+
.offset(query.offset)
|
|
65
|
+
.orderBy(asc(dropoffPriceRules.sortOrder), asc(dropoffPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(dropoffPriceRules).where(where), query.limit, query.offset);
|
|
66
|
+
}
|
|
67
|
+
export async function getDropoffPriceRuleById(db, id) {
|
|
68
|
+
const [row] = await db
|
|
69
|
+
.select()
|
|
70
|
+
.from(dropoffPriceRules)
|
|
71
|
+
.where(eq(dropoffPriceRules.id, id))
|
|
72
|
+
.limit(1);
|
|
73
|
+
return row ?? null;
|
|
74
|
+
}
|
|
75
|
+
export async function createDropoffPriceRule(db, data) {
|
|
76
|
+
const [row] = await db.insert(dropoffPriceRules).values(data).returning();
|
|
77
|
+
return row ?? null;
|
|
78
|
+
}
|
|
79
|
+
export async function updateDropoffPriceRule(db, id, data) {
|
|
80
|
+
const [row] = await db
|
|
81
|
+
.update(dropoffPriceRules)
|
|
82
|
+
.set({ ...data, updatedAt: new Date() })
|
|
83
|
+
.where(eq(dropoffPriceRules.id, id))
|
|
84
|
+
.returning();
|
|
85
|
+
return row ?? null;
|
|
86
|
+
}
|
|
87
|
+
export async function deleteDropoffPriceRule(db, id) {
|
|
88
|
+
const [row] = await db
|
|
89
|
+
.delete(dropoffPriceRules)
|
|
90
|
+
.where(eq(dropoffPriceRules.id, id))
|
|
91
|
+
.returning({ id: dropoffPriceRules.id });
|
|
92
|
+
return row ?? null;
|
|
93
|
+
}
|
|
94
|
+
export async function listExtraPriceRules(db, query) {
|
|
95
|
+
const conditions = [];
|
|
96
|
+
if (query.optionPriceRuleId) {
|
|
97
|
+
conditions.push(eq(extraPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
98
|
+
}
|
|
99
|
+
if (query.optionId)
|
|
100
|
+
conditions.push(eq(extraPriceRules.optionId, query.optionId));
|
|
101
|
+
if (query.productExtraId)
|
|
102
|
+
conditions.push(eq(extraPriceRules.productExtraId, query.productExtraId));
|
|
103
|
+
if (query.optionExtraConfigId) {
|
|
104
|
+
conditions.push(eq(extraPriceRules.optionExtraConfigId, query.optionExtraConfigId));
|
|
105
|
+
}
|
|
106
|
+
if (query.active !== undefined)
|
|
107
|
+
conditions.push(eq(extraPriceRules.active, query.active));
|
|
108
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
109
|
+
return paginate(db
|
|
110
|
+
.select()
|
|
111
|
+
.from(extraPriceRules)
|
|
112
|
+
.where(where)
|
|
113
|
+
.limit(query.limit)
|
|
114
|
+
.offset(query.offset)
|
|
115
|
+
.orderBy(asc(extraPriceRules.sortOrder), asc(extraPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(extraPriceRules).where(where), query.limit, query.offset);
|
|
116
|
+
}
|
|
117
|
+
export async function getExtraPriceRuleById(db, id) {
|
|
118
|
+
const [row] = await db.select().from(extraPriceRules).where(eq(extraPriceRules.id, id)).limit(1);
|
|
119
|
+
return row ?? null;
|
|
120
|
+
}
|
|
121
|
+
export async function createExtraPriceRule(db, data) {
|
|
122
|
+
const [row] = await db.insert(extraPriceRules).values(data).returning();
|
|
123
|
+
return row ?? null;
|
|
124
|
+
}
|
|
125
|
+
export async function updateExtraPriceRule(db, id, data) {
|
|
126
|
+
const [row] = await db
|
|
127
|
+
.update(extraPriceRules)
|
|
128
|
+
.set({ ...data, updatedAt: new Date() })
|
|
129
|
+
.where(eq(extraPriceRules.id, id))
|
|
130
|
+
.returning();
|
|
131
|
+
return row ?? null;
|
|
132
|
+
}
|
|
133
|
+
export async function deleteExtraPriceRule(db, id) {
|
|
134
|
+
const [row] = await db
|
|
135
|
+
.delete(extraPriceRules)
|
|
136
|
+
.where(eq(extraPriceRules.id, id))
|
|
137
|
+
.returning({ id: extraPriceRules.id });
|
|
138
|
+
return row ?? null;
|
|
139
|
+
}
|