@voyantjs/pricing 0.2.0 → 0.3.0
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/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-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 +3 -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-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.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -0
- package/package.json +8 -8
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { and, asc, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { optionPriceRules, optionStartTimeRules, optionUnitPriceRules, optionUnitTiers, } from "./schema.js";
|
|
3
|
+
import { paginate } from "./service-shared.js";
|
|
4
|
+
export async function listOptionPriceRules(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.productId)
|
|
7
|
+
conditions.push(eq(optionPriceRules.productId, query.productId));
|
|
8
|
+
if (query.optionId)
|
|
9
|
+
conditions.push(eq(optionPriceRules.optionId, query.optionId));
|
|
10
|
+
if (query.priceCatalogId)
|
|
11
|
+
conditions.push(eq(optionPriceRules.priceCatalogId, query.priceCatalogId));
|
|
12
|
+
if (query.priceScheduleId)
|
|
13
|
+
conditions.push(eq(optionPriceRules.priceScheduleId, query.priceScheduleId));
|
|
14
|
+
if (query.cancellationPolicyId) {
|
|
15
|
+
conditions.push(eq(optionPriceRules.cancellationPolicyId, query.cancellationPolicyId));
|
|
16
|
+
}
|
|
17
|
+
if (query.pricingMode)
|
|
18
|
+
conditions.push(eq(optionPriceRules.pricingMode, query.pricingMode));
|
|
19
|
+
if (query.active !== undefined)
|
|
20
|
+
conditions.push(eq(optionPriceRules.active, query.active));
|
|
21
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
22
|
+
return paginate(db
|
|
23
|
+
.select()
|
|
24
|
+
.from(optionPriceRules)
|
|
25
|
+
.where(where)
|
|
26
|
+
.limit(query.limit)
|
|
27
|
+
.offset(query.offset)
|
|
28
|
+
.orderBy(desc(optionPriceRules.updatedAt)), db.select({ count: sql `count(*)::int` }).from(optionPriceRules).where(where), query.limit, query.offset);
|
|
29
|
+
}
|
|
30
|
+
export async function getOptionPriceRuleById(db, id) {
|
|
31
|
+
const [row] = await db.select().from(optionPriceRules).where(eq(optionPriceRules.id, id)).limit(1);
|
|
32
|
+
return row ?? null;
|
|
33
|
+
}
|
|
34
|
+
export async function createOptionPriceRule(db, data) {
|
|
35
|
+
const [row] = await db.insert(optionPriceRules).values(data).returning();
|
|
36
|
+
return row ?? null;
|
|
37
|
+
}
|
|
38
|
+
export async function updateOptionPriceRule(db, id, data) {
|
|
39
|
+
const [row] = await db
|
|
40
|
+
.update(optionPriceRules)
|
|
41
|
+
.set({ ...data, updatedAt: new Date() })
|
|
42
|
+
.where(eq(optionPriceRules.id, id))
|
|
43
|
+
.returning();
|
|
44
|
+
return row ?? null;
|
|
45
|
+
}
|
|
46
|
+
export async function deleteOptionPriceRule(db, id) {
|
|
47
|
+
const [row] = await db
|
|
48
|
+
.delete(optionPriceRules)
|
|
49
|
+
.where(eq(optionPriceRules.id, id))
|
|
50
|
+
.returning({ id: optionPriceRules.id });
|
|
51
|
+
return row ?? null;
|
|
52
|
+
}
|
|
53
|
+
export async function listOptionUnitPriceRules(db, query) {
|
|
54
|
+
const conditions = [];
|
|
55
|
+
if (query.optionPriceRuleId) {
|
|
56
|
+
conditions.push(eq(optionUnitPriceRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
57
|
+
}
|
|
58
|
+
if (query.optionId)
|
|
59
|
+
conditions.push(eq(optionUnitPriceRules.optionId, query.optionId));
|
|
60
|
+
if (query.unitId)
|
|
61
|
+
conditions.push(eq(optionUnitPriceRules.unitId, query.unitId));
|
|
62
|
+
if (query.pricingCategoryId) {
|
|
63
|
+
conditions.push(eq(optionUnitPriceRules.pricingCategoryId, query.pricingCategoryId));
|
|
64
|
+
}
|
|
65
|
+
if (query.active !== undefined)
|
|
66
|
+
conditions.push(eq(optionUnitPriceRules.active, query.active));
|
|
67
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
68
|
+
return paginate(db
|
|
69
|
+
.select()
|
|
70
|
+
.from(optionUnitPriceRules)
|
|
71
|
+
.where(where)
|
|
72
|
+
.limit(query.limit)
|
|
73
|
+
.offset(query.offset)
|
|
74
|
+
.orderBy(asc(optionUnitPriceRules.sortOrder), asc(optionUnitPriceRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(optionUnitPriceRules).where(where), query.limit, query.offset);
|
|
75
|
+
}
|
|
76
|
+
export async function getOptionUnitPriceRuleById(db, id) {
|
|
77
|
+
const [row] = await db
|
|
78
|
+
.select()
|
|
79
|
+
.from(optionUnitPriceRules)
|
|
80
|
+
.where(eq(optionUnitPriceRules.id, id))
|
|
81
|
+
.limit(1);
|
|
82
|
+
return row ?? null;
|
|
83
|
+
}
|
|
84
|
+
export async function createOptionUnitPriceRule(db, data) {
|
|
85
|
+
const [row] = await db.insert(optionUnitPriceRules).values(data).returning();
|
|
86
|
+
return row ?? null;
|
|
87
|
+
}
|
|
88
|
+
export async function updateOptionUnitPriceRule(db, id, data) {
|
|
89
|
+
const [row] = await db
|
|
90
|
+
.update(optionUnitPriceRules)
|
|
91
|
+
.set({ ...data, updatedAt: new Date() })
|
|
92
|
+
.where(eq(optionUnitPriceRules.id, id))
|
|
93
|
+
.returning();
|
|
94
|
+
return row ?? null;
|
|
95
|
+
}
|
|
96
|
+
export async function deleteOptionUnitPriceRule(db, id) {
|
|
97
|
+
const [row] = await db
|
|
98
|
+
.delete(optionUnitPriceRules)
|
|
99
|
+
.where(eq(optionUnitPriceRules.id, id))
|
|
100
|
+
.returning({ id: optionUnitPriceRules.id });
|
|
101
|
+
return row ?? null;
|
|
102
|
+
}
|
|
103
|
+
export async function listOptionStartTimeRules(db, query) {
|
|
104
|
+
const conditions = [];
|
|
105
|
+
if (query.optionPriceRuleId) {
|
|
106
|
+
conditions.push(eq(optionStartTimeRules.optionPriceRuleId, query.optionPriceRuleId));
|
|
107
|
+
}
|
|
108
|
+
if (query.optionId)
|
|
109
|
+
conditions.push(eq(optionStartTimeRules.optionId, query.optionId));
|
|
110
|
+
if (query.startTimeId)
|
|
111
|
+
conditions.push(eq(optionStartTimeRules.startTimeId, query.startTimeId));
|
|
112
|
+
if (query.active !== undefined)
|
|
113
|
+
conditions.push(eq(optionStartTimeRules.active, query.active));
|
|
114
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
115
|
+
return paginate(db
|
|
116
|
+
.select()
|
|
117
|
+
.from(optionStartTimeRules)
|
|
118
|
+
.where(where)
|
|
119
|
+
.limit(query.limit)
|
|
120
|
+
.offset(query.offset)
|
|
121
|
+
.orderBy(asc(optionStartTimeRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(optionStartTimeRules).where(where), query.limit, query.offset);
|
|
122
|
+
}
|
|
123
|
+
export async function getOptionStartTimeRuleById(db, id) {
|
|
124
|
+
const [row] = await db
|
|
125
|
+
.select()
|
|
126
|
+
.from(optionStartTimeRules)
|
|
127
|
+
.where(eq(optionStartTimeRules.id, id))
|
|
128
|
+
.limit(1);
|
|
129
|
+
return row ?? null;
|
|
130
|
+
}
|
|
131
|
+
export async function createOptionStartTimeRule(db, data) {
|
|
132
|
+
const [row] = await db.insert(optionStartTimeRules).values(data).returning();
|
|
133
|
+
return row ?? null;
|
|
134
|
+
}
|
|
135
|
+
export async function updateOptionStartTimeRule(db, id, data) {
|
|
136
|
+
const [row] = await db
|
|
137
|
+
.update(optionStartTimeRules)
|
|
138
|
+
.set({ ...data, updatedAt: new Date() })
|
|
139
|
+
.where(eq(optionStartTimeRules.id, id))
|
|
140
|
+
.returning();
|
|
141
|
+
return row ?? null;
|
|
142
|
+
}
|
|
143
|
+
export async function deleteOptionStartTimeRule(db, id) {
|
|
144
|
+
const [row] = await db
|
|
145
|
+
.delete(optionStartTimeRules)
|
|
146
|
+
.where(eq(optionStartTimeRules.id, id))
|
|
147
|
+
.returning({ id: optionStartTimeRules.id });
|
|
148
|
+
return row ?? null;
|
|
149
|
+
}
|
|
150
|
+
export async function listOptionUnitTiers(db, query) {
|
|
151
|
+
const conditions = [];
|
|
152
|
+
if (query.optionUnitPriceRuleId) {
|
|
153
|
+
conditions.push(eq(optionUnitTiers.optionUnitPriceRuleId, query.optionUnitPriceRuleId));
|
|
154
|
+
}
|
|
155
|
+
if (query.active !== undefined)
|
|
156
|
+
conditions.push(eq(optionUnitTiers.active, query.active));
|
|
157
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
158
|
+
return paginate(db
|
|
159
|
+
.select()
|
|
160
|
+
.from(optionUnitTiers)
|
|
161
|
+
.where(where)
|
|
162
|
+
.limit(query.limit)
|
|
163
|
+
.offset(query.offset)
|
|
164
|
+
.orderBy(asc(optionUnitTiers.sortOrder), asc(optionUnitTiers.minQuantity)), db.select({ count: sql `count(*)::int` }).from(optionUnitTiers).where(where), query.limit, query.offset);
|
|
165
|
+
}
|
|
166
|
+
export async function getOptionUnitTierById(db, id) {
|
|
167
|
+
const [row] = await db.select().from(optionUnitTiers).where(eq(optionUnitTiers.id, id)).limit(1);
|
|
168
|
+
return row ?? null;
|
|
169
|
+
}
|
|
170
|
+
export async function createOptionUnitTier(db, data) {
|
|
171
|
+
const [row] = await db.insert(optionUnitTiers).values(data).returning();
|
|
172
|
+
return row ?? null;
|
|
173
|
+
}
|
|
174
|
+
export async function updateOptionUnitTier(db, id, data) {
|
|
175
|
+
const [row] = await db
|
|
176
|
+
.update(optionUnitTiers)
|
|
177
|
+
.set({ ...data, updatedAt: new Date() })
|
|
178
|
+
.where(eq(optionUnitTiers.id, id))
|
|
179
|
+
.returning();
|
|
180
|
+
return row ?? null;
|
|
181
|
+
}
|
|
182
|
+
export async function deleteOptionUnitTier(db, id) {
|
|
183
|
+
const [row] = await db
|
|
184
|
+
.delete(optionUnitTiers)
|
|
185
|
+
.where(eq(optionUnitTiers.id, id))
|
|
186
|
+
.returning({ id: optionUnitTiers.id });
|
|
187
|
+
return row ?? null;
|
|
188
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { CancellationPolicyListQuery, CancellationPolicyRuleListQuery, CreateCancellationPolicyInput, CreateCancellationPolicyRuleInput, UpdateCancellationPolicyInput, UpdateCancellationPolicyRuleInput } from "./service-shared.js";
|
|
3
|
+
export declare function listCancellationPolicies(db: PostgresJsDatabase, query: CancellationPolicyListQuery): Promise<{
|
|
4
|
+
data: {
|
|
5
|
+
id: string;
|
|
6
|
+
code: string | null;
|
|
7
|
+
name: string;
|
|
8
|
+
policyType: "simple" | "advanced" | "non_refundable" | "custom";
|
|
9
|
+
simpleCutoffHours: number | null;
|
|
10
|
+
isDefault: boolean;
|
|
11
|
+
active: boolean;
|
|
12
|
+
notes: string | null;
|
|
13
|
+
metadata: Record<string, unknown> | null;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
}[];
|
|
17
|
+
total: number;
|
|
18
|
+
limit: number;
|
|
19
|
+
offset: number;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function getCancellationPolicyById(db: PostgresJsDatabase, id: string): Promise<{
|
|
22
|
+
id: string;
|
|
23
|
+
code: string | null;
|
|
24
|
+
name: string;
|
|
25
|
+
policyType: "simple" | "advanced" | "non_refundable" | "custom";
|
|
26
|
+
simpleCutoffHours: number | null;
|
|
27
|
+
isDefault: boolean;
|
|
28
|
+
active: boolean;
|
|
29
|
+
notes: string | null;
|
|
30
|
+
metadata: Record<string, unknown> | null;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
} | null>;
|
|
34
|
+
export declare function createCancellationPolicy(db: PostgresJsDatabase, data: CreateCancellationPolicyInput): Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
code: string | null;
|
|
38
|
+
isDefault: boolean;
|
|
39
|
+
active: boolean;
|
|
40
|
+
notes: string | null;
|
|
41
|
+
metadata: Record<string, unknown> | null;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
policyType: "simple" | "advanced" | "non_refundable" | "custom";
|
|
45
|
+
simpleCutoffHours: number | null;
|
|
46
|
+
} | null>;
|
|
47
|
+
export declare function updateCancellationPolicy(db: PostgresJsDatabase, id: string, data: UpdateCancellationPolicyInput): Promise<{
|
|
48
|
+
id: string;
|
|
49
|
+
code: string | null;
|
|
50
|
+
name: string;
|
|
51
|
+
policyType: "simple" | "advanced" | "non_refundable" | "custom";
|
|
52
|
+
simpleCutoffHours: number | null;
|
|
53
|
+
isDefault: boolean;
|
|
54
|
+
active: boolean;
|
|
55
|
+
notes: string | null;
|
|
56
|
+
metadata: Record<string, unknown> | null;
|
|
57
|
+
createdAt: Date;
|
|
58
|
+
updatedAt: Date;
|
|
59
|
+
} | null>;
|
|
60
|
+
export declare function deleteCancellationPolicy(db: PostgresJsDatabase, id: string): Promise<{
|
|
61
|
+
id: string;
|
|
62
|
+
} | null>;
|
|
63
|
+
export declare function listCancellationPolicyRules(db: PostgresJsDatabase, query: CancellationPolicyRuleListQuery): Promise<{
|
|
64
|
+
data: {
|
|
65
|
+
id: string;
|
|
66
|
+
cancellationPolicyId: string;
|
|
67
|
+
sortOrder: number;
|
|
68
|
+
cutoffMinutesBefore: number | null;
|
|
69
|
+
chargeType: "none" | "amount" | "percentage";
|
|
70
|
+
chargeAmountCents: number | null;
|
|
71
|
+
chargePercentBasisPoints: number | null;
|
|
72
|
+
active: boolean;
|
|
73
|
+
notes: string | null;
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
updatedAt: Date;
|
|
76
|
+
}[];
|
|
77
|
+
total: number;
|
|
78
|
+
limit: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
}>;
|
|
81
|
+
export declare function getCancellationPolicyRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
cancellationPolicyId: string;
|
|
84
|
+
sortOrder: number;
|
|
85
|
+
cutoffMinutesBefore: number | null;
|
|
86
|
+
chargeType: "none" | "amount" | "percentage";
|
|
87
|
+
chargeAmountCents: number | null;
|
|
88
|
+
chargePercentBasisPoints: number | null;
|
|
89
|
+
active: boolean;
|
|
90
|
+
notes: string | null;
|
|
91
|
+
createdAt: Date;
|
|
92
|
+
updatedAt: Date;
|
|
93
|
+
} | null>;
|
|
94
|
+
export declare function createCancellationPolicyRule(db: PostgresJsDatabase, data: CreateCancellationPolicyRuleInput): Promise<{
|
|
95
|
+
id: string;
|
|
96
|
+
active: boolean;
|
|
97
|
+
notes: string | null;
|
|
98
|
+
createdAt: Date;
|
|
99
|
+
updatedAt: Date;
|
|
100
|
+
sortOrder: number;
|
|
101
|
+
cancellationPolicyId: string;
|
|
102
|
+
cutoffMinutesBefore: number | null;
|
|
103
|
+
chargeType: "none" | "amount" | "percentage";
|
|
104
|
+
chargeAmountCents: number | null;
|
|
105
|
+
chargePercentBasisPoints: number | null;
|
|
106
|
+
} | null>;
|
|
107
|
+
export declare function updateCancellationPolicyRule(db: PostgresJsDatabase, id: string, data: UpdateCancellationPolicyRuleInput): Promise<{
|
|
108
|
+
id: string;
|
|
109
|
+
cancellationPolicyId: string;
|
|
110
|
+
sortOrder: number;
|
|
111
|
+
cutoffMinutesBefore: number | null;
|
|
112
|
+
chargeType: "none" | "amount" | "percentage";
|
|
113
|
+
chargeAmountCents: number | null;
|
|
114
|
+
chargePercentBasisPoints: number | null;
|
|
115
|
+
active: boolean;
|
|
116
|
+
notes: string | null;
|
|
117
|
+
createdAt: Date;
|
|
118
|
+
updatedAt: Date;
|
|
119
|
+
} | null>;
|
|
120
|
+
export declare function deleteCancellationPolicyRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
121
|
+
id: string;
|
|
122
|
+
} | null>;
|
|
123
|
+
//# sourceMappingURL=service-policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-policies.d.ts","sourceRoot":"","sources":["../src/service-policies.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,KAAK,EACV,2BAA2B,EAC3B,+BAA+B,EAC/B,6BAA6B,EAC7B,iCAAiC,EACjC,6BAA6B,EAC7B,iCAAiC,EAClC,MAAM,qBAAqB,CAAA;AAG5B,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,2BAA2B;;;;;;;;;;;;;;;;;GA4BnC;AAED,wBAAsB,yBAAyB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;UAOjF;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,6BAA6B;;;;;;;;;;;;UAIpC;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,6BAA6B;;;;;;;;;;;;UAQpC;AAED,wBAAsB,wBAAwB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMhF;AAED,wBAAsB,2BAA2B,CAC/C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,+BAA+B;;;;;;;;;;;;;;;;;GAqBvC;AAED,wBAAsB,6BAA6B,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;UAOrF;AAED,wBAAsB,4BAA4B,CAChD,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,iCAAiC;;;;;;;;;;;;UAIxC;AAED,wBAAsB,4BAA4B,CAChD,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,iCAAiC;;;;;;;;;;;;UAQxC;AAED,wBAAsB,4BAA4B,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMpF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
|
|
2
|
+
import { cancellationPolicies, cancellationPolicyRules } from "./schema.js";
|
|
3
|
+
import { paginate } from "./service-shared.js";
|
|
4
|
+
export async function listCancellationPolicies(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.policyType)
|
|
7
|
+
conditions.push(eq(cancellationPolicies.policyType, query.policyType));
|
|
8
|
+
if (query.active !== undefined)
|
|
9
|
+
conditions.push(eq(cancellationPolicies.active, query.active));
|
|
10
|
+
if (query.isDefault !== undefined) {
|
|
11
|
+
conditions.push(eq(cancellationPolicies.isDefault, query.isDefault));
|
|
12
|
+
}
|
|
13
|
+
if (query.search) {
|
|
14
|
+
const term = `%${query.search}%`;
|
|
15
|
+
conditions.push(or(ilike(cancellationPolicies.name, term), ilike(cancellationPolicies.code, term)));
|
|
16
|
+
}
|
|
17
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
18
|
+
return paginate(db
|
|
19
|
+
.select()
|
|
20
|
+
.from(cancellationPolicies)
|
|
21
|
+
.where(where)
|
|
22
|
+
.limit(query.limit)
|
|
23
|
+
.offset(query.offset)
|
|
24
|
+
.orderBy(desc(cancellationPolicies.updatedAt)), db.select({ count: sql `count(*)::int` }).from(cancellationPolicies).where(where), query.limit, query.offset);
|
|
25
|
+
}
|
|
26
|
+
export async function getCancellationPolicyById(db, id) {
|
|
27
|
+
const [row] = await db
|
|
28
|
+
.select()
|
|
29
|
+
.from(cancellationPolicies)
|
|
30
|
+
.where(eq(cancellationPolicies.id, id))
|
|
31
|
+
.limit(1);
|
|
32
|
+
return row ?? null;
|
|
33
|
+
}
|
|
34
|
+
export async function createCancellationPolicy(db, data) {
|
|
35
|
+
const [row] = await db.insert(cancellationPolicies).values(data).returning();
|
|
36
|
+
return row ?? null;
|
|
37
|
+
}
|
|
38
|
+
export async function updateCancellationPolicy(db, id, data) {
|
|
39
|
+
const [row] = await db
|
|
40
|
+
.update(cancellationPolicies)
|
|
41
|
+
.set({ ...data, updatedAt: new Date() })
|
|
42
|
+
.where(eq(cancellationPolicies.id, id))
|
|
43
|
+
.returning();
|
|
44
|
+
return row ?? null;
|
|
45
|
+
}
|
|
46
|
+
export async function deleteCancellationPolicy(db, id) {
|
|
47
|
+
const [row] = await db
|
|
48
|
+
.delete(cancellationPolicies)
|
|
49
|
+
.where(eq(cancellationPolicies.id, id))
|
|
50
|
+
.returning({ id: cancellationPolicies.id });
|
|
51
|
+
return row ?? null;
|
|
52
|
+
}
|
|
53
|
+
export async function listCancellationPolicyRules(db, query) {
|
|
54
|
+
const conditions = [];
|
|
55
|
+
if (query.cancellationPolicyId) {
|
|
56
|
+
conditions.push(eq(cancellationPolicyRules.cancellationPolicyId, query.cancellationPolicyId));
|
|
57
|
+
}
|
|
58
|
+
if (query.active !== undefined)
|
|
59
|
+
conditions.push(eq(cancellationPolicyRules.active, query.active));
|
|
60
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
61
|
+
return paginate(db
|
|
62
|
+
.select()
|
|
63
|
+
.from(cancellationPolicyRules)
|
|
64
|
+
.where(where)
|
|
65
|
+
.limit(query.limit)
|
|
66
|
+
.offset(query.offset)
|
|
67
|
+
.orderBy(asc(cancellationPolicyRules.sortOrder), asc(cancellationPolicyRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(cancellationPolicyRules).where(where), query.limit, query.offset);
|
|
68
|
+
}
|
|
69
|
+
export async function getCancellationPolicyRuleById(db, id) {
|
|
70
|
+
const [row] = await db
|
|
71
|
+
.select()
|
|
72
|
+
.from(cancellationPolicyRules)
|
|
73
|
+
.where(eq(cancellationPolicyRules.id, id))
|
|
74
|
+
.limit(1);
|
|
75
|
+
return row ?? null;
|
|
76
|
+
}
|
|
77
|
+
export async function createCancellationPolicyRule(db, data) {
|
|
78
|
+
const [row] = await db.insert(cancellationPolicyRules).values(data).returning();
|
|
79
|
+
return row ?? null;
|
|
80
|
+
}
|
|
81
|
+
export async function updateCancellationPolicyRule(db, id, data) {
|
|
82
|
+
const [row] = await db
|
|
83
|
+
.update(cancellationPolicyRules)
|
|
84
|
+
.set({ ...data, updatedAt: new Date() })
|
|
85
|
+
.where(eq(cancellationPolicyRules.id, id))
|
|
86
|
+
.returning();
|
|
87
|
+
return row ?? null;
|
|
88
|
+
}
|
|
89
|
+
export async function deleteCancellationPolicyRule(db, id) {
|
|
90
|
+
const [row] = await db
|
|
91
|
+
.delete(cancellationPolicyRules)
|
|
92
|
+
.where(eq(cancellationPolicyRules.id, id))
|
|
93
|
+
.returning({ id: cancellationPolicyRules.id });
|
|
94
|
+
return row ?? null;
|
|
95
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { cancellationPolicyListQuerySchema, cancellationPolicyRuleListQuerySchema, dropoffPriceRuleListQuerySchema, extraPriceRuleListQuerySchema, insertCancellationPolicyRuleSchema, insertCancellationPolicySchema, insertDropoffPriceRuleSchema, insertExtraPriceRuleSchema, insertOptionPriceRuleSchema, insertOptionStartTimeRuleSchema, insertOptionUnitPriceRuleSchema, insertOptionUnitTierSchema, insertPickupPriceRuleSchema, insertPriceCatalogSchema, insertPriceScheduleSchema, insertPricingCategoryDependencySchema, insertPricingCategorySchema, optionPriceRuleListQuerySchema, optionStartTimeRuleListQuerySchema, optionUnitPriceRuleListQuerySchema, optionUnitTierListQuerySchema, pickupPriceRuleListQuerySchema, priceCatalogListQuerySchema, priceScheduleListQuerySchema, pricingCategoryDependencyListQuerySchema, pricingCategoryListQuerySchema, updateCancellationPolicyRuleSchema, updateCancellationPolicySchema, updateDropoffPriceRuleSchema, updateExtraPriceRuleSchema, updateOptionPriceRuleSchema, updateOptionStartTimeRuleSchema, updateOptionUnitPriceRuleSchema, updateOptionUnitTierSchema, updatePickupPriceRuleSchema, updatePriceCatalogSchema, updatePriceScheduleSchema, updatePricingCategoryDependencySchema, updatePricingCategorySchema } from "./validation.js";
|
|
3
|
+
export type PricingCategoryListQuery = z.infer<typeof pricingCategoryListQuerySchema>;
|
|
4
|
+
export type PricingCategoryDependencyListQuery = z.infer<typeof pricingCategoryDependencyListQuerySchema>;
|
|
5
|
+
export type CancellationPolicyListQuery = z.infer<typeof cancellationPolicyListQuerySchema>;
|
|
6
|
+
export type CancellationPolicyRuleListQuery = z.infer<typeof cancellationPolicyRuleListQuerySchema>;
|
|
7
|
+
export type PriceCatalogListQuery = z.infer<typeof priceCatalogListQuerySchema>;
|
|
8
|
+
export type PriceScheduleListQuery = z.infer<typeof priceScheduleListQuerySchema>;
|
|
9
|
+
export type OptionPriceRuleListQuery = z.infer<typeof optionPriceRuleListQuerySchema>;
|
|
10
|
+
export type OptionUnitPriceRuleListQuery = z.infer<typeof optionUnitPriceRuleListQuerySchema>;
|
|
11
|
+
export type OptionStartTimeRuleListQuery = z.infer<typeof optionStartTimeRuleListQuerySchema>;
|
|
12
|
+
export type OptionUnitTierListQuery = z.infer<typeof optionUnitTierListQuerySchema>;
|
|
13
|
+
export type PickupPriceRuleListQuery = z.infer<typeof pickupPriceRuleListQuerySchema>;
|
|
14
|
+
export type DropoffPriceRuleListQuery = z.infer<typeof dropoffPriceRuleListQuerySchema>;
|
|
15
|
+
export type ExtraPriceRuleListQuery = z.infer<typeof extraPriceRuleListQuerySchema>;
|
|
16
|
+
export type CreatePricingCategoryInput = z.infer<typeof insertPricingCategorySchema>;
|
|
17
|
+
export type UpdatePricingCategoryInput = z.infer<typeof updatePricingCategorySchema>;
|
|
18
|
+
export type CreatePricingCategoryDependencyInput = z.infer<typeof insertPricingCategoryDependencySchema>;
|
|
19
|
+
export type UpdatePricingCategoryDependencyInput = z.infer<typeof updatePricingCategoryDependencySchema>;
|
|
20
|
+
export type CreateCancellationPolicyInput = z.infer<typeof insertCancellationPolicySchema>;
|
|
21
|
+
export type UpdateCancellationPolicyInput = z.infer<typeof updateCancellationPolicySchema>;
|
|
22
|
+
export type CreateCancellationPolicyRuleInput = z.infer<typeof insertCancellationPolicyRuleSchema>;
|
|
23
|
+
export type UpdateCancellationPolicyRuleInput = z.infer<typeof updateCancellationPolicyRuleSchema>;
|
|
24
|
+
export type CreatePriceCatalogInput = z.infer<typeof insertPriceCatalogSchema>;
|
|
25
|
+
export type UpdatePriceCatalogInput = z.infer<typeof updatePriceCatalogSchema>;
|
|
26
|
+
export type CreatePriceScheduleInput = z.infer<typeof insertPriceScheduleSchema>;
|
|
27
|
+
export type UpdatePriceScheduleInput = z.infer<typeof updatePriceScheduleSchema>;
|
|
28
|
+
export type CreateOptionPriceRuleInput = z.infer<typeof insertOptionPriceRuleSchema>;
|
|
29
|
+
export type UpdateOptionPriceRuleInput = z.infer<typeof updateOptionPriceRuleSchema>;
|
|
30
|
+
export type CreateOptionUnitPriceRuleInput = z.infer<typeof insertOptionUnitPriceRuleSchema>;
|
|
31
|
+
export type UpdateOptionUnitPriceRuleInput = z.infer<typeof updateOptionUnitPriceRuleSchema>;
|
|
32
|
+
export type CreateOptionStartTimeRuleInput = z.infer<typeof insertOptionStartTimeRuleSchema>;
|
|
33
|
+
export type UpdateOptionStartTimeRuleInput = z.infer<typeof updateOptionStartTimeRuleSchema>;
|
|
34
|
+
export type CreateOptionUnitTierInput = z.infer<typeof insertOptionUnitTierSchema>;
|
|
35
|
+
export type UpdateOptionUnitTierInput = z.infer<typeof updateOptionUnitTierSchema>;
|
|
36
|
+
export type CreatePickupPriceRuleInput = z.infer<typeof insertPickupPriceRuleSchema>;
|
|
37
|
+
export type UpdatePickupPriceRuleInput = z.infer<typeof updatePickupPriceRuleSchema>;
|
|
38
|
+
export type CreateDropoffPriceRuleInput = z.infer<typeof insertDropoffPriceRuleSchema>;
|
|
39
|
+
export type UpdateDropoffPriceRuleInput = z.infer<typeof updateDropoffPriceRuleSchema>;
|
|
40
|
+
export type CreateExtraPriceRuleInput = z.infer<typeof insertExtraPriceRuleSchema>;
|
|
41
|
+
export type UpdateExtraPriceRuleInput = z.infer<typeof updateExtraPriceRuleSchema>;
|
|
42
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
43
|
+
count: number;
|
|
44
|
+
}>>, limit: number, offset: number): Promise<{
|
|
45
|
+
data: T[];
|
|
46
|
+
total: number;
|
|
47
|
+
limit: number;
|
|
48
|
+
offset: number;
|
|
49
|
+
}>;
|
|
50
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../src/service-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,iCAAiC,EACjC,qCAAqC,EACrC,+BAA+B,EAC/B,6BAA6B,EAC7B,kCAAkC,EAClC,8BAA8B,EAC9B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,qCAAqC,EACrC,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,EAClC,kCAAkC,EAClC,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,wCAAwC,EACxC,8BAA8B,EAC9B,kCAAkC,EAClC,8BAA8B,EAC9B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,qCAAqC,EACrC,2BAA2B,EAC5B,MAAM,iBAAiB,CAAA;AAExB,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AACrF,MAAM,MAAM,kCAAkC,G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