@voyant-travel/commerce 0.1.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/LICENSE +201 -0
- package/README.md +145 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.d.ts +2 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.d.ts.map +1 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.js +398 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/interface.d.ts +18 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +246 -0
- package/dist/interface.test.d.ts +2 -0
- package/dist/interface.test.d.ts.map +1 -0
- package/dist/interface.test.js +357 -0
- package/dist/markets/index.d.ts +11 -0
- package/dist/markets/index.d.ts.map +1 -0
- package/dist/markets/index.js +12 -0
- package/dist/markets/routes.d.ts +1182 -0
- package/dist/markets/routes.d.ts.map +1 -0
- package/dist/markets/routes.js +209 -0
- package/dist/markets/schema.d.ts +1527 -0
- package/dist/markets/schema.d.ts.map +1 -0
- package/dist/markets/schema.js +240 -0
- package/dist/markets/service-core.d.ts +253 -0
- package/dist/markets/service-core.d.ts.map +1 -0
- package/dist/markets/service-core.js +242 -0
- package/dist/markets/service-rules.d.ts +191 -0
- package/dist/markets/service-rules.d.ts.map +1 -0
- package/dist/markets/service-rules.js +155 -0
- package/dist/markets/service-shared.d.ts +36 -0
- package/dist/markets/service-shared.d.ts.map +1 -0
- package/dist/markets/service-shared.js +7 -0
- package/dist/markets/service.d.ts +43 -0
- package/dist/markets/service.d.ts.map +1 -0
- package/dist/markets/service.js +42 -0
- package/dist/markets/validation.d.ts +451 -0
- package/dist/markets/validation.d.ts.map +1 -0
- package/dist/markets/validation.js +160 -0
- package/dist/pricing/events.d.ts +53 -0
- package/dist/pricing/events.d.ts.map +1 -0
- package/dist/pricing/events.js +28 -0
- package/dist/pricing/index.d.ts +15 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +18 -0
- package/dist/pricing/routes-core.d.ts +981 -0
- package/dist/pricing/routes-core.d.ts.map +1 -0
- package/dist/pricing/routes-core.js +102 -0
- package/dist/pricing/routes-public.d.ts +136 -0
- package/dist/pricing/routes-public.d.ts.map +1 -0
- package/dist/pricing/routes-public.js +14 -0
- package/dist/pricing/routes-rules.d.ts +1339 -0
- package/dist/pricing/routes-rules.d.ts.map +1 -0
- package/dist/pricing/routes-rules.js +138 -0
- package/dist/pricing/routes-shared.d.ts +14 -0
- package/dist/pricing/routes-shared.d.ts.map +1 -0
- package/dist/pricing/routes-shared.js +3 -0
- package/dist/pricing/routes.d.ts +7 -0
- package/dist/pricing/routes.d.ts.map +1 -0
- package/dist/pricing/routes.js +6 -0
- package/dist/pricing/schema-catalogs.d.ts +467 -0
- package/dist/pricing/schema-catalogs.d.ts.map +1 -0
- package/dist/pricing/schema-catalogs.js +47 -0
- package/dist/pricing/schema-categories.d.ts +497 -0
- package/dist/pricing/schema-categories.d.ts.map +1 -0
- package/dist/pricing/schema-categories.js +54 -0
- package/dist/pricing/schema-departure-overrides.d.ts +228 -0
- package/dist/pricing/schema-departure-overrides.d.ts.map +1 -0
- package/dist/pricing/schema-departure-overrides.js +36 -0
- package/dist/pricing/schema-option-rules.d.ts +1770 -0
- package/dist/pricing/schema-option-rules.d.ts.map +1 -0
- package/dist/pricing/schema-option-rules.js +181 -0
- package/dist/pricing/schema-policies.d.ts +395 -0
- package/dist/pricing/schema-policies.d.ts.map +1 -0
- package/dist/pricing/schema-policies.js +41 -0
- package/dist/pricing/schema-relations.d.ts +59 -0
- package/dist/pricing/schema-relations.d.ts.map +1 -0
- package/dist/pricing/schema-relations.js +111 -0
- package/dist/pricing/schema-shared.d.ts +11 -0
- package/dist/pricing/schema-shared.d.ts.map +1 -0
- package/dist/pricing/schema-shared.js +67 -0
- package/dist/pricing/schema.d.ts +8 -0
- package/dist/pricing/schema.d.ts.map +1 -0
- package/dist/pricing/schema.js +7 -0
- package/dist/pricing/service-catalog-plane-pricing.d.ts +95 -0
- package/dist/pricing/service-catalog-plane-pricing.d.ts.map +1 -0
- package/dist/pricing/service-catalog-plane-pricing.js +382 -0
- package/dist/pricing/service-catalogs.d.ts +139 -0
- package/dist/pricing/service-catalogs.d.ts.map +1 -0
- package/dist/pricing/service-catalogs.js +89 -0
- package/dist/pricing/service-categories.d.ts +147 -0
- package/dist/pricing/service-categories.d.ts.map +1 -0
- package/dist/pricing/service-categories.js +105 -0
- package/dist/pricing/service-departure-overrides.d.ts +67 -0
- package/dist/pricing/service-departure-overrides.d.ts.map +1 -0
- package/dist/pricing/service-departure-overrides.js +54 -0
- package/dist/pricing/service-option-rules.d.ts +321 -0
- package/dist/pricing/service-option-rules.d.ts.map +1 -0
- package/dist/pricing/service-option-rules.js +340 -0
- package/dist/pricing/service-policies.d.ts +123 -0
- package/dist/pricing/service-policies.d.ts.map +1 -0
- package/dist/pricing/service-policies.js +95 -0
- package/dist/pricing/service-public.d.ts +89 -0
- package/dist/pricing/service-public.d.ts.map +1 -0
- package/dist/pricing/service-public.js +473 -0
- package/dist/pricing/service-rule-resolver.d.ts +67 -0
- package/dist/pricing/service-rule-resolver.d.ts.map +1 -0
- package/dist/pricing/service-rule-resolver.js +204 -0
- package/dist/pricing/service-shared.d.ts +53 -0
- package/dist/pricing/service-shared.d.ts.map +1 -0
- package/dist/pricing/service-shared.js +4 -0
- package/dist/pricing/service-transfer-rules.d.ts +211 -0
- package/dist/pricing/service-transfer-rules.d.ts.map +1 -0
- package/dist/pricing/service-transfer-rules.js +139 -0
- package/dist/pricing/service.d.ts +79 -0
- package/dist/pricing/service.d.ts.map +1 -0
- package/dist/pricing/service.js +78 -0
- package/dist/pricing/validation-public.d.ts +412 -0
- package/dist/pricing/validation-public.d.ts.map +1 -0
- package/dist/pricing/validation-public.js +111 -0
- package/dist/pricing/validation-shared.d.ts +71 -0
- package/dist/pricing/validation-shared.d.ts.map +1 -0
- package/dist/pricing/validation-shared.js +63 -0
- package/dist/pricing/validation.d.ts +987 -0
- package/dist/pricing/validation.d.ts.map +1 -0
- package/dist/pricing/validation.js +307 -0
- package/dist/promotions/events.d.ts +38 -0
- package/dist/promotions/events.d.ts.map +1 -0
- package/dist/promotions/events.js +25 -0
- package/dist/promotions/index.d.ts +12 -0
- package/dist/promotions/index.d.ts.map +1 -0
- package/dist/promotions/index.js +17 -0
- package/dist/promotions/routes-shared.d.ts +14 -0
- package/dist/promotions/routes-shared.d.ts.map +1 -0
- package/dist/promotions/routes-shared.js +3 -0
- package/dist/promotions/routes.d.ts +395 -0
- package/dist/promotions/routes.d.ts.map +1 -0
- package/dist/promotions/routes.js +55 -0
- package/dist/promotions/schema.d.ts +675 -0
- package/dist/promotions/schema.d.ts.map +1 -0
- package/dist/promotions/schema.js +126 -0
- package/dist/promotions/service-booking-confirmed.d.ts +77 -0
- package/dist/promotions/service-booking-confirmed.d.ts.map +1 -0
- package/dist/promotions/service-booking-confirmed.js +134 -0
- package/dist/promotions/service-boundary-scheduler.d.ts +85 -0
- package/dist/promotions/service-boundary-scheduler.d.ts.map +1 -0
- package/dist/promotions/service-boundary-scheduler.js +141 -0
- package/dist/promotions/service-catalog-evaluator.d.ts +22 -0
- package/dist/promotions/service-catalog-evaluator.d.ts.map +1 -0
- package/dist/promotions/service-catalog-evaluator.js +33 -0
- package/dist/promotions/service-catalog-plane-promotions.d.ts +73 -0
- package/dist/promotions/service-catalog-plane-promotions.d.ts.map +1 -0
- package/dist/promotions/service-catalog-plane-promotions.js +118 -0
- package/dist/promotions/service-evaluator.d.ts +134 -0
- package/dist/promotions/service-evaluator.d.ts.map +1 -0
- package/dist/promotions/service-evaluator.js +302 -0
- package/dist/promotions/service-storefront.d.ts +147 -0
- package/dist/promotions/service-storefront.d.ts.map +1 -0
- package/dist/promotions/service-storefront.js +326 -0
- package/dist/promotions/service.d.ts +143 -0
- package/dist/promotions/service.d.ts.map +1 -0
- package/dist/promotions/service.js +359 -0
- package/dist/promotions/validation.d.ts +195 -0
- package/dist/promotions/validation.d.ts.map +1 -0
- package/dist/promotions/validation.js +167 -0
- package/dist/promotions/workflow-bulk-reindex.d.ts +36 -0
- package/dist/promotions/workflow-bulk-reindex.d.ts.map +1 -0
- package/dist/promotions/workflow-bulk-reindex.js +53 -0
- package/dist/promotions/workflow-runtime.d.ts +17 -0
- package/dist/promotions/workflow-runtime.d.ts.map +1 -0
- package/dist/promotions/workflow-runtime.js +9 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +27 -0
- package/dist/runtime.test.d.ts +2 -0
- package/dist/runtime.test.d.ts.map +1 -0
- package/dist/runtime.test.js +25 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +4 -0
- package/dist/sellability/index.d.ts +13 -0
- package/dist/sellability/index.d.ts.map +1 -0
- package/dist/sellability/index.js +17 -0
- package/dist/sellability/routes.d.ts +2332 -0
- package/dist/sellability/routes.d.ts.map +1 -0
- package/dist/sellability/routes.js +166 -0
- package/dist/sellability/schema.d.ts +1716 -0
- package/dist/sellability/schema.d.ts.map +1 -0
- package/dist/sellability/schema.js +278 -0
- package/dist/sellability/service-records.d.ts +316 -0
- package/dist/sellability/service-records.d.ts.map +1 -0
- package/dist/sellability/service-records.js +253 -0
- package/dist/sellability/service-resolve.d.ts +72 -0
- package/dist/sellability/service-resolve.d.ts.map +1 -0
- package/dist/sellability/service-resolve.js +580 -0
- package/dist/sellability/service-shared.d.ts +124 -0
- package/dist/sellability/service-shared.d.ts.map +1 -0
- package/dist/sellability/service-shared.js +96 -0
- package/dist/sellability/service-snapshots.d.ts +191 -0
- package/dist/sellability/service-snapshots.d.ts.map +1 -0
- package/dist/sellability/service-snapshots.js +153 -0
- package/dist/sellability/service.d.ts +1038 -0
- package/dist/sellability/service.d.ts.map +1 -0
- package/dist/sellability/service.js +17 -0
- package/dist/sellability/validation.d.ts +477 -0
- package/dist/sellability/validation.d.ts.map +1 -0
- package/dist/sellability/validation.js +192 -0
- package/dist/types.d.ts +239 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { and, eq, inArray } from "drizzle-orm";
|
|
2
|
+
import * as rrulePackage from "rrule";
|
|
3
|
+
import { priceSchedules } from "./schema-catalogs.js";
|
|
4
|
+
import { departurePriceOverrides } from "./schema-departure-overrides.js";
|
|
5
|
+
import { optionPriceRules } from "./schema-option-rules.js";
|
|
6
|
+
const rrulePackageCompat = rrulePackage;
|
|
7
|
+
const { rrulestr } = rrulePackageCompat.rrulestr != null
|
|
8
|
+
? rrulePackageCompat
|
|
9
|
+
: (rrulePackageCompat.default ?? rrulePackageCompat.rrule ?? rrulePackageCompat);
|
|
10
|
+
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
11
|
+
const WEEKDAY_CODES = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
12
|
+
function weekdayCode(isoDate) {
|
|
13
|
+
const d = new Date(`${isoDate}T00:00:00Z`);
|
|
14
|
+
return WEEKDAY_CODES[d.getUTCDay()] ?? "MO";
|
|
15
|
+
}
|
|
16
|
+
function dateInWindow(isoDate, from, to) {
|
|
17
|
+
if (from && isoDate < from)
|
|
18
|
+
return false;
|
|
19
|
+
if (to && isoDate > to)
|
|
20
|
+
return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function rruleMatchesDate(ruleString, isoDate, anchor) {
|
|
24
|
+
const trimmed = ruleString.trim();
|
|
25
|
+
if (trimmed === "")
|
|
26
|
+
return true;
|
|
27
|
+
const dtstart = `${anchor.replace(/-/g, "")}T000000Z`;
|
|
28
|
+
const hasDtstart = /(?:^|\n)DTSTART[:;]/.test(trimmed);
|
|
29
|
+
const hasRrule = /(?:^|\n)RRULE[:;]/.test(trimmed);
|
|
30
|
+
const body = hasRrule ? trimmed : `RRULE:${trimmed}`;
|
|
31
|
+
const fullRule = hasDtstart ? body : `DTSTART:${dtstart}\n${body}`;
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = rrulestr(fullRule);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const start = new Date(`${isoDate}T00:00:00Z`);
|
|
40
|
+
const end = new Date(start.getTime() + 24 * 60 * 60 * 1000);
|
|
41
|
+
const occurrences = parsed.between(start, end, true);
|
|
42
|
+
return occurrences.some((occ) => occ.toISOString().slice(0, 10) === isoDate);
|
|
43
|
+
}
|
|
44
|
+
function scheduleMatchesDate(s, isoDate) {
|
|
45
|
+
if (!s.active)
|
|
46
|
+
return false;
|
|
47
|
+
if (!dateInWindow(isoDate, s.validFrom, s.validTo))
|
|
48
|
+
return false;
|
|
49
|
+
if (s.weekdays && s.weekdays.length > 0) {
|
|
50
|
+
if (!s.weekdays.includes(weekdayCode(isoDate)))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const anchor = s.validFrom ?? "2000-01-01";
|
|
54
|
+
if (!rruleMatchesDate(s.recurrenceRule, isoDate, anchor))
|
|
55
|
+
return false;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
function compareMatches(a, b) {
|
|
59
|
+
if (b.priority !== a.priority)
|
|
60
|
+
return b.priority - a.priority;
|
|
61
|
+
const aDef = a.rule.isDefault ? 1 : 0;
|
|
62
|
+
const bDef = b.rule.isDefault ? 1 : 0;
|
|
63
|
+
if (aDef !== bDef)
|
|
64
|
+
return bDef - aDef;
|
|
65
|
+
return a.rule.name.localeCompare(b.rule.name);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Pick the option price rule that applies to a given date, given a set of
|
|
69
|
+
* candidate rules and their schedules.
|
|
70
|
+
*
|
|
71
|
+
* - Rules with a matching schedule beat rules without one.
|
|
72
|
+
* - Among scheduled matches, highest `priority` wins. Ties: `isDefault` first,
|
|
73
|
+
* then alphabetic by `name`.
|
|
74
|
+
* - When no schedule matches, a rule with `isDefault=true` and no schedule acts
|
|
75
|
+
* as the fallback. Without one, returns an empty array.
|
|
76
|
+
*/
|
|
77
|
+
export function pickRulesForDate(rules, schedules, isoDate) {
|
|
78
|
+
if (!ISO_DATE_RE.test(isoDate)) {
|
|
79
|
+
throw new Error(`pickRulesForDate: expected ISO yyyy-mm-dd, got "${isoDate}"`);
|
|
80
|
+
}
|
|
81
|
+
const matches = [];
|
|
82
|
+
for (const rule of rules) {
|
|
83
|
+
if (rule.priceScheduleId === null) {
|
|
84
|
+
if (rule.isDefault) {
|
|
85
|
+
matches.push({ rule, priority: Number.NEGATIVE_INFINITY, scheduled: false });
|
|
86
|
+
}
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const schedule = schedules.get(rule.priceScheduleId);
|
|
90
|
+
if (!schedule)
|
|
91
|
+
continue;
|
|
92
|
+
if (!scheduleMatchesDate(schedule, isoDate))
|
|
93
|
+
continue;
|
|
94
|
+
matches.push({ rule, priority: schedule.priority, scheduled: true });
|
|
95
|
+
}
|
|
96
|
+
if (matches.length === 0)
|
|
97
|
+
return [];
|
|
98
|
+
const scheduled = matches.filter((m) => m.scheduled);
|
|
99
|
+
if (scheduled.length > 0) {
|
|
100
|
+
scheduled.sort(compareMatches);
|
|
101
|
+
const winner = scheduled[0];
|
|
102
|
+
return winner ? [winner.rule] : [];
|
|
103
|
+
}
|
|
104
|
+
matches.sort(compareMatches);
|
|
105
|
+
const winner = matches[0];
|
|
106
|
+
return winner ? [winner.rule] : [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* DB-backed wrapper around `pickRulesForDate`. Fetches active rules for the
|
|
110
|
+
* product/option/catalog plus their schedules, then picks the winning rule
|
|
111
|
+
* per option for the given date.
|
|
112
|
+
*
|
|
113
|
+
* Returns a Map keyed by optionId. Options whose rules don't match the date
|
|
114
|
+
* (and have no default) are absent from the map.
|
|
115
|
+
*/
|
|
116
|
+
export async function resolveOptionPriceRulesForDate(db, params) {
|
|
117
|
+
if (params.optionIds.length === 0)
|
|
118
|
+
return new Map();
|
|
119
|
+
const rules = await db
|
|
120
|
+
.select({
|
|
121
|
+
id: optionPriceRules.id,
|
|
122
|
+
optionId: optionPriceRules.optionId,
|
|
123
|
+
name: optionPriceRules.name,
|
|
124
|
+
isDefault: optionPriceRules.isDefault,
|
|
125
|
+
priceScheduleId: optionPriceRules.priceScheduleId,
|
|
126
|
+
})
|
|
127
|
+
.from(optionPriceRules)
|
|
128
|
+
.where(and(eq(optionPriceRules.productId, params.productId), inArray(optionPriceRules.optionId, params.optionIds), eq(optionPriceRules.priceCatalogId, params.catalogId), eq(optionPriceRules.active, true)));
|
|
129
|
+
const scheduleIds = Array.from(new Set(rules.map((r) => r.priceScheduleId).filter((id) => id !== null)));
|
|
130
|
+
const schedules = scheduleIds.length > 0
|
|
131
|
+
? await db
|
|
132
|
+
.select({
|
|
133
|
+
id: priceSchedules.id,
|
|
134
|
+
active: priceSchedules.active,
|
|
135
|
+
priority: priceSchedules.priority,
|
|
136
|
+
recurrenceRule: priceSchedules.recurrenceRule,
|
|
137
|
+
validFrom: priceSchedules.validFrom,
|
|
138
|
+
validTo: priceSchedules.validTo,
|
|
139
|
+
weekdays: priceSchedules.weekdays,
|
|
140
|
+
timezone: priceSchedules.timezone,
|
|
141
|
+
})
|
|
142
|
+
.from(priceSchedules)
|
|
143
|
+
.where(inArray(priceSchedules.id, scheduleIds))
|
|
144
|
+
: [];
|
|
145
|
+
const scheduleMap = new Map(schedules.map((s) => [
|
|
146
|
+
s.id,
|
|
147
|
+
{
|
|
148
|
+
id: s.id,
|
|
149
|
+
active: s.active,
|
|
150
|
+
priority: s.priority,
|
|
151
|
+
recurrenceRule: s.recurrenceRule,
|
|
152
|
+
validFrom: s.validFrom,
|
|
153
|
+
validTo: s.validTo,
|
|
154
|
+
weekdays: s.weekdays ?? null,
|
|
155
|
+
timezone: s.timezone,
|
|
156
|
+
},
|
|
157
|
+
]));
|
|
158
|
+
const rulesByOption = new Map();
|
|
159
|
+
for (const r of rules) {
|
|
160
|
+
const existing = rulesByOption.get(r.optionId) ?? [];
|
|
161
|
+
existing.push({
|
|
162
|
+
id: r.id,
|
|
163
|
+
name: r.name,
|
|
164
|
+
isDefault: r.isDefault,
|
|
165
|
+
priceScheduleId: r.priceScheduleId,
|
|
166
|
+
});
|
|
167
|
+
rulesByOption.set(r.optionId, existing);
|
|
168
|
+
}
|
|
169
|
+
const result = new Map();
|
|
170
|
+
for (const [optionId, candidateRules] of rulesByOption) {
|
|
171
|
+
const picked = pickRulesForDate(candidateRules, scheduleMap, params.date);
|
|
172
|
+
const first = picked[0];
|
|
173
|
+
if (first)
|
|
174
|
+
result.set(optionId, first);
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Fetch active per-unit price overrides for a given departure + catalog.
|
|
180
|
+
*
|
|
181
|
+
* Returns a Map keyed by `optionUnitId` so callers can apply overrides while
|
|
182
|
+
* iterating per-unit prices in a snapshot. Inactive overrides are excluded at
|
|
183
|
+
* query time.
|
|
184
|
+
*/
|
|
185
|
+
export async function loadDeparturePriceOverrides(db, params) {
|
|
186
|
+
const rows = await db
|
|
187
|
+
.select({
|
|
188
|
+
id: departurePriceOverrides.id,
|
|
189
|
+
optionUnitId: departurePriceOverrides.optionUnitId,
|
|
190
|
+
sellAmountCents: departurePriceOverrides.sellAmountCents,
|
|
191
|
+
costAmountCents: departurePriceOverrides.costAmountCents,
|
|
192
|
+
})
|
|
193
|
+
.from(departurePriceOverrides)
|
|
194
|
+
.where(and(eq(departurePriceOverrides.departureId, params.departureId), eq(departurePriceOverrides.priceCatalogId, params.catalogId), eq(departurePriceOverrides.active, true)));
|
|
195
|
+
return new Map(rows.map((r) => [
|
|
196
|
+
r.optionUnitId,
|
|
197
|
+
{
|
|
198
|
+
id: r.id,
|
|
199
|
+
unitId: r.optionUnitId,
|
|
200
|
+
sellAmountCents: r.sellAmountCents,
|
|
201
|
+
costAmountCents: r.costAmountCents,
|
|
202
|
+
},
|
|
203
|
+
]));
|
|
204
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { cancellationPolicyListQuerySchema, cancellationPolicyRuleListQuerySchema, departurePriceOverrideListQuerySchema, dropoffPriceRuleListQuerySchema, extraPriceRuleListQuerySchema, insertCancellationPolicyRuleSchema, insertCancellationPolicySchema, insertDeparturePriceOverrideSchema, insertDropoffPriceRuleSchema, insertExtraPriceRuleSchema, insertOptionPriceRuleSchema, insertOptionStartTimeRuleSchema, insertOptionUnitPriceRuleSchema, insertOptionUnitTierSchema, insertPickupPriceRuleSchema, insertPriceCatalogSchema, insertPriceScheduleSchema, insertPricingCategoryDependencySchema, insertPricingCategorySchema, optionPriceRuleListQuerySchema, optionStartTimeRuleListQuerySchema, optionUnitPriceRuleListQuerySchema, optionUnitTierListQuerySchema, pickupPriceRuleListQuerySchema, priceCatalogListQuerySchema, priceScheduleListQuerySchema, pricingCategoryDependencyListQuerySchema, pricingCategoryListQuerySchema, updateCancellationPolicyRuleSchema, updateCancellationPolicySchema, updateDeparturePriceOverrideSchema, 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 DeparturePriceOverrideListQuery = z.infer<typeof departurePriceOverrideListQuerySchema>;
|
|
17
|
+
export type CreatePricingCategoryInput = z.infer<typeof insertPricingCategorySchema>;
|
|
18
|
+
export type UpdatePricingCategoryInput = z.infer<typeof updatePricingCategorySchema>;
|
|
19
|
+
export type CreatePricingCategoryDependencyInput = z.infer<typeof insertPricingCategoryDependencySchema>;
|
|
20
|
+
export type UpdatePricingCategoryDependencyInput = z.infer<typeof updatePricingCategoryDependencySchema>;
|
|
21
|
+
export type CreateCancellationPolicyInput = z.infer<typeof insertCancellationPolicySchema>;
|
|
22
|
+
export type UpdateCancellationPolicyInput = z.infer<typeof updateCancellationPolicySchema>;
|
|
23
|
+
export type CreateCancellationPolicyRuleInput = z.infer<typeof insertCancellationPolicyRuleSchema>;
|
|
24
|
+
export type UpdateCancellationPolicyRuleInput = z.infer<typeof updateCancellationPolicyRuleSchema>;
|
|
25
|
+
export type CreatePriceCatalogInput = z.infer<typeof insertPriceCatalogSchema>;
|
|
26
|
+
export type UpdatePriceCatalogInput = z.infer<typeof updatePriceCatalogSchema>;
|
|
27
|
+
export type CreatePriceScheduleInput = z.infer<typeof insertPriceScheduleSchema>;
|
|
28
|
+
export type UpdatePriceScheduleInput = z.infer<typeof updatePriceScheduleSchema>;
|
|
29
|
+
export type CreateOptionPriceRuleInput = z.infer<typeof insertOptionPriceRuleSchema>;
|
|
30
|
+
export type UpdateOptionPriceRuleInput = z.infer<typeof updateOptionPriceRuleSchema>;
|
|
31
|
+
export type CreateOptionUnitPriceRuleInput = z.infer<typeof insertOptionUnitPriceRuleSchema>;
|
|
32
|
+
export type UpdateOptionUnitPriceRuleInput = z.infer<typeof updateOptionUnitPriceRuleSchema>;
|
|
33
|
+
export type CreateOptionStartTimeRuleInput = z.infer<typeof insertOptionStartTimeRuleSchema>;
|
|
34
|
+
export type UpdateOptionStartTimeRuleInput = z.infer<typeof updateOptionStartTimeRuleSchema>;
|
|
35
|
+
export type CreateOptionUnitTierInput = z.infer<typeof insertOptionUnitTierSchema>;
|
|
36
|
+
export type UpdateOptionUnitTierInput = z.infer<typeof updateOptionUnitTierSchema>;
|
|
37
|
+
export type CreatePickupPriceRuleInput = z.infer<typeof insertPickupPriceRuleSchema>;
|
|
38
|
+
export type UpdatePickupPriceRuleInput = z.infer<typeof updatePickupPriceRuleSchema>;
|
|
39
|
+
export type CreateDropoffPriceRuleInput = z.infer<typeof insertDropoffPriceRuleSchema>;
|
|
40
|
+
export type UpdateDropoffPriceRuleInput = z.infer<typeof updateDropoffPriceRuleSchema>;
|
|
41
|
+
export type CreateExtraPriceRuleInput = z.infer<typeof insertExtraPriceRuleSchema>;
|
|
42
|
+
export type UpdateExtraPriceRuleInput = z.infer<typeof updateExtraPriceRuleSchema>;
|
|
43
|
+
export type CreateDeparturePriceOverrideInput = z.infer<typeof insertDeparturePriceOverrideSchema>;
|
|
44
|
+
export type UpdateDeparturePriceOverrideInput = z.infer<typeof updateDeparturePriceOverrideSchema>;
|
|
45
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
46
|
+
count: number;
|
|
47
|
+
}>>, limit: number, offset: number): Promise<{
|
|
48
|
+
data: T[];
|
|
49
|
+
total: number;
|
|
50
|
+
limit: number;
|
|
51
|
+
offset: number;
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../../src/pricing/service-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,iCAAiC,EACjC,qCAAqC,EACrC,qCAAqC,EACrC,+BAA+B,EAC/B,6BAA6B,EAC7B,kCAAkC,EAClC,8BAA8B,EAC9B,kCAAkC,EAClC,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,kCAAkC,EAClC,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,GAAG,CAAC,CAAC,KAAK,CACtD,OAAO,wCAAwC,CAChD,CAAA;AACD,MAAM,MAAM,2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ePickupPriceRuleInput, DropoffPriceRuleListQuery, ExtraPriceRuleListQuery, PickupPriceRuleListQuery, UpdateDropoffPriceRuleInput, UpdateExtraPriceRuleInput, UpdatePickupPriceRuleInput } from "./service-shared.js";
|
|
3
|
+
export declare function listPickupPriceRules(db: PostgresJsDatabase, query: PickupPriceRuleListQuery): Promise<{
|
|
4
|
+
data: {
|
|
5
|
+
id: string;
|
|
6
|
+
optionPriceRuleId: string;
|
|
7
|
+
optionId: string;
|
|
8
|
+
pickupPointId: string;
|
|
9
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
10
|
+
sellAmountCents: number | null;
|
|
11
|
+
costAmountCents: number | null;
|
|
12
|
+
active: boolean;
|
|
13
|
+
sortOrder: number;
|
|
14
|
+
notes: string | null;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date;
|
|
17
|
+
}[];
|
|
18
|
+
total: number;
|
|
19
|
+
limit: number;
|
|
20
|
+
offset: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function getPickupPriceRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
23
|
+
id: string;
|
|
24
|
+
optionPriceRuleId: string;
|
|
25
|
+
optionId: string;
|
|
26
|
+
pickupPointId: string;
|
|
27
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
28
|
+
sellAmountCents: number | null;
|
|
29
|
+
costAmountCents: number | null;
|
|
30
|
+
active: boolean;
|
|
31
|
+
sortOrder: number;
|
|
32
|
+
notes: string | null;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
} | null>;
|
|
36
|
+
export declare function createPickupPriceRule(db: PostgresJsDatabase, data: CreatePickupPriceRuleInput): Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
notes: string | null;
|
|
40
|
+
updatedAt: Date;
|
|
41
|
+
active: boolean;
|
|
42
|
+
sortOrder: number;
|
|
43
|
+
optionId: string;
|
|
44
|
+
sellAmountCents: number | null;
|
|
45
|
+
costAmountCents: number | null;
|
|
46
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
47
|
+
optionPriceRuleId: string;
|
|
48
|
+
pickupPointId: string;
|
|
49
|
+
} | null>;
|
|
50
|
+
export declare function updatePickupPriceRule(db: PostgresJsDatabase, id: string, data: UpdatePickupPriceRuleInput): Promise<{
|
|
51
|
+
id: string;
|
|
52
|
+
optionPriceRuleId: string;
|
|
53
|
+
optionId: string;
|
|
54
|
+
pickupPointId: string;
|
|
55
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
56
|
+
sellAmountCents: number | null;
|
|
57
|
+
costAmountCents: number | null;
|
|
58
|
+
active: boolean;
|
|
59
|
+
sortOrder: number;
|
|
60
|
+
notes: string | null;
|
|
61
|
+
createdAt: Date;
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
} | null>;
|
|
64
|
+
export declare function deletePickupPriceRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
65
|
+
id: string;
|
|
66
|
+
} | null>;
|
|
67
|
+
export declare function listDropoffPriceRules(db: PostgresJsDatabase, query: DropoffPriceRuleListQuery): Promise<{
|
|
68
|
+
data: {
|
|
69
|
+
id: string;
|
|
70
|
+
optionPriceRuleId: string;
|
|
71
|
+
optionId: string;
|
|
72
|
+
facilityId: string | null;
|
|
73
|
+
dropoffCode: string | null;
|
|
74
|
+
dropoffName: string;
|
|
75
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
76
|
+
sellAmountCents: number | null;
|
|
77
|
+
costAmountCents: number | null;
|
|
78
|
+
active: boolean;
|
|
79
|
+
sortOrder: number;
|
|
80
|
+
notes: string | null;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
updatedAt: Date;
|
|
83
|
+
}[];
|
|
84
|
+
total: number;
|
|
85
|
+
limit: number;
|
|
86
|
+
offset: number;
|
|
87
|
+
}>;
|
|
88
|
+
export declare function getDropoffPriceRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
89
|
+
id: string;
|
|
90
|
+
optionPriceRuleId: string;
|
|
91
|
+
optionId: string;
|
|
92
|
+
facilityId: string | null;
|
|
93
|
+
dropoffCode: string | null;
|
|
94
|
+
dropoffName: string;
|
|
95
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
96
|
+
sellAmountCents: number | null;
|
|
97
|
+
costAmountCents: number | null;
|
|
98
|
+
active: boolean;
|
|
99
|
+
sortOrder: number;
|
|
100
|
+
notes: string | null;
|
|
101
|
+
createdAt: Date;
|
|
102
|
+
updatedAt: Date;
|
|
103
|
+
} | null>;
|
|
104
|
+
export declare function createDropoffPriceRule(db: PostgresJsDatabase, data: CreateDropoffPriceRuleInput): Promise<{
|
|
105
|
+
id: string;
|
|
106
|
+
createdAt: Date;
|
|
107
|
+
notes: string | null;
|
|
108
|
+
updatedAt: Date;
|
|
109
|
+
active: boolean;
|
|
110
|
+
sortOrder: number;
|
|
111
|
+
optionId: string;
|
|
112
|
+
sellAmountCents: number | null;
|
|
113
|
+
costAmountCents: number | null;
|
|
114
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
115
|
+
optionPriceRuleId: string;
|
|
116
|
+
facilityId: string | null;
|
|
117
|
+
dropoffCode: string | null;
|
|
118
|
+
dropoffName: string;
|
|
119
|
+
} | null>;
|
|
120
|
+
export declare function updateDropoffPriceRule(db: PostgresJsDatabase, id: string, data: UpdateDropoffPriceRuleInput): Promise<{
|
|
121
|
+
id: string;
|
|
122
|
+
optionPriceRuleId: string;
|
|
123
|
+
optionId: string;
|
|
124
|
+
facilityId: string | null;
|
|
125
|
+
dropoffCode: string | null;
|
|
126
|
+
dropoffName: string;
|
|
127
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
128
|
+
sellAmountCents: number | null;
|
|
129
|
+
costAmountCents: number | null;
|
|
130
|
+
active: boolean;
|
|
131
|
+
sortOrder: number;
|
|
132
|
+
notes: string | null;
|
|
133
|
+
createdAt: Date;
|
|
134
|
+
updatedAt: Date;
|
|
135
|
+
} | null>;
|
|
136
|
+
export declare function deleteDropoffPriceRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
137
|
+
id: string;
|
|
138
|
+
} | null>;
|
|
139
|
+
export declare function listExtraPriceRules(db: PostgresJsDatabase, query: ExtraPriceRuleListQuery): Promise<{
|
|
140
|
+
data: {
|
|
141
|
+
id: string;
|
|
142
|
+
optionPriceRuleId: string;
|
|
143
|
+
optionId: string;
|
|
144
|
+
productExtraId: string | null;
|
|
145
|
+
optionExtraConfigId: string | null;
|
|
146
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
147
|
+
sellAmountCents: number | null;
|
|
148
|
+
costAmountCents: number | null;
|
|
149
|
+
active: boolean;
|
|
150
|
+
sortOrder: number;
|
|
151
|
+
notes: string | null;
|
|
152
|
+
metadata: Record<string, unknown> | null;
|
|
153
|
+
createdAt: Date;
|
|
154
|
+
updatedAt: Date;
|
|
155
|
+
}[];
|
|
156
|
+
total: number;
|
|
157
|
+
limit: number;
|
|
158
|
+
offset: number;
|
|
159
|
+
}>;
|
|
160
|
+
export declare function getExtraPriceRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
161
|
+
id: string;
|
|
162
|
+
optionPriceRuleId: string;
|
|
163
|
+
optionId: string;
|
|
164
|
+
productExtraId: string | null;
|
|
165
|
+
optionExtraConfigId: string | null;
|
|
166
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
167
|
+
sellAmountCents: number | null;
|
|
168
|
+
costAmountCents: number | null;
|
|
169
|
+
active: boolean;
|
|
170
|
+
sortOrder: number;
|
|
171
|
+
notes: string | null;
|
|
172
|
+
metadata: Record<string, unknown> | null;
|
|
173
|
+
createdAt: Date;
|
|
174
|
+
updatedAt: Date;
|
|
175
|
+
} | null>;
|
|
176
|
+
export declare function createExtraPriceRule(db: PostgresJsDatabase, data: CreateExtraPriceRuleInput): Promise<{
|
|
177
|
+
metadata: Record<string, unknown> | null;
|
|
178
|
+
id: string;
|
|
179
|
+
createdAt: Date;
|
|
180
|
+
notes: string | null;
|
|
181
|
+
updatedAt: Date;
|
|
182
|
+
active: boolean;
|
|
183
|
+
sortOrder: number;
|
|
184
|
+
optionId: string;
|
|
185
|
+
sellAmountCents: number | null;
|
|
186
|
+
costAmountCents: number | null;
|
|
187
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
188
|
+
optionPriceRuleId: string;
|
|
189
|
+
productExtraId: string | null;
|
|
190
|
+
optionExtraConfigId: string | null;
|
|
191
|
+
} | null>;
|
|
192
|
+
export declare function updateExtraPriceRule(db: PostgresJsDatabase, id: string, data: UpdateExtraPriceRuleInput): Promise<{
|
|
193
|
+
id: string;
|
|
194
|
+
optionPriceRuleId: string;
|
|
195
|
+
optionId: string;
|
|
196
|
+
productExtraId: string | null;
|
|
197
|
+
optionExtraConfigId: string | null;
|
|
198
|
+
pricingMode: "unavailable" | "on_request" | "per_person" | "per_booking" | "included";
|
|
199
|
+
sellAmountCents: number | null;
|
|
200
|
+
costAmountCents: number | null;
|
|
201
|
+
active: boolean;
|
|
202
|
+
sortOrder: number;
|
|
203
|
+
notes: string | null;
|
|
204
|
+
metadata: Record<string, unknown> | null;
|
|
205
|
+
createdAt: Date;
|
|
206
|
+
updatedAt: Date;
|
|
207
|
+
} | null>;
|
|
208
|
+
export declare function deleteExtraPriceRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
209
|
+
id: string;
|
|
210
|
+
} | null>;
|
|
211
|
+
//# sourceMappingURL=service-transfer-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-transfer-rules.d.ts","sourceRoot":"","sources":["../../src/pricing/service-transfer-rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAA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CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;GA0B/F;AAED,wBAAsB,qBAAqB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;UAG7E;AAED,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,yBAAyB;;;;;;;;;;;;;;;UAIhC;AAED,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB;;;;;;;;;;;;;;;UAQhC;AAED,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAM5E"}
|
|
@@ -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
|
+
}
|