@voyant-travel/distribution 0.109.8
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/LICENSE +201 -0
- package/README.md +42 -0
- package/dist/booking-extension.d.ts +168 -0
- package/dist/booking-extension.d.ts.map +1 -0
- package/dist/booking-extension.js +102 -0
- package/dist/channel-push/admin-routes.d.ts +31 -0
- package/dist/channel-push/admin-routes.d.ts.map +1 -0
- package/dist/channel-push/admin-routes.js +165 -0
- package/dist/channel-push/availability-push.d.ts +76 -0
- package/dist/channel-push/availability-push.d.ts.map +1 -0
- package/dist/channel-push/availability-push.js +236 -0
- package/dist/channel-push/booking-push-helpers.d.ts +36 -0
- package/dist/channel-push/booking-push-helpers.d.ts.map +1 -0
- package/dist/channel-push/booking-push-helpers.js +169 -0
- package/dist/channel-push/booking-push.d.ts +108 -0
- package/dist/channel-push/booking-push.d.ts.map +1 -0
- package/dist/channel-push/booking-push.js +335 -0
- package/dist/channel-push/boundary-sql.d.ts +23 -0
- package/dist/channel-push/boundary-sql.d.ts.map +1 -0
- package/dist/channel-push/boundary-sql.js +75 -0
- package/dist/channel-push/content-push.d.ts +60 -0
- package/dist/channel-push/content-push.d.ts.map +1 -0
- package/dist/channel-push/content-push.js +252 -0
- package/dist/channel-push/index.d.ts +15 -0
- package/dist/channel-push/index.d.ts.map +1 -0
- package/dist/channel-push/index.js +18 -0
- package/dist/channel-push/plugin.d.ts +18 -0
- package/dist/channel-push/plugin.d.ts.map +1 -0
- package/dist/channel-push/plugin.js +21 -0
- package/dist/channel-push/reconciler.d.ts +85 -0
- package/dist/channel-push/reconciler.d.ts.map +1 -0
- package/dist/channel-push/reconciler.js +179 -0
- package/dist/channel-push/subscriber.d.ts +40 -0
- package/dist/channel-push/subscriber.d.ts.map +1 -0
- package/dist/channel-push/subscriber.js +199 -0
- package/dist/channel-push/types.d.ts +43 -0
- package/dist/channel-push/types.d.ts.map +1 -0
- package/dist/channel-push/types.js +32 -0
- package/dist/channel-push/workflows.d.ts +56 -0
- package/dist/channel-push/workflows.d.ts.map +1 -0
- package/dist/channel-push/workflows.js +100 -0
- package/dist/external-refs/index.d.ts +11 -0
- package/dist/external-refs/index.d.ts.map +1 -0
- package/dist/external-refs/index.js +12 -0
- package/dist/external-refs/routes.d.ts +253 -0
- package/dist/external-refs/routes.d.ts.map +1 -0
- package/dist/external-refs/routes.js +52 -0
- package/dist/external-refs/schema.d.ts +251 -0
- package/dist/external-refs/schema.d.ts.map +1 -0
- package/dist/external-refs/schema.js +32 -0
- package/dist/external-refs/service.d.ts +82 -0
- package/dist/external-refs/service.d.ts.map +1 -0
- package/dist/external-refs/service.js +112 -0
- package/dist/external-refs/validation.d.ts +91 -0
- package/dist/external-refs/validation.d.ts.map +1 -0
- package/dist/external-refs/validation.js +40 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/interface-types.d.ts +128 -0
- package/dist/interface-types.d.ts.map +1 -0
- package/dist/interface-types.js +1 -0
- package/dist/interface.d.ts +10 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +286 -0
- package/dist/rate-limit.d.ts +69 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +135 -0
- package/dist/routes/batch.d.ts +200 -0
- package/dist/routes/batch.d.ts.map +1 -0
- package/dist/routes/batch.js +52 -0
- package/dist/routes/env.d.ts +8 -0
- package/dist/routes/env.d.ts.map +1 -0
- package/dist/routes/env.js +1 -0
- package/dist/routes/inventory.d.ts +604 -0
- package/dist/routes/inventory.d.ts.map +1 -0
- package/dist/routes/inventory.js +138 -0
- package/dist/routes/settlements.d.ts +1649 -0
- package/dist/routes/settlements.d.ts.map +1 -0
- package/dist/routes/settlements.js +265 -0
- package/dist/routes.d.ts +3909 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +323 -0
- package/dist/schema-automation.d.ts +680 -0
- package/dist/schema-automation.d.ts.map +1 -0
- package/dist/schema-automation.js +76 -0
- package/dist/schema-core.d.ts +1674 -0
- package/dist/schema-core.d.ts.map +1 -0
- package/dist/schema-core.js +227 -0
- package/dist/schema-finance.d.ts +1372 -0
- package/dist/schema-finance.d.ts.map +1 -0
- package/dist/schema-finance.js +153 -0
- package/dist/schema-inventory.d.ts +855 -0
- package/dist/schema-inventory.d.ts.map +1 -0
- package/dist/schema-inventory.js +102 -0
- package/dist/schema-push-intents.d.ts +387 -0
- package/dist/schema-push-intents.d.ts.map +1 -0
- package/dist/schema-push-intents.js +77 -0
- package/dist/schema-relations.d.ts +95 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +196 -0
- package/dist/schema-shared.d.ts +24 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +123 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +8 -0
- package/dist/service/channels.d.ts +167 -0
- package/dist/service/channels.d.ts.map +1 -0
- package/dist/service/channels.js +305 -0
- package/dist/service/commercial.d.ts +385 -0
- package/dist/service/commercial.d.ts.map +1 -0
- package/dist/service/commercial.js +248 -0
- package/dist/service/helpers.d.ts +10 -0
- package/dist/service/helpers.d.ts.map +1 -0
- package/dist/service/helpers.js +7 -0
- package/dist/service/inventory.d.ts +193 -0
- package/dist/service/inventory.d.ts.map +1 -0
- package/dist/service/inventory.js +154 -0
- package/dist/service/settlement-policies.d.ts +325 -0
- package/dist/service/settlement-policies.d.ts.map +1 -0
- package/dist/service/settlement-policies.js +272 -0
- package/dist/service/settlements.d.ts +357 -0
- package/dist/service/settlements.d.ts.map +1 -0
- package/dist/service/settlements.js +319 -0
- package/dist/service/types.d.ts +60 -0
- package/dist/service/types.d.ts.map +1 -0
- package/dist/service/types.js +1 -0
- package/dist/service.d.ts +1418 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +17 -0
- package/dist/suppliers/index.d.ts +15 -0
- package/dist/suppliers/index.d.ts.map +1 -0
- package/dist/suppliers/index.js +23 -0
- package/dist/suppliers/routes.d.ts +1202 -0
- package/dist/suppliers/routes.d.ts.map +1 -0
- package/dist/suppliers/routes.js +290 -0
- package/dist/suppliers/schema.d.ts +1272 -0
- package/dist/suppliers/schema.d.ts.map +1 -0
- package/dist/suppliers/schema.js +219 -0
- package/dist/suppliers/service-aggregates.d.ts +23 -0
- package/dist/suppliers/service-aggregates.d.ts.map +1 -0
- package/dist/suppliers/service-aggregates.js +51 -0
- package/dist/suppliers/service-core.d.ts +89 -0
- package/dist/suppliers/service-core.d.ts.map +1 -0
- package/dist/suppliers/service-core.js +164 -0
- package/dist/suppliers/service-identity.d.ts +162 -0
- package/dist/suppliers/service-identity.d.ts.map +1 -0
- package/dist/suppliers/service-identity.js +101 -0
- package/dist/suppliers/service-operations.d.ts +1500 -0
- package/dist/suppliers/service-operations.d.ts.map +1 -0
- package/dist/suppliers/service-operations.js +157 -0
- package/dist/suppliers/service-shared.d.ts +45 -0
- package/dist/suppliers/service-shared.d.ts.map +1 -0
- package/dist/suppliers/service-shared.js +294 -0
- package/dist/suppliers/service.d.ts +41 -0
- package/dist/suppliers/service.d.ts.map +1 -0
- package/dist/suppliers/service.js +40 -0
- package/dist/suppliers/validation.d.ts +2 -0
- package/dist/suppliers/validation.d.ts.map +1 -0
- package/dist/suppliers/validation.js +1 -0
- package/dist/validation.d.ts +1371 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +445 -0
- package/dist/webhook-deliveries.d.ts +86 -0
- package/dist/webhook-deliveries.d.ts.map +1 -0
- package/dist/webhook-deliveries.js +296 -0
- package/package.json +71 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/suppliers/schema.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { typeId, typeIdRef } from "@voyant-travel/db/lib/typeid-column";
|
|
2
|
+
import { relations } from "drizzle-orm";
|
|
3
|
+
import { boolean, date, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
4
|
+
export const supplierTypeEnum = pgEnum("supplier_type", [
|
|
5
|
+
"hotel",
|
|
6
|
+
"transfer",
|
|
7
|
+
"guide",
|
|
8
|
+
"experience",
|
|
9
|
+
"airline",
|
|
10
|
+
"restaurant",
|
|
11
|
+
"other",
|
|
12
|
+
]);
|
|
13
|
+
export const supplierStatusEnum = pgEnum("supplier_status", ["active", "inactive", "pending"]);
|
|
14
|
+
export const serviceTypeEnum = pgEnum("service_type", [
|
|
15
|
+
"accommodation",
|
|
16
|
+
"transfer",
|
|
17
|
+
"experience",
|
|
18
|
+
"guide",
|
|
19
|
+
"meal",
|
|
20
|
+
"other",
|
|
21
|
+
]);
|
|
22
|
+
export const rateUnitEnum = pgEnum("rate_unit", [
|
|
23
|
+
"per_person",
|
|
24
|
+
"per_group",
|
|
25
|
+
"per_night",
|
|
26
|
+
"per_vehicle",
|
|
27
|
+
"flat",
|
|
28
|
+
]);
|
|
29
|
+
export const supplierContractStatusEnum = pgEnum("supplier_contract_status", [
|
|
30
|
+
"active",
|
|
31
|
+
"expired",
|
|
32
|
+
"pending",
|
|
33
|
+
"terminated",
|
|
34
|
+
]);
|
|
35
|
+
// ---------- suppliers ----------
|
|
36
|
+
export const suppliers = pgTable("suppliers", {
|
|
37
|
+
id: typeId("suppliers"),
|
|
38
|
+
name: text("name").notNull(),
|
|
39
|
+
type: supplierTypeEnum("type").notNull(),
|
|
40
|
+
status: supplierStatusEnum("status").notNull().default("active"),
|
|
41
|
+
description: text("description"),
|
|
42
|
+
// Defaults
|
|
43
|
+
defaultCurrency: text("default_currency"),
|
|
44
|
+
paymentTermsDays: integer("payment_terms_days"),
|
|
45
|
+
reservationTimeoutMinutes: integer("reservation_timeout_minutes"),
|
|
46
|
+
primaryFacilityId: typeIdRef("primary_facility_id"),
|
|
47
|
+
/**
|
|
48
|
+
* Customer-facing payment policy override. When set, sourced
|
|
49
|
+
* bookings against this supplier inherit these terms instead of
|
|
50
|
+
* the deployment's default policy. Shape mirrors `PaymentPolicy`
|
|
51
|
+
* from `@voyant-travel/finance` (jsonb so the shape can evolve
|
|
52
|
+
* without per-field column adds).
|
|
53
|
+
*
|
|
54
|
+
* `null` means "inherit from operator default" — most suppliers
|
|
55
|
+
* leave this empty unless they impose their own deposit / balance
|
|
56
|
+
* window.
|
|
57
|
+
*
|
|
58
|
+
* Distinct from `paymentTermsDays` above, which governs when the
|
|
59
|
+
* operator pays the supplier (Net 14 / Net 30) — the inverse
|
|
60
|
+
* cash-flow direction.
|
|
61
|
+
*/
|
|
62
|
+
customerPaymentPolicy: jsonb("customer_payment_policy"),
|
|
63
|
+
// Metadata
|
|
64
|
+
tags: jsonb("tags").$type().default([]),
|
|
65
|
+
// Timestamps
|
|
66
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
67
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
68
|
+
}, (table) => [
|
|
69
|
+
index("idx_suppliers_created").on(table.createdAt),
|
|
70
|
+
index("idx_suppliers_type_created").on(table.type, table.createdAt),
|
|
71
|
+
index("idx_suppliers_status_created").on(table.status, table.createdAt),
|
|
72
|
+
index("idx_suppliers_primary_facility_created").on(table.primaryFacilityId, table.createdAt),
|
|
73
|
+
]);
|
|
74
|
+
// ---------- supplier_directory_projections ----------
|
|
75
|
+
export const supplierDirectoryProjections = pgTable("supplier_directory_projections", {
|
|
76
|
+
supplierId: typeIdRef("supplier_id")
|
|
77
|
+
.notNull()
|
|
78
|
+
.references(() => suppliers.id, { onDelete: "cascade" }),
|
|
79
|
+
email: text("email"),
|
|
80
|
+
phone: text("phone"),
|
|
81
|
+
website: text("website"),
|
|
82
|
+
address: text("address"),
|
|
83
|
+
city: text("city"),
|
|
84
|
+
country: text("country"),
|
|
85
|
+
contactName: text("contact_name"),
|
|
86
|
+
contactEmail: text("contact_email"),
|
|
87
|
+
contactPhone: text("contact_phone"),
|
|
88
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
89
|
+
}, (table) => [uniqueIndex("uq_supplier_directory_projections_supplier").on(table.supplierId)]);
|
|
90
|
+
// ---------- supplier_services ----------
|
|
91
|
+
export const supplierServices = pgTable("supplier_services", {
|
|
92
|
+
id: typeId("supplier_services"),
|
|
93
|
+
supplierId: typeIdRef("supplier_id")
|
|
94
|
+
.notNull()
|
|
95
|
+
.references(() => suppliers.id, { onDelete: "cascade" }),
|
|
96
|
+
serviceType: serviceTypeEnum("service_type").notNull(),
|
|
97
|
+
facilityId: typeIdRef("facility_id"),
|
|
98
|
+
name: text("name").notNull(),
|
|
99
|
+
description: text("description"),
|
|
100
|
+
duration: text("duration"),
|
|
101
|
+
capacity: integer("capacity"),
|
|
102
|
+
active: boolean("active").notNull().default(true),
|
|
103
|
+
// Metadata
|
|
104
|
+
tags: jsonb("tags").$type().default([]),
|
|
105
|
+
// Timestamps
|
|
106
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
107
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
108
|
+
}, (table) => [
|
|
109
|
+
index("idx_supplier_services_supplier_created").on(table.supplierId, table.createdAt),
|
|
110
|
+
index("idx_supplier_services_type").on(table.serviceType),
|
|
111
|
+
index("idx_supplier_services_facility").on(table.facilityId),
|
|
112
|
+
]);
|
|
113
|
+
// ---------- supplier_rates ----------
|
|
114
|
+
export const supplierRates = pgTable("supplier_rates", {
|
|
115
|
+
id: typeId("supplier_rates"),
|
|
116
|
+
serviceId: typeIdRef("service_id")
|
|
117
|
+
.notNull()
|
|
118
|
+
.references(() => supplierServices.id, { onDelete: "cascade" }),
|
|
119
|
+
name: text("name").notNull(),
|
|
120
|
+
currency: text("currency").notNull(),
|
|
121
|
+
amountCents: integer("amount_cents").notNull(),
|
|
122
|
+
unit: rateUnitEnum("unit").notNull(),
|
|
123
|
+
// Season range
|
|
124
|
+
validFrom: date("valid_from"),
|
|
125
|
+
validTo: date("valid_to"),
|
|
126
|
+
// Group size
|
|
127
|
+
minPax: integer("min_pax"),
|
|
128
|
+
maxPax: integer("max_pax"),
|
|
129
|
+
notes: text("notes"),
|
|
130
|
+
// Timestamps
|
|
131
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
132
|
+
}, (table) => [
|
|
133
|
+
index("idx_supplier_rates_service_created").on(table.serviceId, table.createdAt),
|
|
134
|
+
index("idx_supplier_rates_validity").on(table.validFrom, table.validTo),
|
|
135
|
+
]);
|
|
136
|
+
// ---------- supplier_notes ----------
|
|
137
|
+
export const supplierNotes = pgTable("supplier_notes", {
|
|
138
|
+
id: typeId("supplier_notes"),
|
|
139
|
+
supplierId: typeIdRef("supplier_id")
|
|
140
|
+
.notNull()
|
|
141
|
+
.references(() => suppliers.id, { onDelete: "cascade" }),
|
|
142
|
+
authorId: text("author_id").notNull(),
|
|
143
|
+
content: text("content").notNull(),
|
|
144
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
145
|
+
}, (table) => [index("idx_supplier_notes_supplier_created").on(table.supplierId, table.createdAt)]);
|
|
146
|
+
// ---------- supplier_availability ----------
|
|
147
|
+
export const supplierAvailability = pgTable("supplier_availability", {
|
|
148
|
+
id: typeId("supplier_availability"),
|
|
149
|
+
supplierId: typeIdRef("supplier_id")
|
|
150
|
+
.notNull()
|
|
151
|
+
.references(() => suppliers.id, { onDelete: "cascade" }),
|
|
152
|
+
date: date("date").notNull(),
|
|
153
|
+
available: boolean("available").notNull().default(true),
|
|
154
|
+
notes: text("notes"),
|
|
155
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
156
|
+
}, (table) => [
|
|
157
|
+
index("idx_supplier_availability_supplier_date").on(table.supplierId, table.date),
|
|
158
|
+
index("idx_supplier_availability_date").on(table.date),
|
|
159
|
+
]);
|
|
160
|
+
// ---------- supplier_contracts ----------
|
|
161
|
+
export const supplierContracts = pgTable("supplier_contracts", {
|
|
162
|
+
id: typeId("supplier_contracts"),
|
|
163
|
+
supplierId: typeIdRef("supplier_id")
|
|
164
|
+
.notNull()
|
|
165
|
+
.references(() => suppliers.id, { onDelete: "cascade" }),
|
|
166
|
+
agreementNumber: text("agreement_number"),
|
|
167
|
+
startDate: date("start_date").notNull(),
|
|
168
|
+
endDate: date("end_date"),
|
|
169
|
+
renewalDate: date("renewal_date"),
|
|
170
|
+
terms: text("terms"),
|
|
171
|
+
status: supplierContractStatusEnum("status").notNull().default("active"),
|
|
172
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
173
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
174
|
+
}, (table) => [
|
|
175
|
+
index("idx_supplier_contracts_supplier_created").on(table.supplierId, table.createdAt),
|
|
176
|
+
index("idx_supplier_contracts_status").on(table.status),
|
|
177
|
+
]);
|
|
178
|
+
// ---------- relations ----------
|
|
179
|
+
export const suppliersRelations = relations(suppliers, ({ one, many }) => ({
|
|
180
|
+
directoryProjection: one(supplierDirectoryProjections, {
|
|
181
|
+
fields: [suppliers.id],
|
|
182
|
+
references: [supplierDirectoryProjections.supplierId],
|
|
183
|
+
}),
|
|
184
|
+
services: many(supplierServices),
|
|
185
|
+
notes: many(supplierNotes),
|
|
186
|
+
availability: many(supplierAvailability),
|
|
187
|
+
contracts: many(supplierContracts),
|
|
188
|
+
}));
|
|
189
|
+
export const supplierDirectoryProjectionsRelations = relations(supplierDirectoryProjections, ({ one }) => ({
|
|
190
|
+
supplier: one(suppliers, {
|
|
191
|
+
fields: [supplierDirectoryProjections.supplierId],
|
|
192
|
+
references: [suppliers.id],
|
|
193
|
+
}),
|
|
194
|
+
}));
|
|
195
|
+
export const supplierServicesRelations = relations(supplierServices, ({ one, many }) => ({
|
|
196
|
+
supplier: one(suppliers, { fields: [supplierServices.supplierId], references: [suppliers.id] }),
|
|
197
|
+
rates: many(supplierRates),
|
|
198
|
+
}));
|
|
199
|
+
export const supplierRatesRelations = relations(supplierRates, ({ one }) => ({
|
|
200
|
+
service: one(supplierServices, {
|
|
201
|
+
fields: [supplierRates.serviceId],
|
|
202
|
+
references: [supplierServices.id],
|
|
203
|
+
}),
|
|
204
|
+
}));
|
|
205
|
+
export const supplierNotesRelations = relations(supplierNotes, ({ one }) => ({
|
|
206
|
+
supplier: one(suppliers, { fields: [supplierNotes.supplierId], references: [suppliers.id] }),
|
|
207
|
+
}));
|
|
208
|
+
export const supplierAvailabilityRelations = relations(supplierAvailability, ({ one }) => ({
|
|
209
|
+
supplier: one(suppliers, {
|
|
210
|
+
fields: [supplierAvailability.supplierId],
|
|
211
|
+
references: [suppliers.id],
|
|
212
|
+
}),
|
|
213
|
+
}));
|
|
214
|
+
export const supplierContractsRelations = relations(supplierContracts, ({ one }) => ({
|
|
215
|
+
supplier: one(suppliers, {
|
|
216
|
+
fields: [supplierContracts.supplierId],
|
|
217
|
+
references: [suppliers.id],
|
|
218
|
+
}),
|
|
219
|
+
}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import { suppliers } from "./schema.js";
|
|
3
|
+
type SupplierStatus = (typeof suppliers.$inferSelect)["status"];
|
|
4
|
+
type SupplierType = (typeof suppliers.$inferSelect)["type"];
|
|
5
|
+
export interface SupplierAggregates {
|
|
6
|
+
total: number;
|
|
7
|
+
countsByStatus: Array<{
|
|
8
|
+
status: SupplierStatus;
|
|
9
|
+
count: number;
|
|
10
|
+
}>;
|
|
11
|
+
countsByType: Array<{
|
|
12
|
+
type: SupplierType;
|
|
13
|
+
count: number;
|
|
14
|
+
}>;
|
|
15
|
+
/** Shorthand for the `active` bucket — dashboard KPI card. */
|
|
16
|
+
active: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function getSupplierAggregates(db: PostgresJsDatabase, options?: {
|
|
19
|
+
from?: string;
|
|
20
|
+
to?: string;
|
|
21
|
+
}): Promise<SupplierAggregates>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=service-aggregates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-aggregates.d.ts","sourceRoot":"","sources":["../../src/suppliers/service-aggregates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,KAAK,cAAc,GAAG,CAAC,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,CAAA;AAC/D,KAAK,YAAY,GAAG,CAAC,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAa3D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAChE,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC1D,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,kBAAkB,EACtB,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAO,GAC3C,OAAO,CAAC,kBAAkB,CAAC,CAwC7B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { and, sql } from "drizzle-orm";
|
|
2
|
+
import { suppliers } from "./schema.js";
|
|
3
|
+
const ALL_SUPPLIER_STATUSES = ["active", "inactive", "pending"];
|
|
4
|
+
const ALL_SUPPLIER_TYPES = [
|
|
5
|
+
"hotel",
|
|
6
|
+
"transfer",
|
|
7
|
+
"guide",
|
|
8
|
+
"experience",
|
|
9
|
+
"airline",
|
|
10
|
+
"restaurant",
|
|
11
|
+
"other",
|
|
12
|
+
];
|
|
13
|
+
export async function getSupplierAggregates(db, options = {}) {
|
|
14
|
+
const fromDate = options.from ? new Date(options.from) : undefined;
|
|
15
|
+
const toDate = options.to ? new Date(options.to) : undefined;
|
|
16
|
+
const rangeConditions = [];
|
|
17
|
+
// agent-quality: raw-sql reviewed -- owner: suppliers; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
18
|
+
if (fromDate)
|
|
19
|
+
rangeConditions.push(sql `${suppliers.createdAt} >= ${fromDate}`);
|
|
20
|
+
// agent-quality: raw-sql reviewed -- owner: suppliers; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
21
|
+
if (toDate)
|
|
22
|
+
rangeConditions.push(sql `${suppliers.createdAt} < ${toDate}`);
|
|
23
|
+
const rangeWhere = rangeConditions.length ? and(...rangeConditions) : undefined;
|
|
24
|
+
const [[totalRow], statusRows, typeRows] = await Promise.all([
|
|
25
|
+
db.select({ count: sql `count(*)::int` }).from(suppliers).where(rangeWhere),
|
|
26
|
+
db
|
|
27
|
+
.select({ status: suppliers.status, count: sql `count(*)::int` })
|
|
28
|
+
.from(suppliers)
|
|
29
|
+
.where(rangeWhere)
|
|
30
|
+
.groupBy(suppliers.status),
|
|
31
|
+
db
|
|
32
|
+
.select({ type: suppliers.type, count: sql `count(*)::int` })
|
|
33
|
+
.from(suppliers)
|
|
34
|
+
.where(rangeWhere)
|
|
35
|
+
.groupBy(suppliers.type),
|
|
36
|
+
]);
|
|
37
|
+
const statusMap = new Map(statusRows.map((r) => [r.status, r.count]));
|
|
38
|
+
const typeMap = new Map(typeRows.map((r) => [r.type, r.count]));
|
|
39
|
+
return {
|
|
40
|
+
total: totalRow?.count ?? 0,
|
|
41
|
+
countsByStatus: ALL_SUPPLIER_STATUSES.map((status) => ({
|
|
42
|
+
status,
|
|
43
|
+
count: statusMap.get(status) ?? 0,
|
|
44
|
+
})),
|
|
45
|
+
countsByType: ALL_SUPPLIER_TYPES.map((type) => ({
|
|
46
|
+
type,
|
|
47
|
+
count: typeMap.get(type) ?? 0,
|
|
48
|
+
})),
|
|
49
|
+
active: statusMap.get("active") ?? 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { CreateSupplierInput, SupplierListQuery, UpdateSupplierInput } from "./service-shared.js";
|
|
3
|
+
export declare function listSuppliers(db: PostgresJsDatabase, query: SupplierListQuery): Promise<{
|
|
4
|
+
data: ({
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: "other" | "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant";
|
|
8
|
+
status: "pending" | "active" | "inactive";
|
|
9
|
+
description: string | null;
|
|
10
|
+
defaultCurrency: string | null;
|
|
11
|
+
paymentTermsDays: number | null;
|
|
12
|
+
reservationTimeoutMinutes: number | null;
|
|
13
|
+
primaryFacilityId: string | null;
|
|
14
|
+
customerPaymentPolicy: unknown;
|
|
15
|
+
tags: string[] | null;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
} & import("./service-shared.js").SupplierHydratedFields)[];
|
|
19
|
+
total: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
offset: number;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function getSupplierById(db: PostgresJsDatabase, id: string): Promise<({
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
type: "other" | "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant";
|
|
27
|
+
status: "pending" | "active" | "inactive";
|
|
28
|
+
description: string | null;
|
|
29
|
+
defaultCurrency: string | null;
|
|
30
|
+
paymentTermsDays: number | null;
|
|
31
|
+
reservationTimeoutMinutes: number | null;
|
|
32
|
+
primaryFacilityId: string | null;
|
|
33
|
+
customerPaymentPolicy: unknown;
|
|
34
|
+
tags: string[] | null;
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
updatedAt: Date;
|
|
37
|
+
} & import("./service-shared.js").SupplierHydratedFields) | null>;
|
|
38
|
+
export declare function createSupplier(db: PostgresJsDatabase, data: CreateSupplierInput): Promise<{
|
|
39
|
+
email: string | null;
|
|
40
|
+
phone: string | null;
|
|
41
|
+
website: string | null;
|
|
42
|
+
address: string | null;
|
|
43
|
+
city: string | null;
|
|
44
|
+
country: string | null;
|
|
45
|
+
contactName: string | null;
|
|
46
|
+
contactEmail: string | null;
|
|
47
|
+
contactPhone: string | null;
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
status: "pending" | "active" | "inactive";
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
tags: string[] | null;
|
|
53
|
+
description: string | null;
|
|
54
|
+
type: "other" | "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant";
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
defaultCurrency: string | null;
|
|
57
|
+
paymentTermsDays: number | null;
|
|
58
|
+
reservationTimeoutMinutes: number | null;
|
|
59
|
+
primaryFacilityId: string | null;
|
|
60
|
+
customerPaymentPolicy: unknown;
|
|
61
|
+
}>;
|
|
62
|
+
export declare function updateSupplier(db: PostgresJsDatabase, id: string, data: UpdateSupplierInput): Promise<{
|
|
63
|
+
email: string | null;
|
|
64
|
+
phone: string | null;
|
|
65
|
+
website: string | null;
|
|
66
|
+
address: string | null;
|
|
67
|
+
city: string | null;
|
|
68
|
+
country: string | null;
|
|
69
|
+
contactName: string | null;
|
|
70
|
+
contactEmail: string | null;
|
|
71
|
+
contactPhone: string | null;
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
type: "other" | "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant";
|
|
75
|
+
status: "pending" | "active" | "inactive";
|
|
76
|
+
description: string | null;
|
|
77
|
+
defaultCurrency: string | null;
|
|
78
|
+
paymentTermsDays: number | null;
|
|
79
|
+
reservationTimeoutMinutes: number | null;
|
|
80
|
+
primaryFacilityId: string | null;
|
|
81
|
+
customerPaymentPolicy: unknown;
|
|
82
|
+
tags: string[] | null;
|
|
83
|
+
createdAt: Date;
|
|
84
|
+
updatedAt: Date;
|
|
85
|
+
} | null>;
|
|
86
|
+
export declare function deleteSupplier(db: PostgresJsDatabase, id: string): Promise<{
|
|
87
|
+
id: string;
|
|
88
|
+
} | null>;
|
|
89
|
+
//# sourceMappingURL=service-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-core.d.ts","sourceRoot":"","sources":["../../src/suppliers/service-core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,qBAAqB,CAAA;AAG5B,wBAAsB,aAAa,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;GA2FnF;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;kEAQvE;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;GA2CrF;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;UAqD1B;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMtE"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { and, asc, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { supplierDirectoryProjections, suppliers } from "./schema.js";
|
|
3
|
+
import { hydrateSuppliers, syncSupplierIdentity } from "./service-shared.js";
|
|
4
|
+
export async function listSuppliers(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.type) {
|
|
7
|
+
conditions.push(eq(suppliers.type, query.type));
|
|
8
|
+
}
|
|
9
|
+
if (query.status) {
|
|
10
|
+
conditions.push(eq(suppliers.status, query.status));
|
|
11
|
+
}
|
|
12
|
+
if (query.primaryFacilityId) {
|
|
13
|
+
conditions.push(eq(suppliers.primaryFacilityId, query.primaryFacilityId));
|
|
14
|
+
}
|
|
15
|
+
if (query.defaultCurrency) {
|
|
16
|
+
conditions.push(eq(suppliers.defaultCurrency, query.defaultCurrency));
|
|
17
|
+
}
|
|
18
|
+
if (query.country) {
|
|
19
|
+
conditions.push(sql `exists (
|
|
20
|
+
select 1
|
|
21
|
+
from ${supplierDirectoryProjections}
|
|
22
|
+
where ${supplierDirectoryProjections.supplierId} = ${suppliers.id}
|
|
23
|
+
and ${supplierDirectoryProjections.country} = ${query.country}
|
|
24
|
+
)`);
|
|
25
|
+
}
|
|
26
|
+
if (query.search) {
|
|
27
|
+
const term = `%${query.search}%`;
|
|
28
|
+
conditions.push(sql `(
|
|
29
|
+
${suppliers.name} ilike ${term}
|
|
30
|
+
or
|
|
31
|
+
exists (
|
|
32
|
+
select 1
|
|
33
|
+
from ${supplierDirectoryProjections}
|
|
34
|
+
where ${supplierDirectoryProjections.supplierId} = ${suppliers.id}
|
|
35
|
+
and (
|
|
36
|
+
${supplierDirectoryProjections.email} ilike ${term}
|
|
37
|
+
or ${supplierDirectoryProjections.phone} ilike ${term}
|
|
38
|
+
or ${supplierDirectoryProjections.website} ilike ${term}
|
|
39
|
+
or ${supplierDirectoryProjections.address} ilike ${term}
|
|
40
|
+
or ${supplierDirectoryProjections.city} ilike ${term}
|
|
41
|
+
or ${supplierDirectoryProjections.country} ilike ${term}
|
|
42
|
+
or ${supplierDirectoryProjections.contactName} ilike ${term}
|
|
43
|
+
or ${supplierDirectoryProjections.contactEmail} ilike ${term}
|
|
44
|
+
or ${supplierDirectoryProjections.contactPhone} ilike ${term}
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
)`);
|
|
48
|
+
}
|
|
49
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
50
|
+
const sortColumn = (() => {
|
|
51
|
+
switch (query.sortBy) {
|
|
52
|
+
case "name":
|
|
53
|
+
return suppliers.name;
|
|
54
|
+
case "type":
|
|
55
|
+
return suppliers.type;
|
|
56
|
+
case "status":
|
|
57
|
+
return suppliers.status;
|
|
58
|
+
case "defaultCurrency":
|
|
59
|
+
return suppliers.defaultCurrency;
|
|
60
|
+
default:
|
|
61
|
+
return suppliers.createdAt;
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
const sortFn = query.sortDir === "asc" ? asc : desc;
|
|
65
|
+
const [rows, countResult] = await Promise.all([
|
|
66
|
+
db
|
|
67
|
+
.select()
|
|
68
|
+
.from(suppliers)
|
|
69
|
+
.where(where)
|
|
70
|
+
.limit(query.limit)
|
|
71
|
+
.offset(query.offset)
|
|
72
|
+
.orderBy(sortFn(sortColumn), desc(suppliers.createdAt)),
|
|
73
|
+
db.select({ count: sql `count(*)::int` }).from(suppliers).where(where),
|
|
74
|
+
]);
|
|
75
|
+
return {
|
|
76
|
+
data: await hydrateSuppliers(db, rows),
|
|
77
|
+
total: countResult[0]?.count ?? 0,
|
|
78
|
+
limit: query.limit,
|
|
79
|
+
offset: query.offset,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export async function getSupplierById(db, id) {
|
|
83
|
+
const [row] = await db.select().from(suppliers).where(eq(suppliers.id, id)).limit(1);
|
|
84
|
+
if (!row) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const [hydrated] = await hydrateSuppliers(db, [row]);
|
|
88
|
+
return hydrated ?? null;
|
|
89
|
+
}
|
|
90
|
+
export async function createSupplier(db, data) {
|
|
91
|
+
const { email, phone, website, address, city, country, contactName, contactEmail, contactPhone, ...supplierValues } = data;
|
|
92
|
+
const [row] = await db.insert(suppliers).values(supplierValues).returning();
|
|
93
|
+
if (!row) {
|
|
94
|
+
throw new Error("Failed to create supplier");
|
|
95
|
+
}
|
|
96
|
+
await syncSupplierIdentity(db, row.id, {
|
|
97
|
+
email,
|
|
98
|
+
phone,
|
|
99
|
+
website,
|
|
100
|
+
address,
|
|
101
|
+
city,
|
|
102
|
+
country,
|
|
103
|
+
contactName,
|
|
104
|
+
contactEmail,
|
|
105
|
+
contactPhone,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...row,
|
|
109
|
+
email: email ?? null,
|
|
110
|
+
phone: phone ?? null,
|
|
111
|
+
website: website ?? null,
|
|
112
|
+
address: address ?? null,
|
|
113
|
+
city: city ?? null,
|
|
114
|
+
country: country ?? null,
|
|
115
|
+
contactName: contactName ?? null,
|
|
116
|
+
contactEmail: contactEmail ?? null,
|
|
117
|
+
contactPhone: contactPhone ?? null,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export async function updateSupplier(db, id, data) {
|
|
121
|
+
const existing = await getSupplierById(db, id);
|
|
122
|
+
if (!existing) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const { email, phone, website, address, city, country, contactName, contactEmail, contactPhone, ...supplierValues } = data;
|
|
126
|
+
const [row] = await db
|
|
127
|
+
.update(suppliers)
|
|
128
|
+
.set({ ...supplierValues, updatedAt: new Date() })
|
|
129
|
+
.where(eq(suppliers.id, id))
|
|
130
|
+
.returning();
|
|
131
|
+
if (!row) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
await syncSupplierIdentity(db, id, {
|
|
135
|
+
email: email ?? existing.email,
|
|
136
|
+
phone: phone ?? existing.phone,
|
|
137
|
+
website: website ?? existing.website,
|
|
138
|
+
address: address ?? existing.address,
|
|
139
|
+
city: city ?? existing.city,
|
|
140
|
+
country: country ?? existing.country,
|
|
141
|
+
contactName: contactName ?? existing.contactName,
|
|
142
|
+
contactEmail: contactEmail ?? existing.contactEmail,
|
|
143
|
+
contactPhone: contactPhone ?? existing.contactPhone,
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
...row,
|
|
147
|
+
email: email ?? existing.email,
|
|
148
|
+
phone: phone ?? existing.phone,
|
|
149
|
+
website: website ?? existing.website,
|
|
150
|
+
address: address ?? existing.address,
|
|
151
|
+
city: city ?? existing.city,
|
|
152
|
+
country: country ?? existing.country,
|
|
153
|
+
contactName: contactName ?? existing.contactName,
|
|
154
|
+
contactEmail: contactEmail ?? existing.contactEmail,
|
|
155
|
+
contactPhone: contactPhone ?? existing.contactPhone,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export async function deleteSupplier(db, id) {
|
|
159
|
+
const [row] = await db
|
|
160
|
+
.delete(suppliers)
|
|
161
|
+
.where(eq(suppliers.id, id))
|
|
162
|
+
.returning({ id: suppliers.id });
|
|
163
|
+
return row ?? null;
|
|
164
|
+
}
|