@voyantjs/availability 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/routes-core.d.ts +851 -0
- package/dist/routes-core.d.ts.map +1 -0
- package/dist/routes-core.js +153 -0
- package/dist/routes-pickups.d.ts +1362 -0
- package/dist/routes-pickups.d.ts.map +1 -0
- package/dist/routes-pickups.js +264 -0
- package/dist/routes-shared.d.ts +49 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +45 -0
- package/dist/routes.d.ts +3 -2216
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +5 -540
- package/dist/service-core.d.ts +291 -0
- package/dist/service-core.d.ts.map +1 -0
- package/dist/service-core.js +205 -0
- package/dist/service-pickups.d.ts +407 -0
- package/dist/service-pickups.d.ts.map +1 -0
- package/dist/service-pickups.js +308 -0
- package/dist/service-shared.d.ts +45 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +12 -0
- package/dist/service.d.ts +57 -729
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +57 -517
- package/package.json +5 -5
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { AvailabilityCloseoutListQuery, AvailabilityRuleListQuery, AvailabilitySlotListQuery, AvailabilityStartTimeListQuery, CreateAvailabilityCloseoutInput, CreateAvailabilityRuleInput, CreateAvailabilitySlotInput, CreateAvailabilityStartTimeInput, UpdateAvailabilityCloseoutInput, UpdateAvailabilityRuleInput, UpdateAvailabilitySlotInput, UpdateAvailabilityStartTimeInput } from "./service-shared.js";
|
|
3
|
+
export declare function listRules(db: PostgresJsDatabase, query: AvailabilityRuleListQuery): Promise<{
|
|
4
|
+
data: {
|
|
5
|
+
id: string;
|
|
6
|
+
productId: string;
|
|
7
|
+
optionId: string | null;
|
|
8
|
+
facilityId: string | null;
|
|
9
|
+
timezone: string;
|
|
10
|
+
recurrenceRule: string;
|
|
11
|
+
maxCapacity: number;
|
|
12
|
+
maxPickupCapacity: number | null;
|
|
13
|
+
minTotalPax: number | null;
|
|
14
|
+
cutoffMinutes: number | null;
|
|
15
|
+
earlyBookingLimitMinutes: number | null;
|
|
16
|
+
active: boolean;
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
updatedAt: Date;
|
|
19
|
+
}[];
|
|
20
|
+
total: number;
|
|
21
|
+
limit: number;
|
|
22
|
+
offset: number;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function getRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
productId: string;
|
|
27
|
+
optionId: string | null;
|
|
28
|
+
facilityId: string | null;
|
|
29
|
+
timezone: string;
|
|
30
|
+
recurrenceRule: string;
|
|
31
|
+
maxCapacity: number;
|
|
32
|
+
maxPickupCapacity: number | null;
|
|
33
|
+
minTotalPax: number | null;
|
|
34
|
+
cutoffMinutes: number | null;
|
|
35
|
+
earlyBookingLimitMinutes: number | null;
|
|
36
|
+
active: boolean;
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
} | null>;
|
|
40
|
+
export declare function createRule(db: PostgresJsDatabase, data: CreateAvailabilityRuleInput): Promise<{
|
|
41
|
+
id: string;
|
|
42
|
+
productId: string;
|
|
43
|
+
optionId: string | null;
|
|
44
|
+
facilityId: string | null;
|
|
45
|
+
timezone: string;
|
|
46
|
+
recurrenceRule: string;
|
|
47
|
+
maxCapacity: number;
|
|
48
|
+
maxPickupCapacity: number | null;
|
|
49
|
+
minTotalPax: number | null;
|
|
50
|
+
cutoffMinutes: number | null;
|
|
51
|
+
earlyBookingLimitMinutes: number | null;
|
|
52
|
+
active: boolean;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
} | undefined>;
|
|
56
|
+
export declare function updateRule(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityRuleInput): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
productId: string;
|
|
59
|
+
optionId: string | null;
|
|
60
|
+
facilityId: string | null;
|
|
61
|
+
timezone: string;
|
|
62
|
+
recurrenceRule: string;
|
|
63
|
+
maxCapacity: number;
|
|
64
|
+
maxPickupCapacity: number | null;
|
|
65
|
+
minTotalPax: number | null;
|
|
66
|
+
cutoffMinutes: number | null;
|
|
67
|
+
earlyBookingLimitMinutes: number | null;
|
|
68
|
+
active: boolean;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
} | null>;
|
|
72
|
+
export declare function deleteRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
73
|
+
id: string;
|
|
74
|
+
} | null>;
|
|
75
|
+
export declare function listStartTimes(db: PostgresJsDatabase, query: AvailabilityStartTimeListQuery): Promise<{
|
|
76
|
+
data: {
|
|
77
|
+
id: string;
|
|
78
|
+
productId: string;
|
|
79
|
+
optionId: string | null;
|
|
80
|
+
facilityId: string | null;
|
|
81
|
+
label: string | null;
|
|
82
|
+
startTimeLocal: string;
|
|
83
|
+
durationMinutes: number | null;
|
|
84
|
+
sortOrder: number;
|
|
85
|
+
active: boolean;
|
|
86
|
+
createdAt: Date;
|
|
87
|
+
updatedAt: Date;
|
|
88
|
+
}[];
|
|
89
|
+
total: number;
|
|
90
|
+
limit: number;
|
|
91
|
+
offset: number;
|
|
92
|
+
}>;
|
|
93
|
+
export declare function getStartTimeById(db: PostgresJsDatabase, id: string): Promise<{
|
|
94
|
+
id: string;
|
|
95
|
+
productId: string;
|
|
96
|
+
optionId: string | null;
|
|
97
|
+
facilityId: string | null;
|
|
98
|
+
label: string | null;
|
|
99
|
+
startTimeLocal: string;
|
|
100
|
+
durationMinutes: number | null;
|
|
101
|
+
sortOrder: number;
|
|
102
|
+
active: boolean;
|
|
103
|
+
createdAt: Date;
|
|
104
|
+
updatedAt: Date;
|
|
105
|
+
} | null>;
|
|
106
|
+
export declare function createStartTime(db: PostgresJsDatabase, data: CreateAvailabilityStartTimeInput): Promise<{
|
|
107
|
+
id: string;
|
|
108
|
+
productId: string;
|
|
109
|
+
optionId: string | null;
|
|
110
|
+
facilityId: string | null;
|
|
111
|
+
active: boolean;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
label: string | null;
|
|
115
|
+
startTimeLocal: string;
|
|
116
|
+
durationMinutes: number | null;
|
|
117
|
+
sortOrder: number;
|
|
118
|
+
} | undefined>;
|
|
119
|
+
export declare function updateStartTime(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityStartTimeInput): Promise<{
|
|
120
|
+
id: string;
|
|
121
|
+
productId: string;
|
|
122
|
+
optionId: string | null;
|
|
123
|
+
facilityId: string | null;
|
|
124
|
+
label: string | null;
|
|
125
|
+
startTimeLocal: string;
|
|
126
|
+
durationMinutes: number | null;
|
|
127
|
+
sortOrder: number;
|
|
128
|
+
active: boolean;
|
|
129
|
+
createdAt: Date;
|
|
130
|
+
updatedAt: Date;
|
|
131
|
+
} | null>;
|
|
132
|
+
export declare function deleteStartTime(db: PostgresJsDatabase, id: string): Promise<{
|
|
133
|
+
id: string;
|
|
134
|
+
} | null>;
|
|
135
|
+
export declare function listSlots(db: PostgresJsDatabase, query: AvailabilitySlotListQuery): Promise<{
|
|
136
|
+
data: {
|
|
137
|
+
id: string;
|
|
138
|
+
productId: string;
|
|
139
|
+
optionId: string | null;
|
|
140
|
+
facilityId: string | null;
|
|
141
|
+
availabilityRuleId: string | null;
|
|
142
|
+
startTimeId: string | null;
|
|
143
|
+
dateLocal: string;
|
|
144
|
+
startsAt: Date;
|
|
145
|
+
endsAt: Date | null;
|
|
146
|
+
timezone: string;
|
|
147
|
+
status: "open" | "closed" | "sold_out" | "cancelled";
|
|
148
|
+
unlimited: boolean;
|
|
149
|
+
initialPax: number | null;
|
|
150
|
+
remainingPax: number | null;
|
|
151
|
+
initialPickups: number | null;
|
|
152
|
+
remainingPickups: number | null;
|
|
153
|
+
remainingResources: number | null;
|
|
154
|
+
pastCutoff: boolean;
|
|
155
|
+
tooEarly: boolean;
|
|
156
|
+
nights: number | null;
|
|
157
|
+
days: number | null;
|
|
158
|
+
notes: string | null;
|
|
159
|
+
createdAt: Date;
|
|
160
|
+
updatedAt: Date;
|
|
161
|
+
}[];
|
|
162
|
+
total: number;
|
|
163
|
+
limit: number;
|
|
164
|
+
offset: number;
|
|
165
|
+
}>;
|
|
166
|
+
export declare function getSlotById(db: PostgresJsDatabase, id: string): Promise<{
|
|
167
|
+
id: string;
|
|
168
|
+
productId: string;
|
|
169
|
+
optionId: string | null;
|
|
170
|
+
facilityId: string | null;
|
|
171
|
+
availabilityRuleId: string | null;
|
|
172
|
+
startTimeId: string | null;
|
|
173
|
+
dateLocal: string;
|
|
174
|
+
startsAt: Date;
|
|
175
|
+
endsAt: Date | null;
|
|
176
|
+
timezone: string;
|
|
177
|
+
status: "open" | "closed" | "sold_out" | "cancelled";
|
|
178
|
+
unlimited: boolean;
|
|
179
|
+
initialPax: number | null;
|
|
180
|
+
remainingPax: number | null;
|
|
181
|
+
initialPickups: number | null;
|
|
182
|
+
remainingPickups: number | null;
|
|
183
|
+
remainingResources: number | null;
|
|
184
|
+
pastCutoff: boolean;
|
|
185
|
+
tooEarly: boolean;
|
|
186
|
+
nights: number | null;
|
|
187
|
+
days: number | null;
|
|
188
|
+
notes: string | null;
|
|
189
|
+
createdAt: Date;
|
|
190
|
+
updatedAt: Date;
|
|
191
|
+
} | null>;
|
|
192
|
+
export declare function createSlot(db: PostgresJsDatabase, data: CreateAvailabilitySlotInput): Promise<{
|
|
193
|
+
id: string;
|
|
194
|
+
productId: string;
|
|
195
|
+
optionId: string | null;
|
|
196
|
+
facilityId: string | null;
|
|
197
|
+
timezone: string;
|
|
198
|
+
createdAt: Date;
|
|
199
|
+
updatedAt: Date;
|
|
200
|
+
availabilityRuleId: string | null;
|
|
201
|
+
startTimeId: string | null;
|
|
202
|
+
dateLocal: string;
|
|
203
|
+
startsAt: Date;
|
|
204
|
+
endsAt: Date | null;
|
|
205
|
+
status: "open" | "closed" | "sold_out" | "cancelled";
|
|
206
|
+
unlimited: boolean;
|
|
207
|
+
initialPax: number | null;
|
|
208
|
+
remainingPax: number | null;
|
|
209
|
+
initialPickups: number | null;
|
|
210
|
+
remainingPickups: number | null;
|
|
211
|
+
remainingResources: number | null;
|
|
212
|
+
pastCutoff: boolean;
|
|
213
|
+
tooEarly: boolean;
|
|
214
|
+
nights: number | null;
|
|
215
|
+
days: number | null;
|
|
216
|
+
notes: string | null;
|
|
217
|
+
} | undefined>;
|
|
218
|
+
export declare function updateSlot(db: PostgresJsDatabase, id: string, data: UpdateAvailabilitySlotInput): Promise<{
|
|
219
|
+
id: string;
|
|
220
|
+
productId: string;
|
|
221
|
+
optionId: string | null;
|
|
222
|
+
facilityId: string | null;
|
|
223
|
+
availabilityRuleId: string | null;
|
|
224
|
+
startTimeId: string | null;
|
|
225
|
+
dateLocal: string;
|
|
226
|
+
startsAt: Date;
|
|
227
|
+
endsAt: Date | null;
|
|
228
|
+
timezone: string;
|
|
229
|
+
status: "open" | "closed" | "sold_out" | "cancelled";
|
|
230
|
+
unlimited: boolean;
|
|
231
|
+
initialPax: number | null;
|
|
232
|
+
remainingPax: number | null;
|
|
233
|
+
initialPickups: number | null;
|
|
234
|
+
remainingPickups: number | null;
|
|
235
|
+
remainingResources: number | null;
|
|
236
|
+
pastCutoff: boolean;
|
|
237
|
+
tooEarly: boolean;
|
|
238
|
+
nights: number | null;
|
|
239
|
+
days: number | null;
|
|
240
|
+
notes: string | null;
|
|
241
|
+
createdAt: Date;
|
|
242
|
+
updatedAt: Date;
|
|
243
|
+
} | null>;
|
|
244
|
+
export declare function deleteSlot(db: PostgresJsDatabase, id: string): Promise<{
|
|
245
|
+
id: string;
|
|
246
|
+
} | null>;
|
|
247
|
+
export declare function listCloseouts(db: PostgresJsDatabase, query: AvailabilityCloseoutListQuery): Promise<{
|
|
248
|
+
data: {
|
|
249
|
+
id: string;
|
|
250
|
+
productId: string;
|
|
251
|
+
slotId: string | null;
|
|
252
|
+
dateLocal: string;
|
|
253
|
+
reason: string | null;
|
|
254
|
+
createdBy: string | null;
|
|
255
|
+
createdAt: Date;
|
|
256
|
+
}[];
|
|
257
|
+
total: number;
|
|
258
|
+
limit: number;
|
|
259
|
+
offset: number;
|
|
260
|
+
}>;
|
|
261
|
+
export declare function getCloseoutById(db: PostgresJsDatabase, id: string): Promise<{
|
|
262
|
+
id: string;
|
|
263
|
+
productId: string;
|
|
264
|
+
slotId: string | null;
|
|
265
|
+
dateLocal: string;
|
|
266
|
+
reason: string | null;
|
|
267
|
+
createdBy: string | null;
|
|
268
|
+
createdAt: Date;
|
|
269
|
+
} | null>;
|
|
270
|
+
export declare function createCloseout(db: PostgresJsDatabase, data: CreateAvailabilityCloseoutInput): Promise<{
|
|
271
|
+
id: string;
|
|
272
|
+
productId: string;
|
|
273
|
+
createdAt: Date;
|
|
274
|
+
dateLocal: string;
|
|
275
|
+
slotId: string | null;
|
|
276
|
+
reason: string | null;
|
|
277
|
+
createdBy: string | null;
|
|
278
|
+
} | undefined>;
|
|
279
|
+
export declare function updateCloseout(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityCloseoutInput): Promise<{
|
|
280
|
+
id: string;
|
|
281
|
+
productId: string;
|
|
282
|
+
slotId: string | null;
|
|
283
|
+
dateLocal: string;
|
|
284
|
+
reason: string | null;
|
|
285
|
+
createdBy: string | null;
|
|
286
|
+
createdAt: Date;
|
|
287
|
+
} | null>;
|
|
288
|
+
export declare function deleteCloseout(db: PostgresJsDatabase, id: string): Promise<{
|
|
289
|
+
id: string;
|
|
290
|
+
} | null>;
|
|
291
|
+
//# sourceMappingURL=service-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-core.d.ts","sourceRoot":"","sources":["../src/service-core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAQjE,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,EACzB,8BAA8B,EAC9B,+BAA+B,EAC/B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EAChC,+BAA+B,EAC/B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,qBAAqB,CAAA;AAG5B,wBAAsB,SAAS,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,yBAAyB;;;;;;;;;;;;;;;;;;;;GAoBvF;AAED,wBAAsB,WAAW,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;UAOnE;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,2BAA2B;;;;;;;;;;;;;;;eAGzF;AAED,wBAAsB,UAAU,CAC9B,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,2BAA2B;;;;;;;;;;;;;;;UAQlC;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMlE;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,8BAA8B;;;;;;;;;;;;;;;;;GAqBtC;AAED,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;UAOxE;AAED,wBAAsB,eAAe,CACnC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,gCAAgC;;;;;;;;;;;;eAIvC;AAED,wBAAsB,eAAe,CACnC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,gCAAgC;;;;;;;;;;;;UAQvC;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMvE;AAED,wBAAsB,SAAS,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyBvF;AAED,wBAAsB,WAAW,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;UAOnE;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;eAUzF;AAED,wBAAsB,UAAU,CAC9B,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;UAelC;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMlE;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,6BAA6B;;;;;;;;;;;;;GAmB/F;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;UAOvE;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,+BAA+B;;;;;;;;eAItC;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,+BAA+B;;;;;;;;UAQtC;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMtE"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { and, asc, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { availabilityCloseouts, availabilityRules, availabilitySlots, availabilityStartTimes, } from "./schema.js";
|
|
3
|
+
import { paginate, toDateOrNull } from "./service-shared.js";
|
|
4
|
+
export async function listRules(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.productId)
|
|
7
|
+
conditions.push(eq(availabilityRules.productId, query.productId));
|
|
8
|
+
if (query.optionId)
|
|
9
|
+
conditions.push(eq(availabilityRules.optionId, query.optionId));
|
|
10
|
+
if (query.facilityId)
|
|
11
|
+
conditions.push(eq(availabilityRules.facilityId, query.facilityId));
|
|
12
|
+
if (query.active !== undefined)
|
|
13
|
+
conditions.push(eq(availabilityRules.active, query.active));
|
|
14
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
15
|
+
return paginate(db
|
|
16
|
+
.select()
|
|
17
|
+
.from(availabilityRules)
|
|
18
|
+
.where(where)
|
|
19
|
+
.limit(query.limit)
|
|
20
|
+
.offset(query.offset)
|
|
21
|
+
.orderBy(desc(availabilityRules.updatedAt)), db.select({ count: sql `count(*)::int` }).from(availabilityRules).where(where), query.limit, query.offset);
|
|
22
|
+
}
|
|
23
|
+
export async function getRuleById(db, id) {
|
|
24
|
+
const [row] = await db
|
|
25
|
+
.select()
|
|
26
|
+
.from(availabilityRules)
|
|
27
|
+
.where(eq(availabilityRules.id, id))
|
|
28
|
+
.limit(1);
|
|
29
|
+
return row ?? null;
|
|
30
|
+
}
|
|
31
|
+
export async function createRule(db, data) {
|
|
32
|
+
const [row] = await db.insert(availabilityRules).values(data).returning();
|
|
33
|
+
return row;
|
|
34
|
+
}
|
|
35
|
+
export async function updateRule(db, id, data) {
|
|
36
|
+
const [row] = await db
|
|
37
|
+
.update(availabilityRules)
|
|
38
|
+
.set({ ...data, updatedAt: new Date() })
|
|
39
|
+
.where(eq(availabilityRules.id, id))
|
|
40
|
+
.returning();
|
|
41
|
+
return row ?? null;
|
|
42
|
+
}
|
|
43
|
+
export async function deleteRule(db, id) {
|
|
44
|
+
const [row] = await db
|
|
45
|
+
.delete(availabilityRules)
|
|
46
|
+
.where(eq(availabilityRules.id, id))
|
|
47
|
+
.returning({ id: availabilityRules.id });
|
|
48
|
+
return row ?? null;
|
|
49
|
+
}
|
|
50
|
+
export async function listStartTimes(db, query) {
|
|
51
|
+
const conditions = [];
|
|
52
|
+
if (query.productId)
|
|
53
|
+
conditions.push(eq(availabilityStartTimes.productId, query.productId));
|
|
54
|
+
if (query.optionId)
|
|
55
|
+
conditions.push(eq(availabilityStartTimes.optionId, query.optionId));
|
|
56
|
+
if (query.facilityId)
|
|
57
|
+
conditions.push(eq(availabilityStartTimes.facilityId, query.facilityId));
|
|
58
|
+
if (query.active !== undefined)
|
|
59
|
+
conditions.push(eq(availabilityStartTimes.active, query.active));
|
|
60
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
61
|
+
return paginate(db
|
|
62
|
+
.select()
|
|
63
|
+
.from(availabilityStartTimes)
|
|
64
|
+
.where(where)
|
|
65
|
+
.limit(query.limit)
|
|
66
|
+
.offset(query.offset)
|
|
67
|
+
.orderBy(availabilityStartTimes.sortOrder, availabilityStartTimes.createdAt), db.select({ count: sql `count(*)::int` }).from(availabilityStartTimes).where(where), query.limit, query.offset);
|
|
68
|
+
}
|
|
69
|
+
export async function getStartTimeById(db, id) {
|
|
70
|
+
const [row] = await db
|
|
71
|
+
.select()
|
|
72
|
+
.from(availabilityStartTimes)
|
|
73
|
+
.where(eq(availabilityStartTimes.id, id))
|
|
74
|
+
.limit(1);
|
|
75
|
+
return row ?? null;
|
|
76
|
+
}
|
|
77
|
+
export async function createStartTime(db, data) {
|
|
78
|
+
const [row] = await db.insert(availabilityStartTimes).values(data).returning();
|
|
79
|
+
return row;
|
|
80
|
+
}
|
|
81
|
+
export async function updateStartTime(db, id, data) {
|
|
82
|
+
const [row] = await db
|
|
83
|
+
.update(availabilityStartTimes)
|
|
84
|
+
.set({ ...data, updatedAt: new Date() })
|
|
85
|
+
.where(eq(availabilityStartTimes.id, id))
|
|
86
|
+
.returning();
|
|
87
|
+
return row ?? null;
|
|
88
|
+
}
|
|
89
|
+
export async function deleteStartTime(db, id) {
|
|
90
|
+
const [row] = await db
|
|
91
|
+
.delete(availabilityStartTimes)
|
|
92
|
+
.where(eq(availabilityStartTimes.id, id))
|
|
93
|
+
.returning({ id: availabilityStartTimes.id });
|
|
94
|
+
return row ?? null;
|
|
95
|
+
}
|
|
96
|
+
export async function listSlots(db, query) {
|
|
97
|
+
const conditions = [];
|
|
98
|
+
if (query.productId)
|
|
99
|
+
conditions.push(eq(availabilitySlots.productId, query.productId));
|
|
100
|
+
if (query.optionId)
|
|
101
|
+
conditions.push(eq(availabilitySlots.optionId, query.optionId));
|
|
102
|
+
if (query.facilityId)
|
|
103
|
+
conditions.push(eq(availabilitySlots.facilityId, query.facilityId));
|
|
104
|
+
if (query.availabilityRuleId) {
|
|
105
|
+
conditions.push(eq(availabilitySlots.availabilityRuleId, query.availabilityRuleId));
|
|
106
|
+
}
|
|
107
|
+
if (query.startTimeId)
|
|
108
|
+
conditions.push(eq(availabilitySlots.startTimeId, query.startTimeId));
|
|
109
|
+
if (query.dateLocal)
|
|
110
|
+
conditions.push(eq(availabilitySlots.dateLocal, query.dateLocal));
|
|
111
|
+
if (query.status)
|
|
112
|
+
conditions.push(eq(availabilitySlots.status, query.status));
|
|
113
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
114
|
+
return paginate(db
|
|
115
|
+
.select()
|
|
116
|
+
.from(availabilitySlots)
|
|
117
|
+
.where(where)
|
|
118
|
+
.limit(query.limit)
|
|
119
|
+
.offset(query.offset)
|
|
120
|
+
.orderBy(asc(availabilitySlots.startsAt)), db.select({ count: sql `count(*)::int` }).from(availabilitySlots).where(where), query.limit, query.offset);
|
|
121
|
+
}
|
|
122
|
+
export async function getSlotById(db, id) {
|
|
123
|
+
const [row] = await db
|
|
124
|
+
.select()
|
|
125
|
+
.from(availabilitySlots)
|
|
126
|
+
.where(eq(availabilitySlots.id, id))
|
|
127
|
+
.limit(1);
|
|
128
|
+
return row ?? null;
|
|
129
|
+
}
|
|
130
|
+
export async function createSlot(db, data) {
|
|
131
|
+
const [row] = await db
|
|
132
|
+
.insert(availabilitySlots)
|
|
133
|
+
.values({
|
|
134
|
+
...data,
|
|
135
|
+
startsAt: new Date(data.startsAt),
|
|
136
|
+
endsAt: toDateOrNull(data.endsAt),
|
|
137
|
+
})
|
|
138
|
+
.returning();
|
|
139
|
+
return row;
|
|
140
|
+
}
|
|
141
|
+
export async function updateSlot(db, id, data) {
|
|
142
|
+
const patch = {
|
|
143
|
+
...data,
|
|
144
|
+
startsAt: data.startsAt === undefined ? undefined : new Date(data.startsAt),
|
|
145
|
+
endsAt: data.endsAt === undefined ? undefined : toDateOrNull(data.endsAt),
|
|
146
|
+
updatedAt: new Date(),
|
|
147
|
+
};
|
|
148
|
+
const [row] = await db
|
|
149
|
+
.update(availabilitySlots)
|
|
150
|
+
.set(patch)
|
|
151
|
+
.where(eq(availabilitySlots.id, id))
|
|
152
|
+
.returning();
|
|
153
|
+
return row ?? null;
|
|
154
|
+
}
|
|
155
|
+
export async function deleteSlot(db, id) {
|
|
156
|
+
const [row] = await db
|
|
157
|
+
.delete(availabilitySlots)
|
|
158
|
+
.where(eq(availabilitySlots.id, id))
|
|
159
|
+
.returning({ id: availabilitySlots.id });
|
|
160
|
+
return row ?? null;
|
|
161
|
+
}
|
|
162
|
+
export async function listCloseouts(db, query) {
|
|
163
|
+
const conditions = [];
|
|
164
|
+
if (query.productId)
|
|
165
|
+
conditions.push(eq(availabilityCloseouts.productId, query.productId));
|
|
166
|
+
if (query.slotId)
|
|
167
|
+
conditions.push(eq(availabilityCloseouts.slotId, query.slotId));
|
|
168
|
+
if (query.dateLocal)
|
|
169
|
+
conditions.push(eq(availabilityCloseouts.dateLocal, query.dateLocal));
|
|
170
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
171
|
+
return paginate(db
|
|
172
|
+
.select()
|
|
173
|
+
.from(availabilityCloseouts)
|
|
174
|
+
.where(where)
|
|
175
|
+
.limit(query.limit)
|
|
176
|
+
.offset(query.offset)
|
|
177
|
+
.orderBy(desc(availabilityCloseouts.createdAt)), db.select({ count: sql `count(*)::int` }).from(availabilityCloseouts).where(where), query.limit, query.offset);
|
|
178
|
+
}
|
|
179
|
+
export async function getCloseoutById(db, id) {
|
|
180
|
+
const [row] = await db
|
|
181
|
+
.select()
|
|
182
|
+
.from(availabilityCloseouts)
|
|
183
|
+
.where(eq(availabilityCloseouts.id, id))
|
|
184
|
+
.limit(1);
|
|
185
|
+
return row ?? null;
|
|
186
|
+
}
|
|
187
|
+
export async function createCloseout(db, data) {
|
|
188
|
+
const [row] = await db.insert(availabilityCloseouts).values(data).returning();
|
|
189
|
+
return row;
|
|
190
|
+
}
|
|
191
|
+
export async function updateCloseout(db, id, data) {
|
|
192
|
+
const [row] = await db
|
|
193
|
+
.update(availabilityCloseouts)
|
|
194
|
+
.set(data)
|
|
195
|
+
.where(eq(availabilityCloseouts.id, id))
|
|
196
|
+
.returning();
|
|
197
|
+
return row ?? null;
|
|
198
|
+
}
|
|
199
|
+
export async function deleteCloseout(db, id) {
|
|
200
|
+
const [row] = await db
|
|
201
|
+
.delete(availabilityCloseouts)
|
|
202
|
+
.where(eq(availabilityCloseouts.id, id))
|
|
203
|
+
.returning({ id: availabilityCloseouts.id });
|
|
204
|
+
return row ?? null;
|
|
205
|
+
}
|