@voyantjs/ground 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":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,yBAAyB,kHAUpC,CAAA;AAEF,eAAO,MAAM,sBAAsB,2GAOjC,CAAA;AAEF,eAAO,MAAM,sBAAsB,wFAMjC,CAAA;AAEF,eAAO,MAAM,wBAAwB,mJAUnC,CAAA;AAEF,eAAO,MAAM,4BAA4B,6KAUvC,CAAA;AAEF,eAAO,MAAM,0BAA0B,uEAIrC,CAAA;AAEF,eAAO,MAAM,yBAAyB,iFAKpC,CAAA;AAEF,eAAO,MAAM,2BAA2B,uGAMtC,CAAA;AAEF,eAAO,MAAM,0BAA0B,uEAIrC,CAAA;AAEF,eAAO,MAAM,kCAAkC,sFAK7C,CAAA;AAEF,eAAO,MAAM,0BAA0B,qFAKrC,CAAA;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkB3B,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2B1B,CAAA;AAED,eAAO,MAAM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;;;;EAoB9C,CAAA;AAED,eAAO,MAAM,2BAA2B;;;;EAarC,CAAA;AAEH,eAAO,MAAM,iCAAiC;;EAK3C,CAAA;AAEH,eAAO,MAAM,2BAA2B;;;;EAarC,CAAA;AAEH,eAAO,MAAM,+BAA+B;;EAKzC,CAAA;AAEH,eAAO,MAAM,kCAAkC;;;;EAgB9C,CAAA"}
package/dist/schema.js ADDED
@@ -0,0 +1,513 @@
1
+ import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
2
+ import { facilities } from "@voyantjs/facilities/schema";
3
+ import { identityAddresses } from "@voyantjs/identity/schema";
4
+ import { relations } from "drizzle-orm";
5
+ import { boolean, date, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
6
+ export const groundVehicleCategoryEnum = pgEnum("ground_vehicle_category", [
7
+ "car",
8
+ "sedan",
9
+ "suv",
10
+ "van",
11
+ "minibus",
12
+ "bus",
13
+ "boat",
14
+ "train",
15
+ "other",
16
+ ]);
17
+ export const groundVehicleClassEnum = pgEnum("ground_vehicle_class", [
18
+ "economy",
19
+ "standard",
20
+ "premium",
21
+ "luxury",
22
+ "accessible",
23
+ "other",
24
+ ]);
25
+ export const groundServiceLevelEnum = pgEnum("ground_service_level", [
26
+ "private",
27
+ "shared",
28
+ "vip",
29
+ "shuttle",
30
+ "other",
31
+ ]);
32
+ export const groundDispatchStatusEnum = pgEnum("ground_dispatch_status", [
33
+ "draft",
34
+ "scheduled",
35
+ "assigned",
36
+ "en_route",
37
+ "arrived",
38
+ "picked_up",
39
+ "completed",
40
+ "cancelled",
41
+ "no_show",
42
+ ]);
43
+ export const groundExecutionEventTypeEnum = pgEnum("ground_execution_event_type", [
44
+ "scheduled",
45
+ "assigned",
46
+ "driver_en_route",
47
+ "driver_arrived",
48
+ "pickup_completed",
49
+ "dropoff_completed",
50
+ "cancelled",
51
+ "issue",
52
+ "note",
53
+ ]);
54
+ export const groundAssignmentSourceEnum = pgEnum("ground_assignment_source", [
55
+ "manual",
56
+ "suggested",
57
+ "auto",
58
+ ]);
59
+ export const groundDispatchLegTypeEnum = pgEnum("ground_dispatch_leg_type", [
60
+ "pickup",
61
+ "stop",
62
+ "dropoff",
63
+ "deadhead",
64
+ ]);
65
+ export const groundDriverShiftStatusEnum = pgEnum("ground_driver_shift_status", [
66
+ "scheduled",
67
+ "available",
68
+ "on_duty",
69
+ "completed",
70
+ "cancelled",
71
+ ]);
72
+ export const groundIncidentSeverityEnum = pgEnum("ground_incident_severity", [
73
+ "info",
74
+ "warning",
75
+ "critical",
76
+ ]);
77
+ export const groundIncidentResolutionStatusEnum = pgEnum("ground_incident_resolution_status", [
78
+ "open",
79
+ "mitigated",
80
+ "resolved",
81
+ "cancelled",
82
+ ]);
83
+ export const groundCheckpointStatusEnum = pgEnum("ground_checkpoint_status", [
84
+ "pending",
85
+ "reached",
86
+ "missed",
87
+ "cancelled",
88
+ ]);
89
+ export const groundOperators = pgTable("ground_operators", {
90
+ id: typeId("ground_operators"),
91
+ supplierId: text("supplier_id"),
92
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
93
+ name: text("name").notNull(),
94
+ code: text("code"),
95
+ active: boolean("active").notNull().default(true),
96
+ notes: text("notes"),
97
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
98
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
99
+ }, (table) => [
100
+ index("idx_ground_operators_supplier").on(table.supplierId),
101
+ index("idx_ground_operators_facility").on(table.facilityId),
102
+ index("idx_ground_operators_active").on(table.active),
103
+ ]);
104
+ export const groundVehicles = pgTable("ground_vehicles", {
105
+ id: typeId("ground_vehicles"),
106
+ resourceId: text("resource_id").notNull(),
107
+ operatorId: typeIdRef("operator_id").references(() => groundOperators.id, {
108
+ onDelete: "set null",
109
+ }),
110
+ category: groundVehicleCategoryEnum("category").notNull().default("other"),
111
+ vehicleClass: groundVehicleClassEnum("vehicle_class").notNull().default("standard"),
112
+ passengerCapacity: integer("passenger_capacity"),
113
+ checkedBagCapacity: integer("checked_bag_capacity"),
114
+ carryOnCapacity: integer("carry_on_capacity"),
115
+ wheelchairCapacity: integer("wheelchair_capacity"),
116
+ childSeatCapacity: integer("child_seat_capacity"),
117
+ isAccessible: boolean("is_accessible").notNull().default(false),
118
+ active: boolean("active").notNull().default(true),
119
+ notes: text("notes"),
120
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
121
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
122
+ }, (table) => [
123
+ uniqueIndex("uidx_ground_vehicles_resource").on(table.resourceId),
124
+ index("idx_ground_vehicles_operator").on(table.operatorId),
125
+ index("idx_ground_vehicles_category").on(table.category),
126
+ index("idx_ground_vehicles_active").on(table.active),
127
+ ]);
128
+ export const groundDrivers = pgTable("ground_drivers", {
129
+ id: typeId("ground_drivers"),
130
+ resourceId: text("resource_id").notNull(),
131
+ operatorId: typeIdRef("operator_id").references(() => groundOperators.id, {
132
+ onDelete: "set null",
133
+ }),
134
+ licenseNumber: text("license_number"),
135
+ spokenLanguages: jsonb("spoken_languages").$type().notNull().default([]),
136
+ isGuide: boolean("is_guide").notNull().default(false),
137
+ isMeetAndGreetCapable: boolean("is_meet_and_greet_capable").notNull().default(false),
138
+ active: boolean("active").notNull().default(true),
139
+ notes: text("notes"),
140
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
141
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
142
+ }, (table) => [
143
+ uniqueIndex("uidx_ground_drivers_resource").on(table.resourceId),
144
+ index("idx_ground_drivers_operator").on(table.operatorId),
145
+ index("idx_ground_drivers_active").on(table.active),
146
+ ]);
147
+ export const groundTransferPreferences = pgTable("ground_transfer_preferences", {
148
+ id: typeId("ground_transfer_preferences"),
149
+ bookingId: text("booking_id").notNull(),
150
+ bookingItemId: text("booking_item_id"),
151
+ pickupFacilityId: typeIdRef("pickup_facility_id").references(() => facilities.id, {
152
+ onDelete: "set null",
153
+ }),
154
+ dropoffFacilityId: typeIdRef("dropoff_facility_id").references(() => facilities.id, {
155
+ onDelete: "set null",
156
+ }),
157
+ pickupAddressId: typeIdRef("pickup_address_id").references(() => identityAddresses.id, {
158
+ onDelete: "set null",
159
+ }),
160
+ dropoffAddressId: typeIdRef("dropoff_address_id").references(() => identityAddresses.id, {
161
+ onDelete: "set null",
162
+ }),
163
+ requestedVehicleCategory: groundVehicleCategoryEnum("requested_vehicle_category"),
164
+ requestedVehicleClass: groundVehicleClassEnum("requested_vehicle_class"),
165
+ serviceLevel: groundServiceLevelEnum("service_level").notNull().default("private"),
166
+ passengerCount: integer("passenger_count"),
167
+ checkedBags: integer("checked_bags"),
168
+ carryOnBags: integer("carry_on_bags"),
169
+ wheelchairCount: integer("wheelchair_count"),
170
+ childSeatCount: integer("child_seat_count"),
171
+ driverLanguage: text("driver_language"),
172
+ meetAndGreet: boolean("meet_and_greet").notNull().default(false),
173
+ accessibilityNotes: text("accessibility_notes"),
174
+ pickupNotes: text("pickup_notes"),
175
+ dropoffNotes: text("dropoff_notes"),
176
+ notes: text("notes"),
177
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
178
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
179
+ }, (table) => [
180
+ index("idx_ground_transfer_preferences_booking").on(table.bookingId),
181
+ index("idx_ground_transfer_preferences_booking_item").on(table.bookingItemId),
182
+ index("idx_ground_transfer_preferences_service_level").on(table.serviceLevel),
183
+ ]);
184
+ export const groundDispatches = pgTable("ground_dispatches", {
185
+ id: typeId("ground_dispatches"),
186
+ transferPreferenceId: typeIdRef("transfer_preference_id")
187
+ .notNull()
188
+ .references(() => groundTransferPreferences.id, { onDelete: "cascade" }),
189
+ bookingId: text("booking_id").notNull(),
190
+ bookingItemId: text("booking_item_id"),
191
+ operatorId: typeIdRef("operator_id").references(() => groundOperators.id, {
192
+ onDelete: "set null",
193
+ }),
194
+ vehicleId: typeIdRef("vehicle_id").references(() => groundVehicles.id, {
195
+ onDelete: "set null",
196
+ }),
197
+ driverId: typeIdRef("driver_id").references(() => groundDrivers.id, { onDelete: "set null" }),
198
+ serviceDate: date("service_date"),
199
+ scheduledPickupAt: timestamp("scheduled_pickup_at", { withTimezone: true }),
200
+ scheduledDropoffAt: timestamp("scheduled_dropoff_at", { withTimezone: true }),
201
+ actualPickupAt: timestamp("actual_pickup_at", { withTimezone: true }),
202
+ actualDropoffAt: timestamp("actual_dropoff_at", { withTimezone: true }),
203
+ status: groundDispatchStatusEnum("status").notNull().default("draft"),
204
+ passengerCount: integer("passenger_count"),
205
+ checkedBags: integer("checked_bags"),
206
+ carryOnBags: integer("carry_on_bags"),
207
+ notes: text("notes"),
208
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
209
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
210
+ }, (table) => [
211
+ index("idx_ground_dispatches_preference").on(table.transferPreferenceId),
212
+ index("idx_ground_dispatches_booking").on(table.bookingId),
213
+ index("idx_ground_dispatches_booking_item").on(table.bookingItemId),
214
+ index("idx_ground_dispatches_operator").on(table.operatorId),
215
+ index("idx_ground_dispatches_vehicle").on(table.vehicleId),
216
+ index("idx_ground_dispatches_driver").on(table.driverId),
217
+ index("idx_ground_dispatches_status").on(table.status),
218
+ index("idx_ground_dispatches_service_date").on(table.serviceDate),
219
+ ]);
220
+ export const groundExecutionEvents = pgTable("ground_execution_events", {
221
+ id: typeId("ground_execution_events"),
222
+ dispatchId: typeIdRef("dispatch_id")
223
+ .notNull()
224
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
225
+ eventType: groundExecutionEventTypeEnum("event_type").notNull().default("note"),
226
+ occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull().defaultNow(),
227
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
228
+ addressId: typeIdRef("address_id").references(() => identityAddresses.id, {
229
+ onDelete: "set null",
230
+ }),
231
+ notes: text("notes"),
232
+ metadata: jsonb("metadata").$type(),
233
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
234
+ }, (table) => [
235
+ index("idx_ground_execution_events_dispatch").on(table.dispatchId),
236
+ index("idx_ground_execution_events_type").on(table.eventType),
237
+ index("idx_ground_execution_events_occurred_at").on(table.occurredAt),
238
+ ]);
239
+ export const groundDispatchAssignments = pgTable("ground_dispatch_assignments", {
240
+ id: typeId("ground_dispatch_assignments"),
241
+ dispatchId: typeIdRef("dispatch_id")
242
+ .notNull()
243
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
244
+ operatorId: typeIdRef("operator_id").references(() => groundOperators.id, {
245
+ onDelete: "set null",
246
+ }),
247
+ vehicleId: typeIdRef("vehicle_id").references(() => groundVehicles.id, {
248
+ onDelete: "set null",
249
+ }),
250
+ driverId: typeIdRef("driver_id").references(() => groundDrivers.id, { onDelete: "set null" }),
251
+ assignmentSource: groundAssignmentSourceEnum("assignment_source").notNull().default("manual"),
252
+ assignedAt: timestamp("assigned_at", { withTimezone: true }).notNull().defaultNow(),
253
+ acceptedAt: timestamp("accepted_at", { withTimezone: true }),
254
+ notes: text("notes"),
255
+ metadata: jsonb("metadata").$type(),
256
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
257
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
258
+ }, (table) => [
259
+ index("idx_ground_dispatch_assignments_dispatch").on(table.dispatchId),
260
+ index("idx_ground_dispatch_assignments_operator").on(table.operatorId),
261
+ index("idx_ground_dispatch_assignments_vehicle").on(table.vehicleId),
262
+ index("idx_ground_dispatch_assignments_driver").on(table.driverId),
263
+ index("idx_ground_dispatch_assignments_source").on(table.assignmentSource),
264
+ ]);
265
+ export const groundDispatchLegs = pgTable("ground_dispatch_legs", {
266
+ id: typeId("ground_dispatch_legs"),
267
+ dispatchId: typeIdRef("dispatch_id")
268
+ .notNull()
269
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
270
+ sequence: integer("sequence").notNull().default(0),
271
+ legType: groundDispatchLegTypeEnum("leg_type").notNull().default("pickup"),
272
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
273
+ addressId: typeIdRef("address_id").references(() => identityAddresses.id, {
274
+ onDelete: "set null",
275
+ }),
276
+ scheduledAt: timestamp("scheduled_at", { withTimezone: true }),
277
+ actualAt: timestamp("actual_at", { withTimezone: true }),
278
+ notes: text("notes"),
279
+ metadata: jsonb("metadata").$type(),
280
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
281
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
282
+ }, (table) => [
283
+ index("idx_ground_dispatch_legs_dispatch").on(table.dispatchId),
284
+ index("idx_ground_dispatch_legs_sequence").on(table.sequence),
285
+ index("idx_ground_dispatch_legs_type").on(table.legType),
286
+ ]);
287
+ export const groundDispatchPassengers = pgTable("ground_dispatch_passengers", {
288
+ id: typeId("ground_dispatch_passengers"),
289
+ dispatchId: typeIdRef("dispatch_id")
290
+ .notNull()
291
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
292
+ participantId: text("participant_id"),
293
+ displayName: text("display_name"),
294
+ seatLabel: text("seat_label"),
295
+ notes: text("notes"),
296
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
297
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
298
+ }, (table) => [
299
+ index("idx_ground_dispatch_passengers_dispatch").on(table.dispatchId),
300
+ index("idx_ground_dispatch_passengers_participant").on(table.participantId),
301
+ ]);
302
+ export const groundDriverShifts = pgTable("ground_driver_shifts", {
303
+ id: typeId("ground_driver_shifts"),
304
+ driverId: typeIdRef("driver_id")
305
+ .notNull()
306
+ .references(() => groundDrivers.id, { onDelete: "cascade" }),
307
+ operatorId: typeIdRef("operator_id").references(() => groundOperators.id, {
308
+ onDelete: "set null",
309
+ }),
310
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
311
+ startsAt: timestamp("starts_at", { withTimezone: true }).notNull(),
312
+ endsAt: timestamp("ends_at", { withTimezone: true }).notNull(),
313
+ status: groundDriverShiftStatusEnum("status").notNull().default("scheduled"),
314
+ notes: text("notes"),
315
+ metadata: jsonb("metadata").$type(),
316
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
317
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
318
+ }, (table) => [
319
+ index("idx_ground_driver_shifts_driver").on(table.driverId),
320
+ index("idx_ground_driver_shifts_operator").on(table.operatorId),
321
+ index("idx_ground_driver_shifts_facility").on(table.facilityId),
322
+ index("idx_ground_driver_shifts_status").on(table.status),
323
+ ]);
324
+ export const groundServiceIncidents = pgTable("ground_service_incidents", {
325
+ id: typeId("ground_service_incidents"),
326
+ dispatchId: typeIdRef("dispatch_id")
327
+ .notNull()
328
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
329
+ severity: groundIncidentSeverityEnum("severity").notNull().default("warning"),
330
+ incidentType: text("incident_type").notNull(),
331
+ resolutionStatus: groundIncidentResolutionStatusEnum("resolution_status")
332
+ .notNull()
333
+ .default("open"),
334
+ openedAt: timestamp("opened_at", { withTimezone: true }).notNull().defaultNow(),
335
+ resolvedAt: timestamp("resolved_at", { withTimezone: true }),
336
+ notes: text("notes"),
337
+ metadata: jsonb("metadata").$type(),
338
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
339
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
340
+ }, (table) => [
341
+ index("idx_ground_service_incidents_dispatch").on(table.dispatchId),
342
+ index("idx_ground_service_incidents_severity").on(table.severity),
343
+ index("idx_ground_service_incidents_resolution").on(table.resolutionStatus),
344
+ ]);
345
+ export const groundDispatchCheckpoints = pgTable("ground_dispatch_checkpoints", {
346
+ id: typeId("ground_dispatch_checkpoints"),
347
+ dispatchId: typeIdRef("dispatch_id")
348
+ .notNull()
349
+ .references(() => groundDispatches.id, { onDelete: "cascade" }),
350
+ sequence: integer("sequence").notNull().default(0),
351
+ checkpointType: text("checkpoint_type").notNull(),
352
+ status: groundCheckpointStatusEnum("status").notNull().default("pending"),
353
+ plannedAt: timestamp("planned_at", { withTimezone: true }),
354
+ actualAt: timestamp("actual_at", { withTimezone: true }),
355
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
356
+ addressId: typeIdRef("address_id").references(() => identityAddresses.id, {
357
+ onDelete: "set null",
358
+ }),
359
+ notes: text("notes"),
360
+ metadata: jsonb("metadata").$type(),
361
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
362
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
363
+ }, (table) => [
364
+ index("idx_ground_dispatch_checkpoints_dispatch").on(table.dispatchId),
365
+ index("idx_ground_dispatch_checkpoints_sequence").on(table.sequence),
366
+ index("idx_ground_dispatch_checkpoints_status").on(table.status),
367
+ ]);
368
+ export const groundOperatorsRelations = relations(groundOperators, ({ one, many }) => ({
369
+ facility: one(facilities, { fields: [groundOperators.facilityId], references: [facilities.id] }),
370
+ vehicles: many(groundVehicles),
371
+ drivers: many(groundDrivers),
372
+ }));
373
+ export const groundVehiclesRelations = relations(groundVehicles, ({ one }) => ({
374
+ operator: one(groundOperators, {
375
+ fields: [groundVehicles.operatorId],
376
+ references: [groundOperators.id],
377
+ }),
378
+ }));
379
+ export const groundDriversRelations = relations(groundDrivers, ({ one }) => ({
380
+ operator: one(groundOperators, {
381
+ fields: [groundDrivers.operatorId],
382
+ references: [groundOperators.id],
383
+ }),
384
+ }));
385
+ export const groundTransferPreferencesRelations = relations(groundTransferPreferences, ({ one, many }) => ({
386
+ pickupFacility: one(facilities, {
387
+ fields: [groundTransferPreferences.pickupFacilityId],
388
+ references: [facilities.id],
389
+ }),
390
+ dropoffFacility: one(facilities, {
391
+ fields: [groundTransferPreferences.dropoffFacilityId],
392
+ references: [facilities.id],
393
+ }),
394
+ pickupAddress: one(identityAddresses, {
395
+ fields: [groundTransferPreferences.pickupAddressId],
396
+ references: [identityAddresses.id],
397
+ }),
398
+ dropoffAddress: one(identityAddresses, {
399
+ fields: [groundTransferPreferences.dropoffAddressId],
400
+ references: [identityAddresses.id],
401
+ }),
402
+ dispatches: many(groundDispatches),
403
+ }));
404
+ export const groundDispatchesRelations = relations(groundDispatches, ({ one, many }) => ({
405
+ transferPreference: one(groundTransferPreferences, {
406
+ fields: [groundDispatches.transferPreferenceId],
407
+ references: [groundTransferPreferences.id],
408
+ }),
409
+ operator: one(groundOperators, {
410
+ fields: [groundDispatches.operatorId],
411
+ references: [groundOperators.id],
412
+ }),
413
+ vehicle: one(groundVehicles, {
414
+ fields: [groundDispatches.vehicleId],
415
+ references: [groundVehicles.id],
416
+ }),
417
+ driver: one(groundDrivers, {
418
+ fields: [groundDispatches.driverId],
419
+ references: [groundDrivers.id],
420
+ }),
421
+ executionEvents: many(groundExecutionEvents),
422
+ assignments: many(groundDispatchAssignments),
423
+ legs: many(groundDispatchLegs),
424
+ passengers: many(groundDispatchPassengers),
425
+ incidents: many(groundServiceIncidents),
426
+ checkpoints: many(groundDispatchCheckpoints),
427
+ }));
428
+ export const groundExecutionEventsRelations = relations(groundExecutionEvents, ({ one }) => ({
429
+ dispatch: one(groundDispatches, {
430
+ fields: [groundExecutionEvents.dispatchId],
431
+ references: [groundDispatches.id],
432
+ }),
433
+ facility: one(facilities, {
434
+ fields: [groundExecutionEvents.facilityId],
435
+ references: [facilities.id],
436
+ }),
437
+ address: one(identityAddresses, {
438
+ fields: [groundExecutionEvents.addressId],
439
+ references: [identityAddresses.id],
440
+ }),
441
+ }));
442
+ export const groundDispatchAssignmentsRelations = relations(groundDispatchAssignments, ({ one }) => ({
443
+ dispatch: one(groundDispatches, {
444
+ fields: [groundDispatchAssignments.dispatchId],
445
+ references: [groundDispatches.id],
446
+ }),
447
+ operator: one(groundOperators, {
448
+ fields: [groundDispatchAssignments.operatorId],
449
+ references: [groundOperators.id],
450
+ }),
451
+ vehicle: one(groundVehicles, {
452
+ fields: [groundDispatchAssignments.vehicleId],
453
+ references: [groundVehicles.id],
454
+ }),
455
+ driver: one(groundDrivers, {
456
+ fields: [groundDispatchAssignments.driverId],
457
+ references: [groundDrivers.id],
458
+ }),
459
+ }));
460
+ export const groundDispatchLegsRelations = relations(groundDispatchLegs, ({ one }) => ({
461
+ dispatch: one(groundDispatches, {
462
+ fields: [groundDispatchLegs.dispatchId],
463
+ references: [groundDispatches.id],
464
+ }),
465
+ facility: one(facilities, {
466
+ fields: [groundDispatchLegs.facilityId],
467
+ references: [facilities.id],
468
+ }),
469
+ address: one(identityAddresses, {
470
+ fields: [groundDispatchLegs.addressId],
471
+ references: [identityAddresses.id],
472
+ }),
473
+ }));
474
+ export const groundDispatchPassengersRelations = relations(groundDispatchPassengers, ({ one }) => ({
475
+ dispatch: one(groundDispatches, {
476
+ fields: [groundDispatchPassengers.dispatchId],
477
+ references: [groundDispatches.id],
478
+ }),
479
+ }));
480
+ export const groundDriverShiftsRelations = relations(groundDriverShifts, ({ one }) => ({
481
+ driver: one(groundDrivers, {
482
+ fields: [groundDriverShifts.driverId],
483
+ references: [groundDrivers.id],
484
+ }),
485
+ operator: one(groundOperators, {
486
+ fields: [groundDriverShifts.operatorId],
487
+ references: [groundOperators.id],
488
+ }),
489
+ facility: one(facilities, {
490
+ fields: [groundDriverShifts.facilityId],
491
+ references: [facilities.id],
492
+ }),
493
+ }));
494
+ export const groundServiceIncidentsRelations = relations(groundServiceIncidents, ({ one }) => ({
495
+ dispatch: one(groundDispatches, {
496
+ fields: [groundServiceIncidents.dispatchId],
497
+ references: [groundDispatches.id],
498
+ }),
499
+ }));
500
+ export const groundDispatchCheckpointsRelations = relations(groundDispatchCheckpoints, ({ one }) => ({
501
+ dispatch: one(groundDispatches, {
502
+ fields: [groundDispatchCheckpoints.dispatchId],
503
+ references: [groundDispatches.id],
504
+ }),
505
+ facility: one(facilities, {
506
+ fields: [groundDispatchCheckpoints.facilityId],
507
+ references: [facilities.id],
508
+ }),
509
+ address: one(identityAddresses, {
510
+ fields: [groundDispatchCheckpoints.addressId],
511
+ references: [identityAddresses.id],
512
+ }),
513
+ }));