@voyantjs/availability 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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAe5B,OAAO,KAAK,EACV,mCAAmC,EACnC,sCAAsC,EACtC,+BAA+B,EAC/B,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EACpC,+BAA+B,EAC/B,gCAAgC,EAChC,mCAAmC,EACnC,4BAA4B,EAC5B,kCAAkC,EAClC,4BAA4B,EAC5B,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,uBAAuB,EACvB,0BAA0B,EAC1B,gCAAgC,EAChC,iCAAiC,EACjC,0BAA0B,EAC1B,6BAA6B,EAC7B,mCAAmC,EACnC,gCAAgC,EAChC,mCAAmC,EACnC,4BAA4B,EAC5B,kCAAkC,EAClC,4BAA4B,EAC5B,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,uBAAuB,EACvB,0BAA0B,EAC1B,gCAAgC,EACjC,MAAM,iBAAiB,CAAA;AAExB,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAA;AAChF,KAAK,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oCAAoC,CAAC,CAAA;AAC1F,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAA;AAChF,KAAK,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAA;AACxF,KAAK,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sCAAsC,CAAC,CAAA;AAC9F,KAA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MAAM;;;;;;;;;;;;;;;;;;4BAS/B,kBAAkB,QAAQ,+BAA+B;;;;;;;;;;;;;;;;;;4BAMjF,kBAAkB,MAClB,MAAM,QACJ,+BAA+B;;;;;;;;;;;;;;;;;;4BAUT,kBAAkB,MAAM,MAAM;;;yBAQjC,kBAAkB,SAAS,oBAAoB;;;;;;;;;;;;;;;;2BAsB7C,kBAAkB,MAAM,MAAM;;;;;;;;;;;0BAK/B,kBAAkB,QAAQ,sBAAsB;;;;;;;;;;;0BAKhD,kBAAkB,MAAM,MAAM,QAAQ,sBAAsB;;;;;;;;;;;0BAS5D,kBAAkB,MAAM,MAAM;;;4BAQ5B,kBAAkB,SAAS,uBAAuB;;;;;;;;;;;;;;;;;;8BAqBhD,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;6BAK/B,kBAAkB,QAAQ,yBAAyB;;;;;;;;;;;;;6BAKnD,kBAAkB,MAAM,MAAM,QAAQ,yBAAyB;;;;;;;;;;;;;6BAS/D,kBAAkB,MAAM,MAAM;;;gCAQ3B,kBAAkB,SAAS,2BAA2B;;;;;;;;;;;;;;;;;;;;kCAuBpD,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;iCAS/B,kBAAkB,QAAQ,6BAA6B;;;;;;;;;;;;;;;iCAMpF,kBAAkB,MAClB,MAAM,QACJ,6BAA6B;;;;;;;;;;;;;;;iCAUF,kBAAkB,MAAM,MAAM;;;8BAQjC,kBAAkB,SAAS,yBAAyB;;;;;;;;;;;;;;;gCAqBlD,kBAAkB,MAAM,MAAM;;;;;;;;;;+BAS/B,kBAAkB,QAAQ,2BAA2B;;;;;;;;;;+BAMhF,kBAAkB,MAClB,MAAM,QACJ,2BAA2B;;;;;;;;;;+BAUF,kBAAkB,MAAM,MAAM;;;CAOhE,CAAA"}
@@ -0,0 +1,519 @@
1
+ import { and, asc, desc, eq, sql } from "drizzle-orm";
2
+ import { availabilityCloseouts, availabilityPickupPoints, availabilityRules, availabilitySlotPickups, availabilitySlots, availabilityStartTimes, customPickupAreas, locationPickupTimes, pickupGroups, pickupLocations, productMeetingConfigs, } from "./schema.js";
3
+ async function paginate(rowsQuery, countQuery, limit, offset) {
4
+ const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
5
+ return {
6
+ data,
7
+ total: countResult[0]?.count ?? 0,
8
+ limit,
9
+ offset,
10
+ };
11
+ }
12
+ function toDateOrNull(value) {
13
+ return value ? new Date(value) : null;
14
+ }
15
+ export const availabilityService = {
16
+ async listRules(db, query) {
17
+ const conditions = [];
18
+ if (query.productId)
19
+ conditions.push(eq(availabilityRules.productId, query.productId));
20
+ if (query.optionId)
21
+ conditions.push(eq(availabilityRules.optionId, query.optionId));
22
+ if (query.facilityId)
23
+ conditions.push(eq(availabilityRules.facilityId, query.facilityId));
24
+ if (query.active !== undefined)
25
+ conditions.push(eq(availabilityRules.active, query.active));
26
+ const where = conditions.length ? and(...conditions) : undefined;
27
+ return paginate(db
28
+ .select()
29
+ .from(availabilityRules)
30
+ .where(where)
31
+ .limit(query.limit)
32
+ .offset(query.offset)
33
+ .orderBy(desc(availabilityRules.updatedAt)), db.select({ count: sql `count(*)::int` }).from(availabilityRules).where(where), query.limit, query.offset);
34
+ },
35
+ async getRuleById(db, id) {
36
+ const [row] = await db
37
+ .select()
38
+ .from(availabilityRules)
39
+ .where(eq(availabilityRules.id, id))
40
+ .limit(1);
41
+ return row ?? null;
42
+ },
43
+ async createRule(db, data) {
44
+ const [row] = await db.insert(availabilityRules).values(data).returning();
45
+ return row;
46
+ },
47
+ async updateRule(db, id, data) {
48
+ const [row] = await db
49
+ .update(availabilityRules)
50
+ .set({ ...data, updatedAt: new Date() })
51
+ .where(eq(availabilityRules.id, id))
52
+ .returning();
53
+ return row ?? null;
54
+ },
55
+ async deleteRule(db, id) {
56
+ const [row] = await db
57
+ .delete(availabilityRules)
58
+ .where(eq(availabilityRules.id, id))
59
+ .returning({ id: availabilityRules.id });
60
+ return row ?? null;
61
+ },
62
+ async listStartTimes(db, query) {
63
+ const conditions = [];
64
+ if (query.productId)
65
+ conditions.push(eq(availabilityStartTimes.productId, query.productId));
66
+ if (query.optionId)
67
+ conditions.push(eq(availabilityStartTimes.optionId, query.optionId));
68
+ if (query.facilityId)
69
+ conditions.push(eq(availabilityStartTimes.facilityId, query.facilityId));
70
+ if (query.active !== undefined)
71
+ conditions.push(eq(availabilityStartTimes.active, query.active));
72
+ const where = conditions.length ? and(...conditions) : undefined;
73
+ return paginate(db
74
+ .select()
75
+ .from(availabilityStartTimes)
76
+ .where(where)
77
+ .limit(query.limit)
78
+ .offset(query.offset)
79
+ .orderBy(availabilityStartTimes.sortOrder, availabilityStartTimes.createdAt), db.select({ count: sql `count(*)::int` }).from(availabilityStartTimes).where(where), query.limit, query.offset);
80
+ },
81
+ async getStartTimeById(db, id) {
82
+ const [row] = await db
83
+ .select()
84
+ .from(availabilityStartTimes)
85
+ .where(eq(availabilityStartTimes.id, id))
86
+ .limit(1);
87
+ return row ?? null;
88
+ },
89
+ async createStartTime(db, data) {
90
+ const [row] = await db.insert(availabilityStartTimes).values(data).returning();
91
+ return row;
92
+ },
93
+ async updateStartTime(db, id, data) {
94
+ const [row] = await db
95
+ .update(availabilityStartTimes)
96
+ .set({ ...data, updatedAt: new Date() })
97
+ .where(eq(availabilityStartTimes.id, id))
98
+ .returning();
99
+ return row ?? null;
100
+ },
101
+ async deleteStartTime(db, id) {
102
+ const [row] = await db
103
+ .delete(availabilityStartTimes)
104
+ .where(eq(availabilityStartTimes.id, id))
105
+ .returning({ id: availabilityStartTimes.id });
106
+ return row ?? null;
107
+ },
108
+ async listSlots(db, query) {
109
+ const conditions = [];
110
+ if (query.productId)
111
+ conditions.push(eq(availabilitySlots.productId, query.productId));
112
+ if (query.optionId)
113
+ conditions.push(eq(availabilitySlots.optionId, query.optionId));
114
+ if (query.facilityId)
115
+ conditions.push(eq(availabilitySlots.facilityId, query.facilityId));
116
+ if (query.availabilityRuleId)
117
+ conditions.push(eq(availabilitySlots.availabilityRuleId, query.availabilityRuleId));
118
+ if (query.startTimeId)
119
+ conditions.push(eq(availabilitySlots.startTimeId, query.startTimeId));
120
+ if (query.dateLocal)
121
+ conditions.push(eq(availabilitySlots.dateLocal, query.dateLocal));
122
+ if (query.status)
123
+ conditions.push(eq(availabilitySlots.status, query.status));
124
+ const where = conditions.length ? and(...conditions) : undefined;
125
+ return paginate(db
126
+ .select()
127
+ .from(availabilitySlots)
128
+ .where(where)
129
+ .limit(query.limit)
130
+ .offset(query.offset)
131
+ .orderBy(asc(availabilitySlots.startsAt)), db.select({ count: sql `count(*)::int` }).from(availabilitySlots).where(where), query.limit, query.offset);
132
+ },
133
+ async getSlotById(db, id) {
134
+ const [row] = await db
135
+ .select()
136
+ .from(availabilitySlots)
137
+ .where(eq(availabilitySlots.id, id))
138
+ .limit(1);
139
+ return row ?? null;
140
+ },
141
+ async createSlot(db, data) {
142
+ const [row] = await db
143
+ .insert(availabilitySlots)
144
+ .values({
145
+ ...data,
146
+ startsAt: new Date(data.startsAt),
147
+ endsAt: toDateOrNull(data.endsAt),
148
+ })
149
+ .returning();
150
+ return row;
151
+ },
152
+ async updateSlot(db, id, data) {
153
+ const patch = {
154
+ ...data,
155
+ startsAt: data.startsAt === undefined ? undefined : new Date(data.startsAt),
156
+ endsAt: data.endsAt === undefined ? undefined : toDateOrNull(data.endsAt),
157
+ updatedAt: new Date(),
158
+ };
159
+ const [row] = await db
160
+ .update(availabilitySlots)
161
+ .set(patch)
162
+ .where(eq(availabilitySlots.id, id))
163
+ .returning();
164
+ return row ?? null;
165
+ },
166
+ async deleteSlot(db, id) {
167
+ const [row] = await db
168
+ .delete(availabilitySlots)
169
+ .where(eq(availabilitySlots.id, id))
170
+ .returning({ id: availabilitySlots.id });
171
+ return row ?? null;
172
+ },
173
+ async listCloseouts(db, query) {
174
+ const conditions = [];
175
+ if (query.productId)
176
+ conditions.push(eq(availabilityCloseouts.productId, query.productId));
177
+ if (query.slotId)
178
+ conditions.push(eq(availabilityCloseouts.slotId, query.slotId));
179
+ if (query.dateLocal)
180
+ conditions.push(eq(availabilityCloseouts.dateLocal, query.dateLocal));
181
+ const where = conditions.length ? and(...conditions) : undefined;
182
+ return paginate(db
183
+ .select()
184
+ .from(availabilityCloseouts)
185
+ .where(where)
186
+ .limit(query.limit)
187
+ .offset(query.offset)
188
+ .orderBy(desc(availabilityCloseouts.createdAt)), db.select({ count: sql `count(*)::int` }).from(availabilityCloseouts).where(where), query.limit, query.offset);
189
+ },
190
+ async getCloseoutById(db, id) {
191
+ const [row] = await db
192
+ .select()
193
+ .from(availabilityCloseouts)
194
+ .where(eq(availabilityCloseouts.id, id))
195
+ .limit(1);
196
+ return row ?? null;
197
+ },
198
+ async createCloseout(db, data) {
199
+ const [row] = await db.insert(availabilityCloseouts).values(data).returning();
200
+ return row;
201
+ },
202
+ async updateCloseout(db, id, data) {
203
+ const [row] = await db
204
+ .update(availabilityCloseouts)
205
+ .set(data)
206
+ .where(eq(availabilityCloseouts.id, id))
207
+ .returning();
208
+ return row ?? null;
209
+ },
210
+ async deleteCloseout(db, id) {
211
+ const [row] = await db
212
+ .delete(availabilityCloseouts)
213
+ .where(eq(availabilityCloseouts.id, id))
214
+ .returning({ id: availabilityCloseouts.id });
215
+ return row ?? null;
216
+ },
217
+ async listPickupPoints(db, query) {
218
+ const conditions = [];
219
+ if (query.productId)
220
+ conditions.push(eq(availabilityPickupPoints.productId, query.productId));
221
+ if (query.facilityId)
222
+ conditions.push(eq(availabilityPickupPoints.facilityId, query.facilityId));
223
+ if (query.active !== undefined)
224
+ conditions.push(eq(availabilityPickupPoints.active, query.active));
225
+ const where = conditions.length ? and(...conditions) : undefined;
226
+ return paginate(db
227
+ .select()
228
+ .from(availabilityPickupPoints)
229
+ .where(where)
230
+ .limit(query.limit)
231
+ .offset(query.offset)
232
+ .orderBy(availabilityPickupPoints.createdAt), db.select({ count: sql `count(*)::int` }).from(availabilityPickupPoints).where(where), query.limit, query.offset);
233
+ },
234
+ async getPickupPointById(db, id) {
235
+ const [row] = await db
236
+ .select()
237
+ .from(availabilityPickupPoints)
238
+ .where(eq(availabilityPickupPoints.id, id))
239
+ .limit(1);
240
+ return row ?? null;
241
+ },
242
+ async createPickupPoint(db, data) {
243
+ const [row] = await db.insert(availabilityPickupPoints).values(data).returning();
244
+ return row;
245
+ },
246
+ async updatePickupPoint(db, id, data) {
247
+ const [row] = await db
248
+ .update(availabilityPickupPoints)
249
+ .set({ ...data, updatedAt: new Date() })
250
+ .where(eq(availabilityPickupPoints.id, id))
251
+ .returning();
252
+ return row ?? null;
253
+ },
254
+ async deletePickupPoint(db, id) {
255
+ const [row] = await db
256
+ .delete(availabilityPickupPoints)
257
+ .where(eq(availabilityPickupPoints.id, id))
258
+ .returning({ id: availabilityPickupPoints.id });
259
+ return row ?? null;
260
+ },
261
+ async listSlotPickups(db, query) {
262
+ const conditions = [];
263
+ if (query.slotId)
264
+ conditions.push(eq(availabilitySlotPickups.slotId, query.slotId));
265
+ if (query.pickupPointId)
266
+ conditions.push(eq(availabilitySlotPickups.pickupPointId, query.pickupPointId));
267
+ const where = conditions.length ? and(...conditions) : undefined;
268
+ return paginate(db
269
+ .select()
270
+ .from(availabilitySlotPickups)
271
+ .where(where)
272
+ .limit(query.limit)
273
+ .offset(query.offset)
274
+ .orderBy(availabilitySlotPickups.createdAt), db.select({ count: sql `count(*)::int` }).from(availabilitySlotPickups).where(where), query.limit, query.offset);
275
+ },
276
+ async getSlotPickupById(db, id) {
277
+ const [row] = await db
278
+ .select()
279
+ .from(availabilitySlotPickups)
280
+ .where(eq(availabilitySlotPickups.id, id))
281
+ .limit(1);
282
+ return row ?? null;
283
+ },
284
+ async createSlotPickup(db, data) {
285
+ const [row] = await db.insert(availabilitySlotPickups).values(data).returning();
286
+ return row;
287
+ },
288
+ async updateSlotPickup(db, id, data) {
289
+ const [row] = await db
290
+ .update(availabilitySlotPickups)
291
+ .set({ ...data, updatedAt: new Date() })
292
+ .where(eq(availabilitySlotPickups.id, id))
293
+ .returning();
294
+ return row ?? null;
295
+ },
296
+ async deleteSlotPickup(db, id) {
297
+ const [row] = await db
298
+ .delete(availabilitySlotPickups)
299
+ .where(eq(availabilitySlotPickups.id, id))
300
+ .returning({ id: availabilitySlotPickups.id });
301
+ return row ?? null;
302
+ },
303
+ async listMeetingConfigs(db, query) {
304
+ const conditions = [];
305
+ if (query.productId)
306
+ conditions.push(eq(productMeetingConfigs.productId, query.productId));
307
+ if (query.optionId)
308
+ conditions.push(eq(productMeetingConfigs.optionId, query.optionId));
309
+ if (query.facilityId)
310
+ conditions.push(eq(productMeetingConfigs.facilityId, query.facilityId));
311
+ if (query.mode)
312
+ conditions.push(eq(productMeetingConfigs.mode, query.mode));
313
+ if (query.active !== undefined)
314
+ conditions.push(eq(productMeetingConfigs.active, query.active));
315
+ const where = conditions.length ? and(...conditions) : undefined;
316
+ return paginate(db
317
+ .select()
318
+ .from(productMeetingConfigs)
319
+ .where(where)
320
+ .limit(query.limit)
321
+ .offset(query.offset)
322
+ .orderBy(desc(productMeetingConfigs.updatedAt)), db.select({ count: sql `count(*)::int` }).from(productMeetingConfigs).where(where), query.limit, query.offset);
323
+ },
324
+ async getMeetingConfigById(db, id) {
325
+ const [row] = await db
326
+ .select()
327
+ .from(productMeetingConfigs)
328
+ .where(eq(productMeetingConfigs.id, id))
329
+ .limit(1);
330
+ return row ?? null;
331
+ },
332
+ async createMeetingConfig(db, data) {
333
+ const [row] = await db.insert(productMeetingConfigs).values(data).returning();
334
+ return row;
335
+ },
336
+ async updateMeetingConfig(db, id, data) {
337
+ const [row] = await db
338
+ .update(productMeetingConfigs)
339
+ .set({ ...data, updatedAt: new Date() })
340
+ .where(eq(productMeetingConfigs.id, id))
341
+ .returning();
342
+ return row ?? null;
343
+ },
344
+ async deleteMeetingConfig(db, id) {
345
+ const [row] = await db
346
+ .delete(productMeetingConfigs)
347
+ .where(eq(productMeetingConfigs.id, id))
348
+ .returning({ id: productMeetingConfigs.id });
349
+ return row ?? null;
350
+ },
351
+ async listPickupGroups(db, query) {
352
+ const conditions = [];
353
+ if (query.meetingConfigId)
354
+ conditions.push(eq(pickupGroups.meetingConfigId, query.meetingConfigId));
355
+ if (query.kind)
356
+ conditions.push(eq(pickupGroups.kind, query.kind));
357
+ if (query.active !== undefined)
358
+ conditions.push(eq(pickupGroups.active, query.active));
359
+ const where = conditions.length ? and(...conditions) : undefined;
360
+ return paginate(db
361
+ .select()
362
+ .from(pickupGroups)
363
+ .where(where)
364
+ .limit(query.limit)
365
+ .offset(query.offset)
366
+ .orderBy(asc(pickupGroups.sortOrder), pickupGroups.createdAt), db.select({ count: sql `count(*)::int` }).from(pickupGroups).where(where), query.limit, query.offset);
367
+ },
368
+ async getPickupGroupById(db, id) {
369
+ const [row] = await db.select().from(pickupGroups).where(eq(pickupGroups.id, id)).limit(1);
370
+ return row ?? null;
371
+ },
372
+ async createPickupGroup(db, data) {
373
+ const [row] = await db.insert(pickupGroups).values(data).returning();
374
+ return row;
375
+ },
376
+ async updatePickupGroup(db, id, data) {
377
+ const [row] = await db
378
+ .update(pickupGroups)
379
+ .set({ ...data, updatedAt: new Date() })
380
+ .where(eq(pickupGroups.id, id))
381
+ .returning();
382
+ return row ?? null;
383
+ },
384
+ async deletePickupGroup(db, id) {
385
+ const [row] = await db
386
+ .delete(pickupGroups)
387
+ .where(eq(pickupGroups.id, id))
388
+ .returning({ id: pickupGroups.id });
389
+ return row ?? null;
390
+ },
391
+ async listPickupLocations(db, query) {
392
+ const conditions = [];
393
+ if (query.groupId)
394
+ conditions.push(eq(pickupLocations.groupId, query.groupId));
395
+ if (query.facilityId)
396
+ conditions.push(eq(pickupLocations.facilityId, query.facilityId));
397
+ if (query.active !== undefined)
398
+ conditions.push(eq(pickupLocations.active, query.active));
399
+ const where = conditions.length ? and(...conditions) : undefined;
400
+ return paginate(db
401
+ .select()
402
+ .from(pickupLocations)
403
+ .where(where)
404
+ .limit(query.limit)
405
+ .offset(query.offset)
406
+ .orderBy(asc(pickupLocations.sortOrder), pickupLocations.createdAt), db.select({ count: sql `count(*)::int` }).from(pickupLocations).where(where), query.limit, query.offset);
407
+ },
408
+ async getPickupLocationById(db, id) {
409
+ const [row] = await db.select().from(pickupLocations).where(eq(pickupLocations.id, id)).limit(1);
410
+ return row ?? null;
411
+ },
412
+ async createPickupLocation(db, data) {
413
+ const [row] = await db.insert(pickupLocations).values(data).returning();
414
+ return row;
415
+ },
416
+ async updatePickupLocation(db, id, data) {
417
+ const [row] = await db
418
+ .update(pickupLocations)
419
+ .set({ ...data, updatedAt: new Date() })
420
+ .where(eq(pickupLocations.id, id))
421
+ .returning();
422
+ return row ?? null;
423
+ },
424
+ async deletePickupLocation(db, id) {
425
+ const [row] = await db
426
+ .delete(pickupLocations)
427
+ .where(eq(pickupLocations.id, id))
428
+ .returning({ id: pickupLocations.id });
429
+ return row ?? null;
430
+ },
431
+ async listLocationPickupTimes(db, query) {
432
+ const conditions = [];
433
+ if (query.pickupLocationId)
434
+ conditions.push(eq(locationPickupTimes.pickupLocationId, query.pickupLocationId));
435
+ if (query.slotId)
436
+ conditions.push(eq(locationPickupTimes.slotId, query.slotId));
437
+ if (query.startTimeId)
438
+ conditions.push(eq(locationPickupTimes.startTimeId, query.startTimeId));
439
+ if (query.active !== undefined)
440
+ conditions.push(eq(locationPickupTimes.active, query.active));
441
+ const where = conditions.length ? and(...conditions) : undefined;
442
+ return paginate(db
443
+ .select()
444
+ .from(locationPickupTimes)
445
+ .where(where)
446
+ .limit(query.limit)
447
+ .offset(query.offset)
448
+ .orderBy(locationPickupTimes.createdAt), db.select({ count: sql `count(*)::int` }).from(locationPickupTimes).where(where), query.limit, query.offset);
449
+ },
450
+ async getLocationPickupTimeById(db, id) {
451
+ const [row] = await db
452
+ .select()
453
+ .from(locationPickupTimes)
454
+ .where(eq(locationPickupTimes.id, id))
455
+ .limit(1);
456
+ return row ?? null;
457
+ },
458
+ async createLocationPickupTime(db, data) {
459
+ const [row] = await db.insert(locationPickupTimes).values(data).returning();
460
+ return row;
461
+ },
462
+ async updateLocationPickupTime(db, id, data) {
463
+ const [row] = await db
464
+ .update(locationPickupTimes)
465
+ .set({ ...data, updatedAt: new Date() })
466
+ .where(eq(locationPickupTimes.id, id))
467
+ .returning();
468
+ return row ?? null;
469
+ },
470
+ async deleteLocationPickupTime(db, id) {
471
+ const [row] = await db
472
+ .delete(locationPickupTimes)
473
+ .where(eq(locationPickupTimes.id, id))
474
+ .returning({ id: locationPickupTimes.id });
475
+ return row ?? null;
476
+ },
477
+ async listCustomPickupAreas(db, query) {
478
+ const conditions = [];
479
+ if (query.meetingConfigId)
480
+ conditions.push(eq(customPickupAreas.meetingConfigId, query.meetingConfigId));
481
+ if (query.active !== undefined)
482
+ conditions.push(eq(customPickupAreas.active, query.active));
483
+ const where = conditions.length ? and(...conditions) : undefined;
484
+ return paginate(db
485
+ .select()
486
+ .from(customPickupAreas)
487
+ .where(where)
488
+ .limit(query.limit)
489
+ .offset(query.offset)
490
+ .orderBy(customPickupAreas.createdAt), db.select({ count: sql `count(*)::int` }).from(customPickupAreas).where(where), query.limit, query.offset);
491
+ },
492
+ async getCustomPickupAreaById(db, id) {
493
+ const [row] = await db
494
+ .select()
495
+ .from(customPickupAreas)
496
+ .where(eq(customPickupAreas.id, id))
497
+ .limit(1);
498
+ return row ?? null;
499
+ },
500
+ async createCustomPickupArea(db, data) {
501
+ const [row] = await db.insert(customPickupAreas).values(data).returning();
502
+ return row;
503
+ },
504
+ async updateCustomPickupArea(db, id, data) {
505
+ const [row] = await db
506
+ .update(customPickupAreas)
507
+ .set({ ...data, updatedAt: new Date() })
508
+ .where(eq(customPickupAreas.id, id))
509
+ .returning();
510
+ return row ?? null;
511
+ },
512
+ async deleteCustomPickupArea(db, id) {
513
+ const [row] = await db
514
+ .delete(customPickupAreas)
515
+ .where(eq(customPickupAreas.id, id))
516
+ .returning({ id: customPickupAreas.id });
517
+ return row ?? null;
518
+ },
519
+ };