@voyantjs/suppliers 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":"AAeA,eAAO,MAAM,gBAAgB,sHAQ3B,CAAA;AAEF,eAAO,MAAM,kBAAkB,yEAA+D,CAAA;AAE9F,eAAO,MAAM,eAAe,6GAO1B,CAAA;AAEF,eAAO,MAAM,YAAY,uGAMvB,CAAA;AAEF,eAAO,MAAM,0BAA0B,sFAKrC,CAAA;AAIF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BrB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,YAAY,CAAA;AACpD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,YAAY,CAAA;AAIvD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B5B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAA;AAClE,MAAM,MAAM,kBAAkB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAA;AAIrE,eAAO,MAAM,aAAa;;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G,OAAO,iBAAiB,CAAC,YAAY,CAAA;AACpE,MAAM,MAAM,mBAAmB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAA;AAIvE,eAAO,MAAM,kBAAkB;;;;;;EAS5B,CAAA;AAEH,eAAO,MAAM,yBAAyB;;;;EAOnC,CAAA;AAEH,eAAO,MAAM,sBAAsB;;EAKhC,CAAA;AAEH,eAAO,MAAM,sBAAsB;;EAEhC,CAAA;AAEH,eAAO,MAAM,6BAA6B;;EAKvC,CAAA;AAEH,eAAO,MAAM,0BAA0B;;EAKpC,CAAA"}
package/dist/schema.js ADDED
@@ -0,0 +1,186 @@
1
+ import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
2
+ import { facilities } from "@voyantjs/facilities/schema";
3
+ import { relations } from "drizzle-orm";
4
+ import { boolean, date, index, integer, jsonb, pgEnum, pgTable, text, timestamp, } from "drizzle-orm/pg-core";
5
+ export const supplierTypeEnum = pgEnum("supplier_type", [
6
+ "hotel",
7
+ "transfer",
8
+ "guide",
9
+ "experience",
10
+ "airline",
11
+ "restaurant",
12
+ "other",
13
+ ]);
14
+ export const supplierStatusEnum = pgEnum("supplier_status", ["active", "inactive", "pending"]);
15
+ export const serviceTypeEnum = pgEnum("service_type", [
16
+ "accommodation",
17
+ "transfer",
18
+ "experience",
19
+ "guide",
20
+ "meal",
21
+ "other",
22
+ ]);
23
+ export const rateUnitEnum = pgEnum("rate_unit", [
24
+ "per_person",
25
+ "per_group",
26
+ "per_night",
27
+ "per_vehicle",
28
+ "flat",
29
+ ]);
30
+ export const supplierContractStatusEnum = pgEnum("supplier_contract_status", [
31
+ "active",
32
+ "expired",
33
+ "pending",
34
+ "terminated",
35
+ ]);
36
+ // ---------- suppliers ----------
37
+ export const suppliers = pgTable("suppliers", {
38
+ id: typeId("suppliers"),
39
+ name: text("name").notNull(),
40
+ type: supplierTypeEnum("type").notNull(),
41
+ status: supplierStatusEnum("status").notNull().default("active"),
42
+ description: text("description"),
43
+ // Defaults
44
+ defaultCurrency: text("default_currency"),
45
+ paymentTermsDays: integer("payment_terms_days"),
46
+ primaryFacilityId: typeIdRef("primary_facility_id").references(() => facilities.id, {
47
+ onDelete: "set null",
48
+ }),
49
+ // Metadata
50
+ tags: jsonb("tags").$type().default([]),
51
+ // Timestamps
52
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
53
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
54
+ }, (table) => [
55
+ index("idx_suppliers_type").on(table.type),
56
+ index("idx_suppliers_status").on(table.status),
57
+ index("idx_suppliers_primary_facility").on(table.primaryFacilityId),
58
+ ]);
59
+ // ---------- supplier_services ----------
60
+ export const supplierServices = pgTable("supplier_services", {
61
+ id: typeId("supplier_services"),
62
+ supplierId: typeIdRef("supplier_id")
63
+ .notNull()
64
+ .references(() => suppliers.id, { onDelete: "cascade" }),
65
+ serviceType: serviceTypeEnum("service_type").notNull(),
66
+ facilityId: typeIdRef("facility_id").references(() => facilities.id, { onDelete: "set null" }),
67
+ name: text("name").notNull(),
68
+ description: text("description"),
69
+ duration: text("duration"),
70
+ capacity: integer("capacity"),
71
+ active: boolean("active").notNull().default(true),
72
+ // Metadata
73
+ tags: jsonb("tags").$type().default([]),
74
+ // Timestamps
75
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
76
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
77
+ }, (table) => [
78
+ index("idx_supplier_services_supplier").on(table.supplierId),
79
+ index("idx_supplier_services_type").on(table.serviceType),
80
+ index("idx_supplier_services_facility").on(table.facilityId),
81
+ ]);
82
+ // ---------- supplier_rates ----------
83
+ export const supplierRates = pgTable("supplier_rates", {
84
+ id: typeId("supplier_rates"),
85
+ serviceId: typeIdRef("service_id")
86
+ .notNull()
87
+ .references(() => supplierServices.id, { onDelete: "cascade" }),
88
+ name: text("name").notNull(),
89
+ currency: text("currency").notNull(),
90
+ amountCents: integer("amount_cents").notNull(),
91
+ unit: rateUnitEnum("unit").notNull(),
92
+ // Season range
93
+ validFrom: date("valid_from"),
94
+ validTo: date("valid_to"),
95
+ // Group size
96
+ minPax: integer("min_pax"),
97
+ maxPax: integer("max_pax"),
98
+ notes: text("notes"),
99
+ // Timestamps
100
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
101
+ }, (table) => [
102
+ index("idx_supplier_rates_service").on(table.serviceId),
103
+ index("idx_supplier_rates_validity").on(table.validFrom, table.validTo),
104
+ ]);
105
+ // ---------- supplier_notes ----------
106
+ export const supplierNotes = pgTable("supplier_notes", {
107
+ id: typeId("supplier_notes"),
108
+ supplierId: typeIdRef("supplier_id")
109
+ .notNull()
110
+ .references(() => suppliers.id, { onDelete: "cascade" }),
111
+ authorId: text("author_id").notNull(),
112
+ content: text("content").notNull(),
113
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
114
+ }, (table) => [index("idx_supplier_notes_supplier").on(table.supplierId)]);
115
+ // ---------- supplier_availability ----------
116
+ export const supplierAvailability = pgTable("supplier_availability", {
117
+ id: typeId("supplier_availability"),
118
+ supplierId: typeIdRef("supplier_id")
119
+ .notNull()
120
+ .references(() => suppliers.id, { onDelete: "cascade" }),
121
+ date: date("date").notNull(),
122
+ available: boolean("available").notNull().default(true),
123
+ notes: text("notes"),
124
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
125
+ }, (table) => [
126
+ index("idx_supplier_availability_supplier").on(table.supplierId),
127
+ index("idx_supplier_availability_date").on(table.date),
128
+ ]);
129
+ // ---------- supplier_contracts ----------
130
+ export const supplierContracts = pgTable("supplier_contracts", {
131
+ id: typeId("supplier_contracts"),
132
+ supplierId: typeIdRef("supplier_id")
133
+ .notNull()
134
+ .references(() => suppliers.id, { onDelete: "cascade" }),
135
+ agreementNumber: text("agreement_number"),
136
+ startDate: date("start_date").notNull(),
137
+ endDate: date("end_date"),
138
+ renewalDate: date("renewal_date"),
139
+ terms: text("terms"),
140
+ status: supplierContractStatusEnum("status").notNull().default("active"),
141
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
142
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
143
+ }, (table) => [
144
+ index("idx_supplier_contracts_supplier").on(table.supplierId),
145
+ index("idx_supplier_contracts_status").on(table.status),
146
+ ]);
147
+ // ---------- relations ----------
148
+ export const suppliersRelations = relations(suppliers, ({ one, many }) => ({
149
+ primaryFacility: one(facilities, {
150
+ fields: [suppliers.primaryFacilityId],
151
+ references: [facilities.id],
152
+ }),
153
+ services: many(supplierServices),
154
+ notes: many(supplierNotes),
155
+ availability: many(supplierAvailability),
156
+ contracts: many(supplierContracts),
157
+ }));
158
+ export const supplierServicesRelations = relations(supplierServices, ({ one, many }) => ({
159
+ supplier: one(suppliers, { fields: [supplierServices.supplierId], references: [suppliers.id] }),
160
+ facility: one(facilities, {
161
+ fields: [supplierServices.facilityId],
162
+ references: [facilities.id],
163
+ }),
164
+ rates: many(supplierRates),
165
+ }));
166
+ export const supplierRatesRelations = relations(supplierRates, ({ one }) => ({
167
+ service: one(supplierServices, {
168
+ fields: [supplierRates.serviceId],
169
+ references: [supplierServices.id],
170
+ }),
171
+ }));
172
+ export const supplierNotesRelations = relations(supplierNotes, ({ one }) => ({
173
+ supplier: one(suppliers, { fields: [supplierNotes.supplierId], references: [suppliers.id] }),
174
+ }));
175
+ export const supplierAvailabilityRelations = relations(supplierAvailability, ({ one }) => ({
176
+ supplier: one(suppliers, {
177
+ fields: [supplierAvailability.supplierId],
178
+ references: [suppliers.id],
179
+ }),
180
+ }));
181
+ export const supplierContractsRelations = relations(supplierContracts, ({ one }) => ({
182
+ supplier: one(suppliers, {
183
+ fields: [supplierContracts.supplierId],
184
+ references: [suppliers.id],
185
+ }),
186
+ }));