@voyantjs/ground 0.1.1 → 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/service.js CHANGED
@@ -1,630 +1,65 @@
1
- import { and, asc, desc, eq, sql } from "drizzle-orm";
2
- import { groundDispatchAssignments, groundDispatchCheckpoints, groundDispatches, groundDispatchLegs, groundDispatchPassengers, groundDriverShifts, groundDrivers, groundExecutionEvents, groundOperators, groundServiceIncidents, groundTransferPreferences, groundVehicles, } from "./schema.js";
3
- async function paginate(rowsQuery, countQuery, limit, offset) {
4
- const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
5
- return { data, total: countResult[0]?.count ?? 0, limit, offset };
6
- }
7
- function toDateOrNull(value) {
8
- return value ? new Date(value) : null;
9
- }
1
+ import { createDispatch, createExecutionEvent, createTransferPreference, deleteDispatch, deleteExecutionEvent, deleteTransferPreference, getDispatchById, getExecutionEventById, getTransferPreferenceById, listDispatches, listExecutionEvents, listTransferPreferences, updateDispatch, updateExecutionEvent, updateTransferPreference, } from "./service-dispatch-core.js";
2
+ import { createDispatchAssignment, createDispatchCheckpoint, createDispatchLeg, createDispatchPassenger, createServiceIncident, deleteDispatchAssignment, deleteDispatchCheckpoint, deleteDispatchLeg, deleteDispatchPassenger, deleteServiceIncident, getDispatchAssignmentById, getDispatchCheckpointById, getDispatchLegById, getDispatchPassengerById, getServiceIncidentById, listDispatchAssignments, listDispatchCheckpoints, listDispatchLegs, listDispatchPassengers, listServiceIncidents, updateDispatchAssignment, updateDispatchCheckpoint, updateDispatchLeg, updateDispatchPassenger, updateServiceIncident, } from "./service-dispatch-ops.js";
3
+ import { createDriver, createDriverShift, createOperator, createVehicle, deleteDriver, deleteDriverShift, deleteOperator, deleteVehicle, getDriverById, getDriverShiftById, getOperatorById, getVehicleById, listDriverShifts, listDrivers, listOperators, listVehicles, updateDriver, updateDriverShift, updateOperator, updateVehicle, } from "./service-resources.js";
10
4
  export const groundService = {
11
- async listOperators(db, query) {
12
- const conditions = [];
13
- if (query.supplierId)
14
- conditions.push(eq(groundOperators.supplierId, query.supplierId));
15
- if (query.facilityId)
16
- conditions.push(eq(groundOperators.facilityId, query.facilityId));
17
- if (query.active !== undefined)
18
- conditions.push(eq(groundOperators.active, query.active));
19
- const where = conditions.length > 0 ? and(...conditions) : undefined;
20
- return paginate(db
21
- .select()
22
- .from(groundOperators)
23
- .where(where)
24
- .limit(query.limit)
25
- .offset(query.offset)
26
- .orderBy(asc(groundOperators.name), asc(groundOperators.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundOperators).where(where), query.limit, query.offset);
27
- },
28
- async getOperatorById(db, id) {
29
- const [row] = await db.select().from(groundOperators).where(eq(groundOperators.id, id)).limit(1);
30
- return row ?? null;
31
- },
32
- async createOperator(db, data) {
33
- const [row] = await db.insert(groundOperators).values(data).returning();
34
- return row;
35
- },
36
- async updateOperator(db, id, data) {
37
- const [row] = await db
38
- .update(groundOperators)
39
- .set({ ...data, updatedAt: new Date() })
40
- .where(eq(groundOperators.id, id))
41
- .returning();
42
- return row ?? null;
43
- },
44
- async deleteOperator(db, id) {
45
- const [row] = await db
46
- .delete(groundOperators)
47
- .where(eq(groundOperators.id, id))
48
- .returning({ id: groundOperators.id });
49
- return row ?? null;
50
- },
51
- async listVehicles(db, query) {
52
- const conditions = [];
53
- if (query.resourceId)
54
- conditions.push(eq(groundVehicles.resourceId, query.resourceId));
55
- if (query.operatorId)
56
- conditions.push(eq(groundVehicles.operatorId, query.operatorId));
57
- if (query.category)
58
- conditions.push(eq(groundVehicles.category, query.category));
59
- if (query.active !== undefined)
60
- conditions.push(eq(groundVehicles.active, query.active));
61
- const where = conditions.length > 0 ? and(...conditions) : undefined;
62
- return paginate(db
63
- .select()
64
- .from(groundVehicles)
65
- .where(where)
66
- .limit(query.limit)
67
- .offset(query.offset)
68
- .orderBy(asc(groundVehicles.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundVehicles).where(where), query.limit, query.offset);
69
- },
70
- async getVehicleById(db, id) {
71
- const [row] = await db.select().from(groundVehicles).where(eq(groundVehicles.id, id)).limit(1);
72
- return row ?? null;
73
- },
74
- async createVehicle(db, data) {
75
- const [row] = await db.insert(groundVehicles).values(data).returning();
76
- return row;
77
- },
78
- async updateVehicle(db, id, data) {
79
- const [row] = await db
80
- .update(groundVehicles)
81
- .set({ ...data, updatedAt: new Date() })
82
- .where(eq(groundVehicles.id, id))
83
- .returning();
84
- return row ?? null;
85
- },
86
- async deleteVehicle(db, id) {
87
- const [row] = await db
88
- .delete(groundVehicles)
89
- .where(eq(groundVehicles.id, id))
90
- .returning({ id: groundVehicles.id });
91
- return row ?? null;
92
- },
93
- async listDrivers(db, query) {
94
- const conditions = [];
95
- if (query.resourceId)
96
- conditions.push(eq(groundDrivers.resourceId, query.resourceId));
97
- if (query.operatorId)
98
- conditions.push(eq(groundDrivers.operatorId, query.operatorId));
99
- if (query.active !== undefined)
100
- conditions.push(eq(groundDrivers.active, query.active));
101
- const where = conditions.length > 0 ? and(...conditions) : undefined;
102
- return paginate(db
103
- .select()
104
- .from(groundDrivers)
105
- .where(where)
106
- .limit(query.limit)
107
- .offset(query.offset)
108
- .orderBy(asc(groundDrivers.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundDrivers).where(where), query.limit, query.offset);
109
- },
110
- async getDriverById(db, id) {
111
- const [row] = await db.select().from(groundDrivers).where(eq(groundDrivers.id, id)).limit(1);
112
- return row ?? null;
113
- },
114
- async createDriver(db, data) {
115
- const [row] = await db.insert(groundDrivers).values(data).returning();
116
- return row;
117
- },
118
- async updateDriver(db, id, data) {
119
- const [row] = await db
120
- .update(groundDrivers)
121
- .set({ ...data, updatedAt: new Date() })
122
- .where(eq(groundDrivers.id, id))
123
- .returning();
124
- return row ?? null;
125
- },
126
- async deleteDriver(db, id) {
127
- const [row] = await db
128
- .delete(groundDrivers)
129
- .where(eq(groundDrivers.id, id))
130
- .returning({ id: groundDrivers.id });
131
- return row ?? null;
132
- },
133
- async listTransferPreferences(db, query) {
134
- const conditions = [];
135
- if (query.bookingId) {
136
- conditions.push(eq(groundTransferPreferences.bookingId, query.bookingId));
137
- }
138
- if (query.bookingItemId) {
139
- conditions.push(eq(groundTransferPreferences.bookingItemId, query.bookingItemId));
140
- }
141
- if (query.serviceLevel) {
142
- conditions.push(eq(groundTransferPreferences.serviceLevel, query.serviceLevel));
143
- }
144
- const where = conditions.length > 0 ? and(...conditions) : undefined;
145
- return paginate(db
146
- .select()
147
- .from(groundTransferPreferences)
148
- .where(where)
149
- .limit(query.limit)
150
- .offset(query.offset)
151
- .orderBy(asc(groundTransferPreferences.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundTransferPreferences).where(where), query.limit, query.offset);
152
- },
153
- async getTransferPreferenceById(db, id) {
154
- const [row] = await db
155
- .select()
156
- .from(groundTransferPreferences)
157
- .where(eq(groundTransferPreferences.id, id))
158
- .limit(1);
159
- return row ?? null;
160
- },
161
- async createTransferPreference(db, data) {
162
- const [row] = await db.insert(groundTransferPreferences).values(data).returning();
163
- return row;
164
- },
165
- async updateTransferPreference(db, id, data) {
166
- const [row] = await db
167
- .update(groundTransferPreferences)
168
- .set({ ...data, updatedAt: new Date() })
169
- .where(eq(groundTransferPreferences.id, id))
170
- .returning();
171
- return row ?? null;
172
- },
173
- async deleteTransferPreference(db, id) {
174
- const [row] = await db
175
- .delete(groundTransferPreferences)
176
- .where(eq(groundTransferPreferences.id, id))
177
- .returning({ id: groundTransferPreferences.id });
178
- return row ?? null;
179
- },
180
- async listDispatches(db, query) {
181
- const conditions = [];
182
- if (query.transferPreferenceId) {
183
- conditions.push(eq(groundDispatches.transferPreferenceId, query.transferPreferenceId));
184
- }
185
- if (query.bookingId)
186
- conditions.push(eq(groundDispatches.bookingId, query.bookingId));
187
- if (query.bookingItemId)
188
- conditions.push(eq(groundDispatches.bookingItemId, query.bookingItemId));
189
- if (query.operatorId)
190
- conditions.push(eq(groundDispatches.operatorId, query.operatorId));
191
- if (query.vehicleId)
192
- conditions.push(eq(groundDispatches.vehicleId, query.vehicleId));
193
- if (query.driverId)
194
- conditions.push(eq(groundDispatches.driverId, query.driverId));
195
- if (query.status)
196
- conditions.push(eq(groundDispatches.status, query.status));
197
- if (query.serviceDate)
198
- conditions.push(eq(groundDispatches.serviceDate, query.serviceDate));
199
- const where = conditions.length > 0 ? and(...conditions) : undefined;
200
- return paginate(db
201
- .select()
202
- .from(groundDispatches)
203
- .where(where)
204
- .limit(query.limit)
205
- .offset(query.offset)
206
- .orderBy(asc(groundDispatches.serviceDate), asc(groundDispatches.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundDispatches).where(where), query.limit, query.offset);
207
- },
208
- async getDispatchById(db, id) {
209
- const [row] = await db
210
- .select()
211
- .from(groundDispatches)
212
- .where(eq(groundDispatches.id, id))
213
- .limit(1);
214
- return row ?? null;
215
- },
216
- async createDispatch(db, data) {
217
- const { scheduledPickupAt, scheduledDropoffAt, actualPickupAt, actualDropoffAt, ...rest } = data;
218
- const [row] = await db
219
- .insert(groundDispatches)
220
- .values({
221
- ...rest,
222
- scheduledPickupAt: toDateOrNull(scheduledPickupAt),
223
- scheduledDropoffAt: toDateOrNull(scheduledDropoffAt),
224
- actualPickupAt: toDateOrNull(actualPickupAt),
225
- actualDropoffAt: toDateOrNull(actualDropoffAt),
226
- })
227
- .returning();
228
- return row;
229
- },
230
- async updateDispatch(db, id, data) {
231
- const { scheduledPickupAt, scheduledDropoffAt, actualPickupAt, actualDropoffAt, ...rest } = data;
232
- const [row] = await db
233
- .update(groundDispatches)
234
- .set({
235
- ...rest,
236
- scheduledPickupAt: toDateOrNull(scheduledPickupAt),
237
- scheduledDropoffAt: toDateOrNull(scheduledDropoffAt),
238
- actualPickupAt: toDateOrNull(actualPickupAt),
239
- actualDropoffAt: toDateOrNull(actualDropoffAt),
240
- updatedAt: new Date(),
241
- })
242
- .where(eq(groundDispatches.id, id))
243
- .returning();
244
- return row ?? null;
245
- },
246
- async deleteDispatch(db, id) {
247
- const [row] = await db
248
- .delete(groundDispatches)
249
- .where(eq(groundDispatches.id, id))
250
- .returning({ id: groundDispatches.id });
251
- return row ?? null;
252
- },
253
- async listExecutionEvents(db, query) {
254
- const conditions = [];
255
- if (query.dispatchId)
256
- conditions.push(eq(groundExecutionEvents.dispatchId, query.dispatchId));
257
- if (query.eventType)
258
- conditions.push(eq(groundExecutionEvents.eventType, query.eventType));
259
- const where = conditions.length > 0 ? and(...conditions) : undefined;
260
- return paginate(db
261
- .select()
262
- .from(groundExecutionEvents)
263
- .where(where)
264
- .limit(query.limit)
265
- .offset(query.offset)
266
- .orderBy(asc(groundExecutionEvents.occurredAt), asc(groundExecutionEvents.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundExecutionEvents).where(where), query.limit, query.offset);
267
- },
268
- async getExecutionEventById(db, id) {
269
- const [row] = await db
270
- .select()
271
- .from(groundExecutionEvents)
272
- .where(eq(groundExecutionEvents.id, id))
273
- .limit(1);
274
- return row ?? null;
275
- },
276
- async createExecutionEvent(db, data) {
277
- const { occurredAt, ...rest } = data;
278
- const [row] = await db
279
- .insert(groundExecutionEvents)
280
- .values({
281
- ...rest,
282
- occurredAt: toDateOrNull(occurredAt) ?? new Date(),
283
- })
284
- .returning();
285
- return row;
286
- },
287
- async updateExecutionEvent(db, id, data) {
288
- const { occurredAt, ...rest } = data;
289
- const [row] = await db
290
- .update(groundExecutionEvents)
291
- .set({
292
- ...rest,
293
- occurredAt: occurredAt === undefined ? undefined : (toDateOrNull(occurredAt) ?? new Date()),
294
- })
295
- .where(eq(groundExecutionEvents.id, id))
296
- .returning();
297
- return row ?? null;
298
- },
299
- async deleteExecutionEvent(db, id) {
300
- const [row] = await db
301
- .delete(groundExecutionEvents)
302
- .where(eq(groundExecutionEvents.id, id))
303
- .returning({ id: groundExecutionEvents.id });
304
- return row ?? null;
305
- },
306
- async listDispatchAssignments(db, query) {
307
- const conditions = [];
308
- if (query.dispatchId)
309
- conditions.push(eq(groundDispatchAssignments.dispatchId, query.dispatchId));
310
- if (query.operatorId)
311
- conditions.push(eq(groundDispatchAssignments.operatorId, query.operatorId));
312
- if (query.vehicleId)
313
- conditions.push(eq(groundDispatchAssignments.vehicleId, query.vehicleId));
314
- if (query.driverId)
315
- conditions.push(eq(groundDispatchAssignments.driverId, query.driverId));
316
- if (query.assignmentSource)
317
- conditions.push(eq(groundDispatchAssignments.assignmentSource, query.assignmentSource));
318
- const where = conditions.length ? and(...conditions) : undefined;
319
- return paginate(db
320
- .select()
321
- .from(groundDispatchAssignments)
322
- .where(where)
323
- .limit(query.limit)
324
- .offset(query.offset)
325
- .orderBy(asc(groundDispatchAssignments.assignedAt)), db.select({ count: sql `count(*)::int` }).from(groundDispatchAssignments).where(where), query.limit, query.offset);
326
- },
327
- async getDispatchAssignmentById(db, id) {
328
- const [row] = await db
329
- .select()
330
- .from(groundDispatchAssignments)
331
- .where(eq(groundDispatchAssignments.id, id))
332
- .limit(1);
333
- return row ?? null;
334
- },
335
- async createDispatchAssignment(db, data) {
336
- const [row] = await db
337
- .insert(groundDispatchAssignments)
338
- .values({
339
- ...data,
340
- assignedAt: toDateOrNull(data.assignedAt) ?? new Date(),
341
- acceptedAt: toDateOrNull(data.acceptedAt),
342
- })
343
- .returning();
344
- return row;
345
- },
346
- async updateDispatchAssignment(db, id, data) {
347
- const [row] = await db
348
- .update(groundDispatchAssignments)
349
- .set({
350
- ...data,
351
- assignedAt: data.assignedAt ? new Date(data.assignedAt) : undefined,
352
- acceptedAt: data.acceptedAt ? new Date(data.acceptedAt) : undefined,
353
- updatedAt: new Date(),
354
- })
355
- .where(eq(groundDispatchAssignments.id, id))
356
- .returning();
357
- return row ?? null;
358
- },
359
- async deleteDispatchAssignment(db, id) {
360
- const [row] = await db
361
- .delete(groundDispatchAssignments)
362
- .where(eq(groundDispatchAssignments.id, id))
363
- .returning({ id: groundDispatchAssignments.id });
364
- return row ?? null;
365
- },
366
- async listDispatchLegs(db, query) {
367
- const conditions = [];
368
- if (query.dispatchId)
369
- conditions.push(eq(groundDispatchLegs.dispatchId, query.dispatchId));
370
- if (query.legType)
371
- conditions.push(eq(groundDispatchLegs.legType, query.legType));
372
- const where = conditions.length ? and(...conditions) : undefined;
373
- return paginate(db
374
- .select()
375
- .from(groundDispatchLegs)
376
- .where(where)
377
- .limit(query.limit)
378
- .offset(query.offset)
379
- .orderBy(asc(groundDispatchLegs.sequence)), db.select({ count: sql `count(*)::int` }).from(groundDispatchLegs).where(where), query.limit, query.offset);
380
- },
381
- async getDispatchLegById(db, id) {
382
- const [row] = await db
383
- .select()
384
- .from(groundDispatchLegs)
385
- .where(eq(groundDispatchLegs.id, id))
386
- .limit(1);
387
- return row ?? null;
388
- },
389
- async createDispatchLeg(db, data) {
390
- const [row] = await db
391
- .insert(groundDispatchLegs)
392
- .values({
393
- ...data,
394
- scheduledAt: toDateOrNull(data.scheduledAt),
395
- actualAt: toDateOrNull(data.actualAt),
396
- })
397
- .returning();
398
- return row;
399
- },
400
- async updateDispatchLeg(db, id, data) {
401
- const [row] = await db
402
- .update(groundDispatchLegs)
403
- .set({
404
- ...data,
405
- scheduledAt: toDateOrNull(data.scheduledAt),
406
- actualAt: toDateOrNull(data.actualAt),
407
- updatedAt: new Date(),
408
- })
409
- .where(eq(groundDispatchLegs.id, id))
410
- .returning();
411
- return row ?? null;
412
- },
413
- async deleteDispatchLeg(db, id) {
414
- const [row] = await db
415
- .delete(groundDispatchLegs)
416
- .where(eq(groundDispatchLegs.id, id))
417
- .returning({ id: groundDispatchLegs.id });
418
- return row ?? null;
419
- },
420
- async listDispatchPassengers(db, query) {
421
- const conditions = [];
422
- if (query.dispatchId)
423
- conditions.push(eq(groundDispatchPassengers.dispatchId, query.dispatchId));
424
- if (query.participantId)
425
- conditions.push(eq(groundDispatchPassengers.participantId, query.participantId));
426
- const where = conditions.length ? and(...conditions) : undefined;
427
- return paginate(db
428
- .select()
429
- .from(groundDispatchPassengers)
430
- .where(where)
431
- .limit(query.limit)
432
- .offset(query.offset)
433
- .orderBy(asc(groundDispatchPassengers.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundDispatchPassengers).where(where), query.limit, query.offset);
434
- },
435
- async getDispatchPassengerById(db, id) {
436
- const [row] = await db
437
- .select()
438
- .from(groundDispatchPassengers)
439
- .where(eq(groundDispatchPassengers.id, id))
440
- .limit(1);
441
- return row ?? null;
442
- },
443
- async createDispatchPassenger(db, data) {
444
- const [row] = await db.insert(groundDispatchPassengers).values(data).returning();
445
- return row;
446
- },
447
- async updateDispatchPassenger(db, id, data) {
448
- const [row] = await db
449
- .update(groundDispatchPassengers)
450
- .set({ ...data, updatedAt: new Date() })
451
- .where(eq(groundDispatchPassengers.id, id))
452
- .returning();
453
- return row ?? null;
454
- },
455
- async deleteDispatchPassenger(db, id) {
456
- const [row] = await db
457
- .delete(groundDispatchPassengers)
458
- .where(eq(groundDispatchPassengers.id, id))
459
- .returning({ id: groundDispatchPassengers.id });
460
- return row ?? null;
461
- },
462
- async listDriverShifts(db, query) {
463
- const conditions = [];
464
- if (query.driverId)
465
- conditions.push(eq(groundDriverShifts.driverId, query.driverId));
466
- if (query.operatorId)
467
- conditions.push(eq(groundDriverShifts.operatorId, query.operatorId));
468
- if (query.facilityId)
469
- conditions.push(eq(groundDriverShifts.facilityId, query.facilityId));
470
- if (query.status)
471
- conditions.push(eq(groundDriverShifts.status, query.status));
472
- const where = conditions.length ? and(...conditions) : undefined;
473
- return paginate(db
474
- .select()
475
- .from(groundDriverShifts)
476
- .where(where)
477
- .limit(query.limit)
478
- .offset(query.offset)
479
- .orderBy(asc(groundDriverShifts.startsAt)), db.select({ count: sql `count(*)::int` }).from(groundDriverShifts).where(where), query.limit, query.offset);
480
- },
481
- async getDriverShiftById(db, id) {
482
- const [row] = await db
483
- .select()
484
- .from(groundDriverShifts)
485
- .where(eq(groundDriverShifts.id, id))
486
- .limit(1);
487
- return row ?? null;
488
- },
489
- async createDriverShift(db, data) {
490
- const [row] = await db
491
- .insert(groundDriverShifts)
492
- .values({
493
- ...data,
494
- startsAt: new Date(data.startsAt),
495
- endsAt: new Date(data.endsAt),
496
- })
497
- .returning();
498
- return row;
499
- },
500
- async updateDriverShift(db, id, data) {
501
- const [row] = await db
502
- .update(groundDriverShifts)
503
- .set({
504
- ...data,
505
- startsAt: data.startsAt ? new Date(data.startsAt) : undefined,
506
- endsAt: data.endsAt ? new Date(data.endsAt) : undefined,
507
- updatedAt: new Date(),
508
- })
509
- .where(eq(groundDriverShifts.id, id))
510
- .returning();
511
- return row ?? null;
512
- },
513
- async deleteDriverShift(db, id) {
514
- const [row] = await db
515
- .delete(groundDriverShifts)
516
- .where(eq(groundDriverShifts.id, id))
517
- .returning({ id: groundDriverShifts.id });
518
- return row ?? null;
519
- },
520
- async listServiceIncidents(db, query) {
521
- const conditions = [];
522
- if (query.dispatchId)
523
- conditions.push(eq(groundServiceIncidents.dispatchId, query.dispatchId));
524
- if (query.severity)
525
- conditions.push(eq(groundServiceIncidents.severity, query.severity));
526
- if (query.resolutionStatus)
527
- conditions.push(eq(groundServiceIncidents.resolutionStatus, query.resolutionStatus));
528
- const where = conditions.length ? and(...conditions) : undefined;
529
- return paginate(db
530
- .select()
531
- .from(groundServiceIncidents)
532
- .where(where)
533
- .limit(query.limit)
534
- .offset(query.offset)
535
- .orderBy(desc(groundServiceIncidents.openedAt)), db.select({ count: sql `count(*)::int` }).from(groundServiceIncidents).where(where), query.limit, query.offset);
536
- },
537
- async getServiceIncidentById(db, id) {
538
- const [row] = await db
539
- .select()
540
- .from(groundServiceIncidents)
541
- .where(eq(groundServiceIncidents.id, id))
542
- .limit(1);
543
- return row ?? null;
544
- },
545
- async createServiceIncident(db, data) {
546
- const [row] = await db
547
- .insert(groundServiceIncidents)
548
- .values({
549
- ...data,
550
- openedAt: toDateOrNull(data.openedAt) ?? new Date(),
551
- resolvedAt: toDateOrNull(data.resolvedAt),
552
- })
553
- .returning();
554
- return row;
555
- },
556
- async updateServiceIncident(db, id, data) {
557
- const [row] = await db
558
- .update(groundServiceIncidents)
559
- .set({
560
- ...data,
561
- openedAt: data.openedAt ? new Date(data.openedAt) : undefined,
562
- resolvedAt: data.resolvedAt ? new Date(data.resolvedAt) : undefined,
563
- updatedAt: new Date(),
564
- })
565
- .where(eq(groundServiceIncidents.id, id))
566
- .returning();
567
- return row ?? null;
568
- },
569
- async deleteServiceIncident(db, id) {
570
- const [row] = await db
571
- .delete(groundServiceIncidents)
572
- .where(eq(groundServiceIncidents.id, id))
573
- .returning({ id: groundServiceIncidents.id });
574
- return row ?? null;
575
- },
576
- async listDispatchCheckpoints(db, query) {
577
- const conditions = [];
578
- if (query.dispatchId)
579
- conditions.push(eq(groundDispatchCheckpoints.dispatchId, query.dispatchId));
580
- if (query.status)
581
- conditions.push(eq(groundDispatchCheckpoints.status, query.status));
582
- const where = conditions.length ? and(...conditions) : undefined;
583
- return paginate(db
584
- .select()
585
- .from(groundDispatchCheckpoints)
586
- .where(where)
587
- .limit(query.limit)
588
- .offset(query.offset)
589
- .orderBy(asc(groundDispatchCheckpoints.sequence)), db.select({ count: sql `count(*)::int` }).from(groundDispatchCheckpoints).where(where), query.limit, query.offset);
590
- },
591
- async getDispatchCheckpointById(db, id) {
592
- const [row] = await db
593
- .select()
594
- .from(groundDispatchCheckpoints)
595
- .where(eq(groundDispatchCheckpoints.id, id))
596
- .limit(1);
597
- return row ?? null;
598
- },
599
- async createDispatchCheckpoint(db, data) {
600
- const [row] = await db
601
- .insert(groundDispatchCheckpoints)
602
- .values({
603
- ...data,
604
- plannedAt: toDateOrNull(data.plannedAt),
605
- actualAt: toDateOrNull(data.actualAt),
606
- })
607
- .returning();
608
- return row;
609
- },
610
- async updateDispatchCheckpoint(db, id, data) {
611
- const [row] = await db
612
- .update(groundDispatchCheckpoints)
613
- .set({
614
- ...data,
615
- plannedAt: toDateOrNull(data.plannedAt),
616
- actualAt: toDateOrNull(data.actualAt),
617
- updatedAt: new Date(),
618
- })
619
- .where(eq(groundDispatchCheckpoints.id, id))
620
- .returning();
621
- return row ?? null;
622
- },
623
- async deleteDispatchCheckpoint(db, id) {
624
- const [row] = await db
625
- .delete(groundDispatchCheckpoints)
626
- .where(eq(groundDispatchCheckpoints.id, id))
627
- .returning({ id: groundDispatchCheckpoints.id });
628
- return row ?? null;
629
- },
5
+ listOperators,
6
+ getOperatorById,
7
+ createOperator,
8
+ updateOperator,
9
+ deleteOperator,
10
+ listVehicles,
11
+ getVehicleById,
12
+ createVehicle,
13
+ updateVehicle,
14
+ deleteVehicle,
15
+ listDrivers,
16
+ getDriverById,
17
+ createDriver,
18
+ updateDriver,
19
+ deleteDriver,
20
+ listTransferPreferences,
21
+ getTransferPreferenceById,
22
+ createTransferPreference,
23
+ updateTransferPreference,
24
+ deleteTransferPreference,
25
+ listDispatches,
26
+ getDispatchById,
27
+ createDispatch,
28
+ updateDispatch,
29
+ deleteDispatch,
30
+ listExecutionEvents,
31
+ getExecutionEventById,
32
+ createExecutionEvent,
33
+ updateExecutionEvent,
34
+ deleteExecutionEvent,
35
+ listDispatchAssignments,
36
+ getDispatchAssignmentById,
37
+ createDispatchAssignment,
38
+ updateDispatchAssignment,
39
+ deleteDispatchAssignment,
40
+ listDispatchLegs,
41
+ getDispatchLegById,
42
+ createDispatchLeg,
43
+ updateDispatchLeg,
44
+ deleteDispatchLeg,
45
+ listDispatchPassengers,
46
+ getDispatchPassengerById,
47
+ createDispatchPassenger,
48
+ updateDispatchPassenger,
49
+ deleteDispatchPassenger,
50
+ listDriverShifts,
51
+ getDriverShiftById,
52
+ createDriverShift,
53
+ updateDriverShift,
54
+ deleteDriverShift,
55
+ listServiceIncidents,
56
+ getServiceIncidentById,
57
+ createServiceIncident,
58
+ updateServiceIncident,
59
+ deleteServiceIncident,
60
+ listDispatchCheckpoints,
61
+ getDispatchCheckpointById,
62
+ createDispatchCheckpoint,
63
+ updateDispatchCheckpoint,
64
+ deleteDispatchCheckpoint,
630
65
  };