@voyant-travel/inventory 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.
- package/LICENSE +201 -0
- package/dist/action-ledger-drift.d.ts +29 -0
- package/dist/action-ledger-drift.d.ts.map +1 -0
- package/dist/action-ledger-drift.js +338 -0
- package/dist/action-ledger.d.ts +104 -0
- package/dist/action-ledger.d.ts.map +1 -0
- package/dist/action-ledger.js +100 -0
- package/dist/authoring/builder.d.ts +37 -0
- package/dist/authoring/builder.d.ts.map +1 -0
- package/dist/authoring/builder.js +248 -0
- package/dist/authoring/clone-content.d.ts +38 -0
- package/dist/authoring/clone-content.d.ts.map +1 -0
- package/dist/authoring/clone-content.js +367 -0
- package/dist/authoring/clone-pricing.d.ts +9 -0
- package/dist/authoring/clone-pricing.d.ts.map +1 -0
- package/dist/authoring/clone-pricing.js +242 -0
- package/dist/authoring/clone.d.ts +45 -0
- package/dist/authoring/clone.d.ts.map +1 -0
- package/dist/authoring/clone.js +142 -0
- package/dist/authoring/errors.d.ts +21 -0
- package/dist/authoring/errors.d.ts.map +1 -0
- package/dist/authoring/errors.js +13 -0
- package/dist/authoring/extension.d.ts +248 -0
- package/dist/authoring/extension.d.ts.map +1 -0
- package/dist/authoring/extension.js +116 -0
- package/dist/authoring/index.d.ts +12 -0
- package/dist/authoring/index.d.ts.map +1 -0
- package/dist/authoring/index.js +11 -0
- package/dist/authoring/schema.d.ts +85 -0
- package/dist/authoring/schema.d.ts.map +1 -0
- package/dist/authoring/schema.js +16 -0
- package/dist/authoring/service.d.ts +28 -0
- package/dist/authoring/service.d.ts.map +1 -0
- package/dist/authoring/service.js +66 -0
- package/dist/authoring/spec.d.ts +524 -0
- package/dist/authoring/spec.d.ts.map +1 -0
- package/dist/authoring/spec.js +167 -0
- package/dist/authoring/validate.d.ts +17 -0
- package/dist/authoring/validate.d.ts.map +1 -0
- package/dist/authoring/validate.js +83 -0
- package/dist/authoring.d.ts +2 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +1 -0
- package/dist/booking-engine/handler-support.d.ts +91 -0
- package/dist/booking-engine/handler-support.d.ts.map +1 -0
- package/dist/booking-engine/handler-support.js +355 -0
- package/dist/booking-engine/handler.d.ts +404 -0
- package/dist/booking-engine/handler.d.ts.map +1 -0
- package/dist/booking-engine/handler.js +398 -0
- package/dist/booking-engine/index.d.ts +8 -0
- package/dist/booking-engine/index.d.ts.map +1 -0
- package/dist/booking-engine/index.js +7 -0
- package/dist/booking-engine.d.ts +2 -0
- package/dist/booking-engine.d.ts.map +1 -0
- package/dist/booking-engine.js +1 -0
- package/dist/booking-extension.d.ts +278 -0
- package/dist/booking-extension.d.ts.map +1 -0
- package/dist/booking-extension.js +161 -0
- package/dist/catalog-policy-departures.d.ts +52 -0
- package/dist/catalog-policy-departures.d.ts.map +1 -0
- package/dist/catalog-policy-departures.js +169 -0
- package/dist/catalog-policy-destinations.d.ts +43 -0
- package/dist/catalog-policy-destinations.d.ts.map +1 -0
- package/dist/catalog-policy-destinations.js +165 -0
- package/dist/catalog-policy-pricing.d.ts +55 -0
- package/dist/catalog-policy-pricing.d.ts.map +1 -0
- package/dist/catalog-policy-pricing.js +109 -0
- package/dist/catalog-policy-promotions.d.ts +52 -0
- package/dist/catalog-policy-promotions.d.ts.map +1 -0
- package/dist/catalog-policy-promotions.js +270 -0
- package/dist/catalog-policy-taxonomy.d.ts +51 -0
- package/dist/catalog-policy-taxonomy.d.ts.map +1 -0
- package/dist/catalog-policy-taxonomy.js +191 -0
- package/dist/catalog-policy.d.ts +33 -0
- package/dist/catalog-policy.d.ts.map +1 -0
- package/dist/catalog-policy.js +733 -0
- package/dist/content-shape.d.ts +15 -0
- package/dist/content-shape.d.ts.map +1 -0
- package/dist/content-shape.js +28 -0
- package/dist/draft-shape.d.ts +43 -0
- package/dist/draft-shape.d.ts.map +1 -0
- package/dist/draft-shape.js +48 -0
- package/dist/events.d.ts +37 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +32 -0
- package/dist/extras/catalog-policy.d.ts +30 -0
- package/dist/extras/catalog-policy.d.ts.map +1 -0
- package/dist/extras/catalog-policy.js +319 -0
- package/dist/extras/content-shape.d.ts +5 -0
- package/dist/extras/content-shape.d.ts.map +1 -0
- package/dist/extras/content-shape.js +13 -0
- package/dist/extras/draft-shape.d.ts +34 -0
- package/dist/extras/draft-shape.d.ts.map +1 -0
- package/dist/extras/draft-shape.js +69 -0
- package/dist/extras/routes.d.ts +380 -0
- package/dist/extras/routes.d.ts.map +1 -0
- package/dist/extras/routes.js +59 -0
- package/dist/extras/schema-sourced-content.d.ts +254 -0
- package/dist/extras/schema-sourced-content.d.ts.map +1 -0
- package/dist/extras/schema-sourced-content.js +45 -0
- package/dist/extras/schema.d.ts +628 -0
- package/dist/extras/schema.d.ts.map +1 -0
- package/dist/extras/schema.js +87 -0
- package/dist/extras/service-catalog-plane.d.ts +77 -0
- package/dist/extras/service-catalog-plane.d.ts.map +1 -0
- package/dist/extras/service-catalog-plane.js +219 -0
- package/dist/extras/service-content-synthesizer.d.ts +41 -0
- package/dist/extras/service-content-synthesizer.d.ts.map +1 -0
- package/dist/extras/service-content-synthesizer.js +138 -0
- package/dist/extras/service-content.d.ts +48 -0
- package/dist/extras/service-content.d.ts.map +1 -0
- package/dist/extras/service-content.js +253 -0
- package/dist/extras/service.d.ts +185 -0
- package/dist/extras/service.d.ts.map +1 -0
- package/dist/extras/service.js +96 -0
- package/dist/extras/validation.d.ts +437 -0
- package/dist/extras/validation.d.ts.map +1 -0
- package/dist/extras/validation.js +149 -0
- package/dist/extras.d.ts +267 -0
- package/dist/extras.d.ts.map +1 -0
- package/dist/extras.js +19 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/interface.d.ts +5869 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +54 -0
- package/dist/public-routes.d.ts +2 -0
- package/dist/public-routes.d.ts.map +1 -0
- package/dist/public-routes.js +1 -0
- package/dist/public-validation.d.ts +2 -0
- package/dist/public-validation.d.ts.map +1 -0
- package/dist/public-validation.js +1 -0
- package/dist/read-model.d.ts +25 -0
- package/dist/read-model.d.ts.map +1 -0
- package/dist/read-model.js +99 -0
- package/dist/route-env.d.ts +22 -0
- package/dist/route-env.d.ts.map +1 -0
- package/dist/route-env.js +1 -0
- package/dist/routes-associations.d.ts +164 -0
- package/dist/routes-associations.d.ts.map +1 -0
- package/dist/routes-associations.js +100 -0
- package/dist/routes-catalog.d.ts +436 -0
- package/dist/routes-catalog.d.ts.map +1 -0
- package/dist/routes-catalog.js +104 -0
- package/dist/routes-configuration.d.ts +773 -0
- package/dist/routes-configuration.d.ts.map +1 -0
- package/dist/routes-configuration.js +364 -0
- package/dist/routes-content.d.ts +74 -0
- package/dist/routes-content.d.ts.map +1 -0
- package/dist/routes-content.js +117 -0
- package/dist/routes-core.d.ts +331 -0
- package/dist/routes-core.d.ts.map +1 -0
- package/dist/routes-core.js +95 -0
- package/dist/routes-itinerary.d.ts +759 -0
- package/dist/routes-itinerary.d.ts.map +1 -0
- package/dist/routes-itinerary.js +387 -0
- package/dist/routes-maintenance.d.ts +32 -0
- package/dist/routes-maintenance.d.ts.map +1 -0
- package/dist/routes-maintenance.js +14 -0
- package/dist/routes-media.d.ts +634 -0
- package/dist/routes-media.d.ts.map +1 -0
- package/dist/routes-media.js +245 -0
- package/dist/routes-merchandising.d.ts +1120 -0
- package/dist/routes-merchandising.d.ts.map +1 -0
- package/dist/routes-merchandising.js +377 -0
- package/dist/routes-options.d.ts +363 -0
- package/dist/routes-options.d.ts.map +1 -0
- package/dist/routes-options.js +173 -0
- package/dist/routes-public.d.ts +776 -0
- package/dist/routes-public.d.ts.map +1 -0
- package/dist/routes-public.js +119 -0
- package/dist/routes-translations.d.ts +489 -0
- package/dist/routes-translations.d.ts.map +1 -0
- package/dist/routes-translations.js +258 -0
- package/dist/routes.d.ts +5097 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +64 -0
- package/dist/schema-core.d.ts +1238 -0
- package/dist/schema-core.d.ts.map +1 -0
- package/dist/schema-core.js +157 -0
- package/dist/schema-itinerary.d.ts +1169 -0
- package/dist/schema-itinerary.d.ts.map +1 -0
- package/dist/schema-itinerary.js +130 -0
- package/dist/schema-relations.d.ts +117 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +192 -0
- package/dist/schema-settings.d.ts +1800 -0
- package/dist/schema-settings.d.ts.map +1 -0
- package/dist/schema-settings.js +220 -0
- package/dist/schema-shared.d.ts +15 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +91 -0
- package/dist/schema-sourced-content.d.ts +262 -0
- package/dist/schema-sourced-content.d.ts.map +1 -0
- package/dist/schema-sourced-content.js +69 -0
- package/dist/schema-taxonomy.d.ts +1363 -0
- package/dist/schema-taxonomy.d.ts.map +1 -0
- package/dist/schema-taxonomy.js +203 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +9 -0
- package/dist/service-aggregates.d.ts +29 -0
- package/dist/service-aggregates.d.ts.map +1 -0
- package/dist/service-aggregates.js +56 -0
- package/dist/service-catalog-plane-destinations.d.ts +30 -0
- package/dist/service-catalog-plane-destinations.d.ts.map +1 -0
- package/dist/service-catalog-plane-destinations.js +143 -0
- package/dist/service-catalog-plane-taxonomy.d.ts +73 -0
- package/dist/service-catalog-plane-taxonomy.d.ts.map +1 -0
- package/dist/service-catalog-plane-taxonomy.js +242 -0
- package/dist/service-catalog-plane.d.ts +179 -0
- package/dist/service-catalog-plane.d.ts.map +1 -0
- package/dist/service-catalog-plane.js +431 -0
- package/dist/service-catalog.d.ts +251 -0
- package/dist/service-catalog.d.ts.map +1 -0
- package/dist/service-catalog.js +517 -0
- package/dist/service-configuration.d.ts +261 -0
- package/dist/service-configuration.d.ts.map +1 -0
- package/dist/service-configuration.js +343 -0
- package/dist/service-content-owned.d.ts +68 -0
- package/dist/service-content-owned.d.ts.map +1 -0
- package/dist/service-content-owned.js +329 -0
- package/dist/service-content-synthesizer.d.ts +90 -0
- package/dist/service-content-synthesizer.d.ts.map +1 -0
- package/dist/service-content-synthesizer.js +178 -0
- package/dist/service-content.d.ts +106 -0
- package/dist/service-content.d.ts.map +1 -0
- package/dist/service-content.js +388 -0
- package/dist/service-core.d.ts +194 -0
- package/dist/service-core.d.ts.map +1 -0
- package/dist/service-core.js +213 -0
- package/dist/service-delivery-formats.d.ts +58 -0
- package/dist/service-delivery-formats.d.ts.map +1 -0
- package/dist/service-delivery-formats.js +107 -0
- package/dist/service-destinations.d.ts +223 -0
- package/dist/service-destinations.d.ts.map +1 -0
- package/dist/service-destinations.js +310 -0
- package/dist/service-itinerary-history.d.ts +457 -0
- package/dist/service-itinerary-history.d.ts.map +1 -0
- package/dist/service-itinerary-history.js +135 -0
- package/dist/service-itinerary.d.ts +1149 -0
- package/dist/service-itinerary.d.ts.map +1 -0
- package/dist/service-itinerary.js +419 -0
- package/dist/service-media.d.ts +272 -0
- package/dist/service-media.d.ts.map +1 -0
- package/dist/service-media.js +320 -0
- package/dist/service-merchandising.d.ts +184 -0
- package/dist/service-merchandising.d.ts.map +1 -0
- package/dist/service-merchandising.js +181 -0
- package/dist/service-option-translations.d.ts +268 -0
- package/dist/service-option-translations.d.ts.map +1 -0
- package/dist/service-option-translations.js +300 -0
- package/dist/service-options.d.ts +181 -0
- package/dist/service-options.d.ts.map +1 -0
- package/dist/service-options.js +179 -0
- package/dist/service-product-destinations.d.ts +37 -0
- package/dist/service-product-destinations.d.ts.map +1 -0
- package/dist/service-product-destinations.js +94 -0
- package/dist/service-public.d.ts +664 -0
- package/dist/service-public.d.ts.map +1 -0
- package/dist/service-public.js +374 -0
- package/dist/service-taxonomy.d.ts +197 -0
- package/dist/service-taxonomy.d.ts.map +1 -0
- package/dist/service-taxonomy.js +221 -0
- package/dist/service.d.ts +3929 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +28 -0
- package/dist/tasks/brochure-printers.d.ts +31 -0
- package/dist/tasks/brochure-printers.d.ts.map +1 -0
- package/dist/tasks/brochure-printers.js +149 -0
- package/dist/tasks/brochure-templates.d.ts +36 -0
- package/dist/tasks/brochure-templates.d.ts.map +1 -0
- package/dist/tasks/brochure-templates.js +110 -0
- package/dist/tasks/brochures.d.ts +43 -0
- package/dist/tasks/brochures.d.ts.map +1 -0
- package/dist/tasks/brochures.js +72 -0
- package/dist/tasks/generate-pdf.d.ts +8 -0
- package/dist/tasks/generate-pdf.d.ts.map +1 -0
- package/dist/tasks/generate-pdf.js +106 -0
- package/dist/tasks/index.d.ts +5 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +4 -0
- package/dist/tasks/pdf-text.d.ts +2 -0
- package/dist/tasks/pdf-text.d.ts.map +1 -0
- package/dist/tasks/pdf-text.js +40 -0
- package/dist/tasks.d.ts +2 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +1 -0
- package/dist/validation-catalog.d.ts +2 -0
- package/dist/validation-catalog.d.ts.map +1 -0
- package/dist/validation-catalog.js +3 -0
- package/dist/validation-config.d.ts +2 -0
- package/dist/validation-config.d.ts.map +1 -0
- package/dist/validation-config.js +3 -0
- package/dist/validation-content.d.ts +2 -0
- package/dist/validation-content.d.ts.map +1 -0
- package/dist/validation-content.js +3 -0
- package/dist/validation-core.d.ts +2 -0
- package/dist/validation-core.d.ts.map +1 -0
- package/dist/validation-core.js +3 -0
- package/dist/validation-public.d.ts +2 -0
- package/dist/validation-public.d.ts.map +1 -0
- package/dist/validation-public.js +3 -0
- package/dist/validation-shared.d.ts +2 -0
- package/dist/validation-shared.d.ts.map +1 -0
- package/dist/validation-shared.js +3 -0
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +3 -0
- package/package.json +204 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extras content service — `getExtraContent` with locale-resolved
|
|
3
|
+
* cache reads, SWR refresh, and synthesizer fallback.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors `service-content.ts` in the products / cruises / accommodations
|
|
6
|
+
* / charters packages but extras-shaped. The extras content aggregate
|
|
7
|
+
* (§3.2 / §3.6) is `{ extra, options[], media[], policies[] }` — one
|
|
8
|
+
* payload returned by a single getContent. Pricing stays out (volatile-
|
|
9
|
+
* live, flows through `liveResolve`).
|
|
10
|
+
*
|
|
11
|
+
* Extras don't appear in the search index (per the vertical's catalog-
|
|
12
|
+
* policy.ts), but sourced extras still need rich content for the
|
|
13
|
+
* booking-flow's add-on selection UI. The cache layer covers exactly
|
|
14
|
+
* that surface.
|
|
15
|
+
*/
|
|
16
|
+
import { createInvalidateOnDrift, fetchOverlaysForEntity, isStale, pickBestCachedLocale, readSourcedEntry, withContentRefreshLock, } from "@voyant-travel/catalog";
|
|
17
|
+
import { and, eq } from "drizzle-orm";
|
|
18
|
+
import { EXTRAS_CONTENT_SCHEMA_VERSION, extraContentSchema, mergeOverlaysIntoExtraContent, validateExtraContent, } from "./content-shape.js";
|
|
19
|
+
import { EXTRAS_CONTENT_MARKET_ANY, extrasSourcedContentTable, } from "./schema-sourced-content.js";
|
|
20
|
+
import { synthesizeExtraContent, } from "./service-content-synthesizer.js";
|
|
21
|
+
/** Extras cache TTL is 24h — same as products. */
|
|
22
|
+
const EXTRAS_DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
export async function getExtraContent(db, entityId, scope, options) {
|
|
24
|
+
const sourcedEntry = await readSourcedEntry(db, "extras", entityId);
|
|
25
|
+
if (!sourcedEntry)
|
|
26
|
+
return null;
|
|
27
|
+
const provenance = {
|
|
28
|
+
kind: "sourced",
|
|
29
|
+
provenance: {
|
|
30
|
+
source_kind: sourcedEntry.source_kind,
|
|
31
|
+
source_provider: sourcedEntry.source_provider ?? undefined,
|
|
32
|
+
source_connection_id: sourcedEntry.source_connection_id ?? undefined,
|
|
33
|
+
source_ref: sourcedEntry.source_ref ?? undefined,
|
|
34
|
+
source_freshness: sourcedEntry.source_freshness,
|
|
35
|
+
last_sourced_at: sourcedEntry.last_sourced_at ?? undefined,
|
|
36
|
+
},
|
|
37
|
+
entry_id: sourcedEntry.id,
|
|
38
|
+
status: sourcedEntry.status,
|
|
39
|
+
projection: sourcedEntry.projection,
|
|
40
|
+
projection_etag: sourcedEntry.projection_etag,
|
|
41
|
+
projection_seen_at: sourcedEntry.projection_seen_at,
|
|
42
|
+
first_seen_at: sourcedEntry.first_seen_at,
|
|
43
|
+
last_seen_at: sourcedEntry.last_seen_at,
|
|
44
|
+
};
|
|
45
|
+
const adapter = sourcedEntry.source_connection_id
|
|
46
|
+
? (options.registry.resolveByConnection(sourcedEntry.source_connection_id) ??
|
|
47
|
+
options.registry.byKind(sourcedEntry.source_kind)[0]?.adapter)
|
|
48
|
+
: options.registry.byKind(sourcedEntry.source_kind)[0]?.adapter;
|
|
49
|
+
const adapterCtx = options.buildAdapterContext?.(adapter) ?? {
|
|
50
|
+
connection_id: sourcedEntry.source_connection_id ?? sourcedEntry.source_kind,
|
|
51
|
+
};
|
|
52
|
+
const market = scope.market ?? EXTRAS_CONTENT_MARKET_ANY;
|
|
53
|
+
const acceptMT = scope.acceptMachineTranslated ?? true;
|
|
54
|
+
const cachedRows = await fetchCacheCandidates(db, entityId, market);
|
|
55
|
+
const eligibleRows = acceptMT ? cachedRows : cachedRows.filter((r) => !r.machine_translated);
|
|
56
|
+
const best = pickBestCachedLocale(eligibleRows.map((row) => ({ ...row, locale: row.locale })), scope.preferredLocales);
|
|
57
|
+
if (best && !isStale(best.candidate)) {
|
|
58
|
+
return finalizeFromCache(db, entityId, best, false, options);
|
|
59
|
+
}
|
|
60
|
+
if (best && isStale(best.candidate)) {
|
|
61
|
+
if (adapter?.getContent) {
|
|
62
|
+
void scheduleRefresh(db, adapter, adapterCtx, {
|
|
63
|
+
entity_module: "extras",
|
|
64
|
+
entity_id: entityId,
|
|
65
|
+
locale: scope.preferredLocales[0] ?? best.candidate.locale,
|
|
66
|
+
market,
|
|
67
|
+
currency: scope.currency,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return finalizeFromCache(db, entityId, best, true, options);
|
|
71
|
+
}
|
|
72
|
+
if (!adapter?.getContent) {
|
|
73
|
+
const overlays = await fetchOverlaysForEntity(db, "extras", entityId);
|
|
74
|
+
const synthesized = synthesizeExtraContent({ locale: scope.preferredLocales[0] ?? "en-GB" }, {
|
|
75
|
+
provenance,
|
|
76
|
+
overlays: overlays.map((o) => ({ field_path: o.field_path, value: o.value })),
|
|
77
|
+
});
|
|
78
|
+
return wrapSynthesized(synthesized, scope, false);
|
|
79
|
+
}
|
|
80
|
+
const fresh = await fetchFreshContent(db, adapter, adapterCtx, {
|
|
81
|
+
entity_module: "extras",
|
|
82
|
+
entity_id: entityId,
|
|
83
|
+
locale: scope.preferredLocales[0] ?? "en-GB",
|
|
84
|
+
market,
|
|
85
|
+
currency: scope.currency,
|
|
86
|
+
});
|
|
87
|
+
if (!fresh) {
|
|
88
|
+
const overlays = await fetchOverlaysForEntity(db, "extras", entityId);
|
|
89
|
+
const synthesized = synthesizeExtraContent({ locale: scope.preferredLocales[0] ?? "en-GB" }, {
|
|
90
|
+
provenance,
|
|
91
|
+
overlays: overlays.map((o) => ({ field_path: o.field_path, value: o.value })),
|
|
92
|
+
});
|
|
93
|
+
return wrapSynthesized(synthesized, scope, false);
|
|
94
|
+
}
|
|
95
|
+
return finalizeFresh(db, entityId, fresh, scope, options);
|
|
96
|
+
}
|
|
97
|
+
async function fetchCacheCandidates(db, entityId, market) {
|
|
98
|
+
return db
|
|
99
|
+
.select()
|
|
100
|
+
.from(extrasSourcedContentTable)
|
|
101
|
+
.where(and(eq(extrasSourcedContentTable.entity_id, entityId), eq(extrasSourcedContentTable.market, market), eq(extrasSourcedContentTable.content_schema_version, EXTRAS_CONTENT_SCHEMA_VERSION)));
|
|
102
|
+
}
|
|
103
|
+
async function fetchFreshContent(db, adapter, ctx, request) {
|
|
104
|
+
const result = await withContentRefreshLock(db, {
|
|
105
|
+
entityModule: request.entity_module,
|
|
106
|
+
entityId: request.entity_id,
|
|
107
|
+
locale: request.locale,
|
|
108
|
+
market: request.market,
|
|
109
|
+
}, async () => {
|
|
110
|
+
const got = await adapter.getContent(ctx, request);
|
|
111
|
+
const validation = validateExtraContent(got.content);
|
|
112
|
+
if (!validation.valid) {
|
|
113
|
+
throw new Error(`extras getContent for ${request.entity_id} failed validation: ${validation.reason}`);
|
|
114
|
+
}
|
|
115
|
+
await writeCacheRow(db, request, got);
|
|
116
|
+
return got;
|
|
117
|
+
});
|
|
118
|
+
return result ?? null;
|
|
119
|
+
}
|
|
120
|
+
function scheduleRefresh(db, adapter, ctx, request) {
|
|
121
|
+
void withContentRefreshLock(db, {
|
|
122
|
+
entityModule: request.entity_module,
|
|
123
|
+
entityId: request.entity_id,
|
|
124
|
+
locale: request.locale,
|
|
125
|
+
market: request.market,
|
|
126
|
+
}, async () => {
|
|
127
|
+
const got = await adapter.getContent(ctx, request);
|
|
128
|
+
const validation = validateExtraContent(got.content);
|
|
129
|
+
if (!validation.valid)
|
|
130
|
+
return;
|
|
131
|
+
await writeCacheRow(db, request, got);
|
|
132
|
+
}).catch(() => {
|
|
133
|
+
// intentional swallow — see §3.4 SWR refresh contract
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async function writeCacheRow(db, request, result) {
|
|
137
|
+
const market = request.market ?? EXTRAS_CONTENT_MARKET_ANY;
|
|
138
|
+
const now = new Date();
|
|
139
|
+
// Coerce JSON-string dates to Date — see products writeCacheRow.
|
|
140
|
+
const sourceUpdatedAt = toDateOrNull(result.source_updated_at);
|
|
141
|
+
const freshUntil = toDateOrNull(result.fresh_until) ?? new Date(now.getTime() + EXTRAS_DEFAULT_TTL_MS);
|
|
142
|
+
await db
|
|
143
|
+
.insert(extrasSourcedContentTable)
|
|
144
|
+
.values({
|
|
145
|
+
entity_id: request.entity_id,
|
|
146
|
+
locale: request.locale,
|
|
147
|
+
market,
|
|
148
|
+
payload: result.content,
|
|
149
|
+
content_schema_version: result.content_schema_version,
|
|
150
|
+
returned_locale: result.returned_locale,
|
|
151
|
+
machine_translated: result.machine_translated ?? false,
|
|
152
|
+
source_updated_at: sourceUpdatedAt,
|
|
153
|
+
fetched_at: now,
|
|
154
|
+
fresh_until: freshUntil,
|
|
155
|
+
etag: result.etag ?? null,
|
|
156
|
+
fetch_status: "ok",
|
|
157
|
+
fetch_error: null,
|
|
158
|
+
})
|
|
159
|
+
.onConflictDoUpdate({
|
|
160
|
+
target: [
|
|
161
|
+
extrasSourcedContentTable.entity_id,
|
|
162
|
+
extrasSourcedContentTable.locale,
|
|
163
|
+
extrasSourcedContentTable.market,
|
|
164
|
+
],
|
|
165
|
+
set: {
|
|
166
|
+
payload: result.content,
|
|
167
|
+
content_schema_version: result.content_schema_version,
|
|
168
|
+
returned_locale: result.returned_locale,
|
|
169
|
+
machine_translated: result.machine_translated ?? false,
|
|
170
|
+
source_updated_at: sourceUpdatedAt,
|
|
171
|
+
fetched_at: now,
|
|
172
|
+
fresh_until: freshUntil,
|
|
173
|
+
etag: result.etag ?? null,
|
|
174
|
+
fetch_status: "ok",
|
|
175
|
+
fetch_error: null,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async function finalizeFromCache(db, entityId, best, servedStale, options) {
|
|
180
|
+
const validation = validateExtraContent(best.candidate.payload);
|
|
181
|
+
if (!validation.valid) {
|
|
182
|
+
throw new Error(`extras cache row for ${entityId} (${best.candidate.locale}) failed validation: ${validation.reason}`);
|
|
183
|
+
}
|
|
184
|
+
const overlays = await fetchOverlaysForEntity(db, "extras", entityId);
|
|
185
|
+
const merged = mergeOverlaysIntoExtraContent(validation.content, overlays.map((o) => ({ field_path: o.field_path, value: o.value })), {
|
|
186
|
+
onOverlayError: options.onOverlayError
|
|
187
|
+
? (e) => options.onOverlayError({
|
|
188
|
+
field_path: e.overlay.field_path,
|
|
189
|
+
reason: e.reason,
|
|
190
|
+
})
|
|
191
|
+
: undefined,
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
content: merged,
|
|
195
|
+
resolution: {
|
|
196
|
+
candidate: { locale: best.candidate.locale, payload: merged },
|
|
197
|
+
served_locale: best.candidate.returned_locale,
|
|
198
|
+
match_kind: best.match_kind,
|
|
199
|
+
},
|
|
200
|
+
source: "sourced-cache",
|
|
201
|
+
served_stale: servedStale,
|
|
202
|
+
synthesized: false,
|
|
203
|
+
machine_translated: best.candidate.machine_translated,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function finalizeFresh(db, entityId, fresh, scope, options) {
|
|
207
|
+
const cachedContent = extraContentSchema.parse(fresh.content);
|
|
208
|
+
const overlays = await fetchOverlaysForEntity(db, "extras", entityId);
|
|
209
|
+
const merged = mergeOverlaysIntoExtraContent(cachedContent, overlays.map((o) => ({ field_path: o.field_path, value: o.value })), {
|
|
210
|
+
onOverlayError: options.onOverlayError
|
|
211
|
+
? (e) => options.onOverlayError({
|
|
212
|
+
field_path: e.overlay.field_path,
|
|
213
|
+
reason: e.reason,
|
|
214
|
+
})
|
|
215
|
+
: undefined,
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
content: merged,
|
|
219
|
+
resolution: {
|
|
220
|
+
candidate: { locale: scope.preferredLocales[0] ?? fresh.returned_locale, payload: merged },
|
|
221
|
+
served_locale: fresh.returned_locale,
|
|
222
|
+
match_kind: scope.preferredLocales[0] === fresh.returned_locale ? "exact" : "language_match",
|
|
223
|
+
},
|
|
224
|
+
source: "sourced-fresh",
|
|
225
|
+
served_stale: false,
|
|
226
|
+
synthesized: false,
|
|
227
|
+
machine_translated: fresh.machine_translated ?? false,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function wrapSynthesized(synthesized, scope, servedStale) {
|
|
231
|
+
return {
|
|
232
|
+
content: synthesized.content,
|
|
233
|
+
resolution: {
|
|
234
|
+
candidate: { locale: synthesized.served_locale, payload: synthesized.content },
|
|
235
|
+
served_locale: synthesized.served_locale,
|
|
236
|
+
match_kind: scope.preferredLocales[0] === synthesized.served_locale ? "exact" : "any",
|
|
237
|
+
},
|
|
238
|
+
source: "synthesized",
|
|
239
|
+
served_stale: servedStale,
|
|
240
|
+
synthesized: true,
|
|
241
|
+
machine_translated: false,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Drift event consumer for the extras content cache. Per §3.4.1. */
|
|
245
|
+
export const invalidateExtraContentOnDrift = createInvalidateOnDrift(extrasSourcedContentTable, { entityModule: "extras" });
|
|
246
|
+
function toDateOrNull(value) {
|
|
247
|
+
if (!value)
|
|
248
|
+
return null;
|
|
249
|
+
if (value instanceof Date)
|
|
250
|
+
return value;
|
|
251
|
+
const parsed = new Date(value);
|
|
252
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
253
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { insertOptionExtraConfigSchema, insertProductExtraSchema, optionExtraConfigListQuerySchema, productExtraListQuerySchema, updateOptionExtraConfigSchema, updateProductExtraSchema } from "./validation.js";
|
|
4
|
+
type ProductExtraListQuery = z.infer<typeof productExtraListQuerySchema>;
|
|
5
|
+
type OptionExtraConfigListQuery = z.infer<typeof optionExtraConfigListQuerySchema>;
|
|
6
|
+
type CreateProductExtraInput = z.infer<typeof insertProductExtraSchema>;
|
|
7
|
+
type UpdateProductExtraInput = z.infer<typeof updateProductExtraSchema>;
|
|
8
|
+
type CreateOptionExtraConfigInput = z.infer<typeof insertOptionExtraConfigSchema>;
|
|
9
|
+
type UpdateOptionExtraConfigInput = z.infer<typeof updateOptionExtraConfigSchema>;
|
|
10
|
+
export declare const inventoryExtrasService: {
|
|
11
|
+
listProductExtras(db: PostgresJsDatabase, query: ProductExtraListQuery): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
id: string;
|
|
14
|
+
productId: string;
|
|
15
|
+
supplierId: string | null;
|
|
16
|
+
code: string | null;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string | null;
|
|
19
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected";
|
|
20
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free";
|
|
21
|
+
pricedPerPerson: boolean;
|
|
22
|
+
collectionMode: "none" | "external" | "included" | "booking_total" | "cash_on_trip";
|
|
23
|
+
showOnSlotManifest: boolean;
|
|
24
|
+
minQuantity: number | null;
|
|
25
|
+
maxQuantity: number | null;
|
|
26
|
+
defaultQuantity: number | null;
|
|
27
|
+
active: boolean;
|
|
28
|
+
sortOrder: number;
|
|
29
|
+
metadata: Record<string, unknown> | null;
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
}[];
|
|
33
|
+
total: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
}>;
|
|
37
|
+
getProductExtraById(db: PostgresJsDatabase, id: string): Promise<{
|
|
38
|
+
id: string;
|
|
39
|
+
productId: string;
|
|
40
|
+
supplierId: string | null;
|
|
41
|
+
code: string | null;
|
|
42
|
+
name: string;
|
|
43
|
+
description: string | null;
|
|
44
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected";
|
|
45
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free";
|
|
46
|
+
pricedPerPerson: boolean;
|
|
47
|
+
collectionMode: "none" | "external" | "included" | "booking_total" | "cash_on_trip";
|
|
48
|
+
showOnSlotManifest: boolean;
|
|
49
|
+
minQuantity: number | null;
|
|
50
|
+
maxQuantity: number | null;
|
|
51
|
+
defaultQuantity: number | null;
|
|
52
|
+
active: boolean;
|
|
53
|
+
sortOrder: number;
|
|
54
|
+
metadata: Record<string, unknown> | null;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
updatedAt: Date;
|
|
57
|
+
} | null>;
|
|
58
|
+
createProductExtra(db: PostgresJsDatabase, data: CreateProductExtraInput): Promise<{
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
createdAt: Date;
|
|
62
|
+
description: string | null;
|
|
63
|
+
active: boolean;
|
|
64
|
+
supplierId: string | null;
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
productId: string;
|
|
67
|
+
code: string | null;
|
|
68
|
+
sortOrder: number;
|
|
69
|
+
minQuantity: number | null;
|
|
70
|
+
maxQuantity: number | null;
|
|
71
|
+
metadata: Record<string, unknown> | null;
|
|
72
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected";
|
|
73
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free";
|
|
74
|
+
pricedPerPerson: boolean;
|
|
75
|
+
collectionMode: "none" | "external" | "included" | "booking_total" | "cash_on_trip";
|
|
76
|
+
showOnSlotManifest: boolean;
|
|
77
|
+
defaultQuantity: number | null;
|
|
78
|
+
} | null>;
|
|
79
|
+
updateProductExtra(db: PostgresJsDatabase, id: string, data: UpdateProductExtraInput): Promise<{
|
|
80
|
+
id: string;
|
|
81
|
+
productId: string;
|
|
82
|
+
supplierId: string | null;
|
|
83
|
+
code: string | null;
|
|
84
|
+
name: string;
|
|
85
|
+
description: string | null;
|
|
86
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected";
|
|
87
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free";
|
|
88
|
+
pricedPerPerson: boolean;
|
|
89
|
+
collectionMode: "none" | "external" | "included" | "booking_total" | "cash_on_trip";
|
|
90
|
+
showOnSlotManifest: boolean;
|
|
91
|
+
minQuantity: number | null;
|
|
92
|
+
maxQuantity: number | null;
|
|
93
|
+
defaultQuantity: number | null;
|
|
94
|
+
active: boolean;
|
|
95
|
+
sortOrder: number;
|
|
96
|
+
metadata: Record<string, unknown> | null;
|
|
97
|
+
createdAt: Date;
|
|
98
|
+
updatedAt: Date;
|
|
99
|
+
} | null>;
|
|
100
|
+
deleteProductExtra(db: PostgresJsDatabase, id: string): Promise<{
|
|
101
|
+
id: string;
|
|
102
|
+
} | null>;
|
|
103
|
+
listOptionExtraConfigs(db: PostgresJsDatabase, query: OptionExtraConfigListQuery): Promise<{
|
|
104
|
+
data: {
|
|
105
|
+
id: string;
|
|
106
|
+
optionId: string;
|
|
107
|
+
productExtraId: string;
|
|
108
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected" | null;
|
|
109
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free" | null;
|
|
110
|
+
pricedPerPerson: boolean | null;
|
|
111
|
+
minQuantity: number | null;
|
|
112
|
+
maxQuantity: number | null;
|
|
113
|
+
defaultQuantity: number | null;
|
|
114
|
+
isDefault: boolean;
|
|
115
|
+
active: boolean;
|
|
116
|
+
sortOrder: number;
|
|
117
|
+
notes: string | null;
|
|
118
|
+
metadata: Record<string, unknown> | null;
|
|
119
|
+
createdAt: Date;
|
|
120
|
+
updatedAt: Date;
|
|
121
|
+
}[];
|
|
122
|
+
total: number;
|
|
123
|
+
limit: number;
|
|
124
|
+
offset: number;
|
|
125
|
+
}>;
|
|
126
|
+
getOptionExtraConfigById(db: PostgresJsDatabase, id: string): Promise<{
|
|
127
|
+
id: string;
|
|
128
|
+
optionId: string;
|
|
129
|
+
productExtraId: string;
|
|
130
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected" | null;
|
|
131
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free" | null;
|
|
132
|
+
pricedPerPerson: boolean | null;
|
|
133
|
+
minQuantity: number | null;
|
|
134
|
+
maxQuantity: number | null;
|
|
135
|
+
defaultQuantity: number | null;
|
|
136
|
+
isDefault: boolean;
|
|
137
|
+
active: boolean;
|
|
138
|
+
sortOrder: number;
|
|
139
|
+
notes: string | null;
|
|
140
|
+
metadata: Record<string, unknown> | null;
|
|
141
|
+
createdAt: Date;
|
|
142
|
+
updatedAt: Date;
|
|
143
|
+
} | null>;
|
|
144
|
+
createOptionExtraConfig(db: PostgresJsDatabase, data: CreateOptionExtraConfigInput): Promise<{
|
|
145
|
+
id: string;
|
|
146
|
+
createdAt: Date;
|
|
147
|
+
active: boolean;
|
|
148
|
+
updatedAt: Date;
|
|
149
|
+
isDefault: boolean;
|
|
150
|
+
sortOrder: number;
|
|
151
|
+
optionId: string;
|
|
152
|
+
minQuantity: number | null;
|
|
153
|
+
maxQuantity: number | null;
|
|
154
|
+
notes: string | null;
|
|
155
|
+
metadata: Record<string, unknown> | null;
|
|
156
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected" | null;
|
|
157
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free" | null;
|
|
158
|
+
pricedPerPerson: boolean | null;
|
|
159
|
+
defaultQuantity: number | null;
|
|
160
|
+
productExtraId: string;
|
|
161
|
+
} | null>;
|
|
162
|
+
updateOptionExtraConfig(db: PostgresJsDatabase, id: string, data: UpdateOptionExtraConfigInput): Promise<{
|
|
163
|
+
id: string;
|
|
164
|
+
optionId: string;
|
|
165
|
+
productExtraId: string;
|
|
166
|
+
selectionType: "required" | "optional" | "unavailable" | "default_selected" | null;
|
|
167
|
+
pricingMode: "on_request" | "per_booking" | "included" | "per_person" | "quantity_based" | "free" | null;
|
|
168
|
+
pricedPerPerson: boolean | null;
|
|
169
|
+
minQuantity: number | null;
|
|
170
|
+
maxQuantity: number | null;
|
|
171
|
+
defaultQuantity: number | null;
|
|
172
|
+
isDefault: boolean;
|
|
173
|
+
active: boolean;
|
|
174
|
+
sortOrder: number;
|
|
175
|
+
notes: string | null;
|
|
176
|
+
metadata: Record<string, unknown> | null;
|
|
177
|
+
createdAt: Date;
|
|
178
|
+
updatedAt: Date;
|
|
179
|
+
} | null>;
|
|
180
|
+
deleteOptionExtraConfig(db: PostgresJsDatabase, id: string): Promise<{
|
|
181
|
+
id: string;
|
|
182
|
+
} | null>;
|
|
183
|
+
};
|
|
184
|
+
export {};
|
|
185
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/extras/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAG5B,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,iBAAiB,CAAA;AAExB,KAAK,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA;AACxE,KAAK,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAClF,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AACvE,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AACvE,KAAK,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AACjF,KAAK,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAYjF,eAAO,MAAM,sBAAsB;0BACL,kBAAkB,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;4BAwB9C,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;2BAK/B,kBAAkB,QAAQ,uBAAuB;;;;;;;;;;;;;;;;;;;;;2BAKjD,kBAAkB,MAAM,MAAM,QAAQ,uBAAuB;;;;;;;;;;;;;;;;;;;;;2BAS7D,kBAAkB,MAAM,MAAM;;;+BAQ1B,kBAAkB,SAAS,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;iCAqBnD,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;;;gCAS/B,kBAAkB,QAAQ,4BAA4B;;;;;;;;;;;;;;;;;;gCAMlF,kBAAkB,MAClB,MAAM,QACJ,4BAA4B;;;;;;;;;;;;;;;;;;gCAUF,kBAAkB,MAAM,MAAM;;;CAOjE,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
|
|
2
|
+
import { optionExtraConfigs, productExtras } 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
|
+
export const inventoryExtrasService = {
|
|
8
|
+
async listProductExtras(db, query) {
|
|
9
|
+
const conditions = [];
|
|
10
|
+
if (query.productId)
|
|
11
|
+
conditions.push(eq(productExtras.productId, query.productId));
|
|
12
|
+
if (query.supplierId)
|
|
13
|
+
conditions.push(eq(productExtras.supplierId, query.supplierId));
|
|
14
|
+
if (query.active !== undefined)
|
|
15
|
+
conditions.push(eq(productExtras.active, query.active));
|
|
16
|
+
if (query.search) {
|
|
17
|
+
const term = `%${query.search}%`;
|
|
18
|
+
conditions.push(or(ilike(productExtras.name, term), ilike(productExtras.code, term)));
|
|
19
|
+
}
|
|
20
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
21
|
+
return paginate(db
|
|
22
|
+
.select()
|
|
23
|
+
.from(productExtras)
|
|
24
|
+
.where(where)
|
|
25
|
+
.limit(query.limit)
|
|
26
|
+
.offset(query.offset)
|
|
27
|
+
.orderBy(asc(productExtras.sortOrder), asc(productExtras.name)), db.select({ count: sql `count(*)::int` }).from(productExtras).where(where), query.limit, query.offset);
|
|
28
|
+
},
|
|
29
|
+
async getProductExtraById(db, id) {
|
|
30
|
+
const [row] = await db.select().from(productExtras).where(eq(productExtras.id, id)).limit(1);
|
|
31
|
+
return row ?? null;
|
|
32
|
+
},
|
|
33
|
+
async createProductExtra(db, data) {
|
|
34
|
+
const [row] = await db.insert(productExtras).values(data).returning();
|
|
35
|
+
return row ?? null;
|
|
36
|
+
},
|
|
37
|
+
async updateProductExtra(db, id, data) {
|
|
38
|
+
const [row] = await db
|
|
39
|
+
.update(productExtras)
|
|
40
|
+
.set({ ...data, updatedAt: new Date() })
|
|
41
|
+
.where(eq(productExtras.id, id))
|
|
42
|
+
.returning();
|
|
43
|
+
return row ?? null;
|
|
44
|
+
},
|
|
45
|
+
async deleteProductExtra(db, id) {
|
|
46
|
+
const [row] = await db
|
|
47
|
+
.delete(productExtras)
|
|
48
|
+
.where(eq(productExtras.id, id))
|
|
49
|
+
.returning({ id: productExtras.id });
|
|
50
|
+
return row ?? null;
|
|
51
|
+
},
|
|
52
|
+
async listOptionExtraConfigs(db, query) {
|
|
53
|
+
const conditions = [];
|
|
54
|
+
if (query.optionId)
|
|
55
|
+
conditions.push(eq(optionExtraConfigs.optionId, query.optionId));
|
|
56
|
+
if (query.productExtraId)
|
|
57
|
+
conditions.push(eq(optionExtraConfigs.productExtraId, query.productExtraId));
|
|
58
|
+
if (query.active !== undefined)
|
|
59
|
+
conditions.push(eq(optionExtraConfigs.active, query.active));
|
|
60
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
61
|
+
return paginate(db
|
|
62
|
+
.select()
|
|
63
|
+
.from(optionExtraConfigs)
|
|
64
|
+
.where(where)
|
|
65
|
+
.limit(query.limit)
|
|
66
|
+
.offset(query.offset)
|
|
67
|
+
.orderBy(asc(optionExtraConfigs.sortOrder), desc(optionExtraConfigs.isDefault)), db.select({ count: sql `count(*)::int` }).from(optionExtraConfigs).where(where), query.limit, query.offset);
|
|
68
|
+
},
|
|
69
|
+
async getOptionExtraConfigById(db, id) {
|
|
70
|
+
const [row] = await db
|
|
71
|
+
.select()
|
|
72
|
+
.from(optionExtraConfigs)
|
|
73
|
+
.where(eq(optionExtraConfigs.id, id))
|
|
74
|
+
.limit(1);
|
|
75
|
+
return row ?? null;
|
|
76
|
+
},
|
|
77
|
+
async createOptionExtraConfig(db, data) {
|
|
78
|
+
const [row] = await db.insert(optionExtraConfigs).values(data).returning();
|
|
79
|
+
return row ?? null;
|
|
80
|
+
},
|
|
81
|
+
async updateOptionExtraConfig(db, id, data) {
|
|
82
|
+
const [row] = await db
|
|
83
|
+
.update(optionExtraConfigs)
|
|
84
|
+
.set({ ...data, updatedAt: new Date() })
|
|
85
|
+
.where(eq(optionExtraConfigs.id, id))
|
|
86
|
+
.returning();
|
|
87
|
+
return row ?? null;
|
|
88
|
+
},
|
|
89
|
+
async deleteOptionExtraConfig(db, id) {
|
|
90
|
+
const [row] = await db
|
|
91
|
+
.delete(optionExtraConfigs)
|
|
92
|
+
.where(eq(optionExtraConfigs.id, id))
|
|
93
|
+
.returning({ id: optionExtraConfigs.id });
|
|
94
|
+
return row ?? null;
|
|
95
|
+
},
|
|
96
|
+
};
|