@voyantjs/extras 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":"AAcA,eAAO,MAAM,sBAAsB,mGAKjC,CAAA;AAEF,eAAO,MAAM,oBAAoB,yHAO/B,CAAA;AAEF,eAAO,MAAM,sBAAsB,oGAMjC,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBzB,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B9B,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCzB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC5D,MAAM,MAAM,eAAe,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC/D,MAAM,MAAM,iBAAiB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAA;AACtE,MAAM,MAAM,oBAAoB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAA;AACzE,MAAM,MAAM,YAAY,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC5D,MAAM,MAAM,eAAe,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAE/D,eAAO,MAAM,sBAAsB;;;EAGhC,CAAA;AAEH,eAAO,MAAM,2BAA2B;;;EAMrC,CAAA;AAEH,eAAO,MAAM,sBAAsB;;;EAShC,CAAA"}
package/dist/schema.js ADDED
@@ -0,0 +1,123 @@
1
+ import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
2
+ import { relations } from "drizzle-orm";
3
+ import { boolean, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
4
+ export const extraSelectionTypeEnum = pgEnum("extra_selection_type", [
5
+ "optional",
6
+ "required",
7
+ "default_selected",
8
+ "unavailable",
9
+ ]);
10
+ export const extraPricingModeEnum = pgEnum("extra_pricing_mode", [
11
+ "included",
12
+ "per_person",
13
+ "per_booking",
14
+ "quantity_based",
15
+ "on_request",
16
+ "free",
17
+ ]);
18
+ export const bookingExtraStatusEnum = pgEnum("booking_extra_status", [
19
+ "draft",
20
+ "selected",
21
+ "confirmed",
22
+ "cancelled",
23
+ "fulfilled",
24
+ ]);
25
+ export const productExtras = pgTable("product_extras", {
26
+ id: typeId("product_extras"),
27
+ productId: text("product_id").notNull(),
28
+ code: text("code"),
29
+ name: text("name").notNull(),
30
+ description: text("description"),
31
+ selectionType: extraSelectionTypeEnum("selection_type").notNull().default("optional"),
32
+ pricingMode: extraPricingModeEnum("pricing_mode").notNull().default("per_booking"),
33
+ pricedPerPerson: boolean("priced_per_person").notNull().default(false),
34
+ minQuantity: integer("min_quantity"),
35
+ maxQuantity: integer("max_quantity"),
36
+ defaultQuantity: integer("default_quantity"),
37
+ active: boolean("active").notNull().default(true),
38
+ sortOrder: integer("sort_order").notNull().default(0),
39
+ metadata: jsonb("metadata").$type(),
40
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
41
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
42
+ }, (table) => [
43
+ index("idx_product_extras_product").on(table.productId),
44
+ index("idx_product_extras_active").on(table.active),
45
+ uniqueIndex("uidx_product_extras_product_code").on(table.productId, table.code),
46
+ ]);
47
+ export const optionExtraConfigs = pgTable("option_extra_configs", {
48
+ id: typeId("option_extra_configs"),
49
+ optionId: text("option_id").notNull(),
50
+ productExtraId: typeIdRef("product_extra_id")
51
+ .notNull()
52
+ .references(() => productExtras.id, { onDelete: "cascade" }),
53
+ selectionType: extraSelectionTypeEnum("selection_type"),
54
+ pricingMode: extraPricingModeEnum("pricing_mode"),
55
+ pricedPerPerson: boolean("priced_per_person"),
56
+ minQuantity: integer("min_quantity"),
57
+ maxQuantity: integer("max_quantity"),
58
+ defaultQuantity: integer("default_quantity"),
59
+ isDefault: boolean("is_default").notNull().default(false),
60
+ active: boolean("active").notNull().default(true),
61
+ sortOrder: integer("sort_order").notNull().default(0),
62
+ notes: text("notes"),
63
+ metadata: jsonb("metadata").$type(),
64
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
65
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
66
+ }, (table) => [
67
+ index("idx_option_extra_configs_option").on(table.optionId),
68
+ index("idx_option_extra_configs_extra").on(table.productExtraId),
69
+ index("idx_option_extra_configs_active").on(table.active),
70
+ uniqueIndex("uidx_option_extra_configs_option_extra").on(table.optionId, table.productExtraId),
71
+ ]);
72
+ export const bookingExtras = pgTable("booking_extras", {
73
+ id: typeId("booking_extras"),
74
+ bookingId: text("booking_id").notNull(),
75
+ productExtraId: typeIdRef("product_extra_id").references(() => productExtras.id, {
76
+ onDelete: "set null",
77
+ }),
78
+ optionExtraConfigId: typeIdRef("option_extra_config_id").references(() => optionExtraConfigs.id, {
79
+ onDelete: "set null",
80
+ }),
81
+ name: text("name").notNull(),
82
+ description: text("description"),
83
+ status: bookingExtraStatusEnum("status").notNull().default("draft"),
84
+ pricingMode: extraPricingModeEnum("pricing_mode").notNull().default("per_booking"),
85
+ pricedPerPerson: boolean("priced_per_person").notNull().default(false),
86
+ quantity: integer("quantity").notNull().default(1),
87
+ sellCurrency: text("sell_currency").notNull(),
88
+ unitSellAmountCents: integer("unit_sell_amount_cents"),
89
+ totalSellAmountCents: integer("total_sell_amount_cents"),
90
+ costCurrency: text("cost_currency"),
91
+ unitCostAmountCents: integer("unit_cost_amount_cents"),
92
+ totalCostAmountCents: integer("total_cost_amount_cents"),
93
+ notes: text("notes"),
94
+ metadata: jsonb("metadata").$type(),
95
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
96
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
97
+ }, (table) => [
98
+ index("idx_booking_extras_booking").on(table.bookingId),
99
+ index("idx_booking_extras_product_extra").on(table.productExtraId),
100
+ index("idx_booking_extras_option_extra_config").on(table.optionExtraConfigId),
101
+ index("idx_booking_extras_status").on(table.status),
102
+ ]);
103
+ export const productExtrasRelations = relations(productExtras, ({ many }) => ({
104
+ optionConfigs: many(optionExtraConfigs),
105
+ bookingExtras: many(bookingExtras),
106
+ }));
107
+ export const optionExtraConfigsRelations = relations(optionExtraConfigs, ({ one, many }) => ({
108
+ productExtra: one(productExtras, {
109
+ fields: [optionExtraConfigs.productExtraId],
110
+ references: [productExtras.id],
111
+ }),
112
+ bookingExtras: many(bookingExtras),
113
+ }));
114
+ export const bookingExtrasRelations = relations(bookingExtras, ({ one }) => ({
115
+ productExtra: one(productExtras, {
116
+ fields: [bookingExtras.productExtraId],
117
+ references: [productExtras.id],
118
+ }),
119
+ optionExtraConfig: one(optionExtraConfigs, {
120
+ fields: [bookingExtras.optionExtraConfigId],
121
+ references: [optionExtraConfigs.id],
122
+ }),
123
+ }));
@@ -0,0 +1,272 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { z } from "zod";
3
+ import type { bookingExtraListQuerySchema, insertBookingExtraSchema, insertOptionExtraConfigSchema, insertProductExtraSchema, optionExtraConfigListQuerySchema, productExtraListQuerySchema, updateBookingExtraSchema, updateOptionExtraConfigSchema, updateProductExtraSchema } from "./validation.js";
4
+ type ProductExtraListQuery = z.infer<typeof productExtraListQuerySchema>;
5
+ type OptionExtraConfigListQuery = z.infer<typeof optionExtraConfigListQuerySchema>;
6
+ type BookingExtraListQuery = z.infer<typeof bookingExtraListQuerySchema>;
7
+ type CreateProductExtraInput = z.infer<typeof insertProductExtraSchema>;
8
+ type UpdateProductExtraInput = z.infer<typeof updateProductExtraSchema>;
9
+ type CreateOptionExtraConfigInput = z.infer<typeof insertOptionExtraConfigSchema>;
10
+ type UpdateOptionExtraConfigInput = z.infer<typeof updateOptionExtraConfigSchema>;
11
+ type CreateBookingExtraInput = z.infer<typeof insertBookingExtraSchema>;
12
+ type UpdateBookingExtraInput = z.infer<typeof updateBookingExtraSchema>;
13
+ export declare const extrasService: {
14
+ listProductExtras(db: PostgresJsDatabase, query: ProductExtraListQuery): Promise<{
15
+ data: {
16
+ id: string;
17
+ productId: string;
18
+ code: string | null;
19
+ name: string;
20
+ description: string | null;
21
+ selectionType: "optional" | "required" | "default_selected" | "unavailable";
22
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
23
+ pricedPerPerson: 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
+ code: string | null;
41
+ name: string;
42
+ description: string | null;
43
+ selectionType: "optional" | "required" | "default_selected" | "unavailable";
44
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
45
+ pricedPerPerson: boolean;
46
+ minQuantity: number | null;
47
+ maxQuantity: number | null;
48
+ defaultQuantity: number | null;
49
+ active: boolean;
50
+ sortOrder: number;
51
+ metadata: Record<string, unknown> | null;
52
+ createdAt: Date;
53
+ updatedAt: Date;
54
+ } | null>;
55
+ createProductExtra(db: PostgresJsDatabase, data: CreateProductExtraInput): Promise<{
56
+ id: string;
57
+ name: string;
58
+ productId: string;
59
+ code: string | null;
60
+ description: string | null;
61
+ selectionType: "optional" | "required" | "default_selected" | "unavailable";
62
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
63
+ pricedPerPerson: boolean;
64
+ minQuantity: number | null;
65
+ maxQuantity: number | null;
66
+ defaultQuantity: number | null;
67
+ active: boolean;
68
+ sortOrder: number;
69
+ metadata: Record<string, unknown> | null;
70
+ createdAt: Date;
71
+ updatedAt: Date;
72
+ } | null>;
73
+ updateProductExtra(db: PostgresJsDatabase, id: string, data: UpdateProductExtraInput): Promise<{
74
+ id: string;
75
+ productId: string;
76
+ code: string | null;
77
+ name: string;
78
+ description: string | null;
79
+ selectionType: "optional" | "required" | "default_selected" | "unavailable";
80
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
81
+ pricedPerPerson: boolean;
82
+ minQuantity: number | null;
83
+ maxQuantity: number | null;
84
+ defaultQuantity: number | null;
85
+ active: boolean;
86
+ sortOrder: number;
87
+ metadata: Record<string, unknown> | null;
88
+ createdAt: Date;
89
+ updatedAt: Date;
90
+ } | null>;
91
+ deleteProductExtra(db: PostgresJsDatabase, id: string): Promise<{
92
+ id: string;
93
+ } | null>;
94
+ listOptionExtraConfigs(db: PostgresJsDatabase, query: OptionExtraConfigListQuery): Promise<{
95
+ data: {
96
+ id: string;
97
+ optionId: string;
98
+ productExtraId: string;
99
+ selectionType: "optional" | "required" | "default_selected" | "unavailable" | null;
100
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free" | null;
101
+ pricedPerPerson: boolean | null;
102
+ minQuantity: number | null;
103
+ maxQuantity: number | null;
104
+ defaultQuantity: number | null;
105
+ isDefault: boolean;
106
+ active: boolean;
107
+ sortOrder: number;
108
+ notes: string | null;
109
+ metadata: Record<string, unknown> | null;
110
+ createdAt: Date;
111
+ updatedAt: Date;
112
+ }[];
113
+ total: number;
114
+ limit: number;
115
+ offset: number;
116
+ }>;
117
+ getOptionExtraConfigById(db: PostgresJsDatabase, id: string): Promise<{
118
+ id: string;
119
+ optionId: string;
120
+ productExtraId: string;
121
+ selectionType: "optional" | "required" | "default_selected" | "unavailable" | null;
122
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free" | null;
123
+ pricedPerPerson: boolean | null;
124
+ minQuantity: number | null;
125
+ maxQuantity: number | null;
126
+ defaultQuantity: number | null;
127
+ isDefault: boolean;
128
+ active: boolean;
129
+ sortOrder: number;
130
+ notes: string | null;
131
+ metadata: Record<string, unknown> | null;
132
+ createdAt: Date;
133
+ updatedAt: Date;
134
+ } | null>;
135
+ createOptionExtraConfig(db: PostgresJsDatabase, data: CreateOptionExtraConfigInput): Promise<{
136
+ id: string;
137
+ selectionType: "optional" | "required" | "default_selected" | "unavailable" | null;
138
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free" | null;
139
+ pricedPerPerson: boolean | null;
140
+ minQuantity: number | null;
141
+ maxQuantity: number | null;
142
+ defaultQuantity: number | null;
143
+ active: boolean;
144
+ sortOrder: number;
145
+ metadata: Record<string, unknown> | null;
146
+ createdAt: Date;
147
+ updatedAt: Date;
148
+ optionId: string;
149
+ productExtraId: string;
150
+ isDefault: boolean;
151
+ notes: string | null;
152
+ } | null>;
153
+ updateOptionExtraConfig(db: PostgresJsDatabase, id: string, data: UpdateOptionExtraConfigInput): Promise<{
154
+ id: string;
155
+ optionId: string;
156
+ productExtraId: string;
157
+ selectionType: "optional" | "required" | "default_selected" | "unavailable" | null;
158
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free" | null;
159
+ pricedPerPerson: boolean | null;
160
+ minQuantity: number | null;
161
+ maxQuantity: number | null;
162
+ defaultQuantity: number | null;
163
+ isDefault: boolean;
164
+ active: boolean;
165
+ sortOrder: number;
166
+ notes: string | null;
167
+ metadata: Record<string, unknown> | null;
168
+ createdAt: Date;
169
+ updatedAt: Date;
170
+ } | null>;
171
+ deleteOptionExtraConfig(db: PostgresJsDatabase, id: string): Promise<{
172
+ id: string;
173
+ } | null>;
174
+ listBookingExtras(db: PostgresJsDatabase, query: BookingExtraListQuery): Promise<{
175
+ data: {
176
+ id: string;
177
+ bookingId: string;
178
+ productExtraId: string | null;
179
+ optionExtraConfigId: string | null;
180
+ name: string;
181
+ description: string | null;
182
+ status: "draft" | "selected" | "confirmed" | "cancelled" | "fulfilled";
183
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
184
+ pricedPerPerson: boolean;
185
+ quantity: number;
186
+ sellCurrency: string;
187
+ unitSellAmountCents: number | null;
188
+ totalSellAmountCents: number | null;
189
+ costCurrency: string | null;
190
+ unitCostAmountCents: number | null;
191
+ totalCostAmountCents: number | null;
192
+ notes: string | null;
193
+ metadata: Record<string, unknown> | null;
194
+ createdAt: Date;
195
+ updatedAt: Date;
196
+ }[];
197
+ total: number;
198
+ limit: number;
199
+ offset: number;
200
+ }>;
201
+ getBookingExtraById(db: PostgresJsDatabase, id: string): Promise<{
202
+ id: string;
203
+ bookingId: string;
204
+ productExtraId: string | null;
205
+ optionExtraConfigId: string | null;
206
+ name: string;
207
+ description: string | null;
208
+ status: "draft" | "selected" | "confirmed" | "cancelled" | "fulfilled";
209
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
210
+ pricedPerPerson: boolean;
211
+ quantity: number;
212
+ sellCurrency: string;
213
+ unitSellAmountCents: number | null;
214
+ totalSellAmountCents: number | null;
215
+ costCurrency: string | null;
216
+ unitCostAmountCents: number | null;
217
+ totalCostAmountCents: number | null;
218
+ notes: string | null;
219
+ metadata: Record<string, unknown> | null;
220
+ createdAt: Date;
221
+ updatedAt: Date;
222
+ } | null>;
223
+ createBookingExtra(db: PostgresJsDatabase, data: CreateBookingExtraInput): Promise<{
224
+ id: string;
225
+ name: string;
226
+ description: string | null;
227
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
228
+ pricedPerPerson: boolean;
229
+ metadata: Record<string, unknown> | null;
230
+ createdAt: Date;
231
+ updatedAt: Date;
232
+ productExtraId: string | null;
233
+ notes: string | null;
234
+ bookingId: string;
235
+ optionExtraConfigId: string | null;
236
+ status: "draft" | "selected" | "confirmed" | "cancelled" | "fulfilled";
237
+ quantity: number;
238
+ sellCurrency: string;
239
+ unitSellAmountCents: number | null;
240
+ totalSellAmountCents: number | null;
241
+ costCurrency: string | null;
242
+ unitCostAmountCents: number | null;
243
+ totalCostAmountCents: number | null;
244
+ } | null>;
245
+ updateBookingExtra(db: PostgresJsDatabase, id: string, data: UpdateBookingExtraInput): Promise<{
246
+ id: string;
247
+ bookingId: string;
248
+ productExtraId: string | null;
249
+ optionExtraConfigId: string | null;
250
+ name: string;
251
+ description: string | null;
252
+ status: "draft" | "selected" | "confirmed" | "cancelled" | "fulfilled";
253
+ pricingMode: "included" | "per_person" | "per_booking" | "quantity_based" | "on_request" | "free";
254
+ pricedPerPerson: boolean;
255
+ quantity: number;
256
+ sellCurrency: string;
257
+ unitSellAmountCents: number | null;
258
+ totalSellAmountCents: number | null;
259
+ costCurrency: string | null;
260
+ unitCostAmountCents: number | null;
261
+ totalCostAmountCents: number | null;
262
+ notes: string | null;
263
+ metadata: Record<string, unknown> | null;
264
+ createdAt: Date;
265
+ updatedAt: Date;
266
+ } | null>;
267
+ deleteBookingExtra(db: PostgresJsDatabase, id: string): Promise<{
268
+ id: string;
269
+ } | null>;
270
+ };
271
+ export {};
272
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/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,2BAA2B,EAC3B,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,wBAAwB,EACxB,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,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA;AACxE,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;AACjF,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AACvE,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAYvE,eAAO,MAAM,aAAa;0BACI,kBAAkB,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;4BAuB9C,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;;;0BAQpC,kBAAkB,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAuB9C,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;2BAK/B,kBAAkB,QAAQ,uBAAuB;;;;;;;;;;;;;;;;;;;;;;2BAKjD,kBAAkB,MAAM,MAAM,QAAQ,uBAAuB;;;;;;;;;;;;;;;;;;;;;;2BAS7D,kBAAkB,MAAM,MAAM;;;CAO5D,CAAA"}
@@ -0,0 +1,136 @@
1
+ import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
2
+ import { bookingExtras, 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 extrasService = {
8
+ async listProductExtras(db, query) {
9
+ const conditions = [];
10
+ if (query.productId)
11
+ conditions.push(eq(productExtras.productId, query.productId));
12
+ if (query.active !== undefined)
13
+ conditions.push(eq(productExtras.active, query.active));
14
+ if (query.search) {
15
+ const term = `%${query.search}%`;
16
+ conditions.push(or(ilike(productExtras.name, term), ilike(productExtras.code, term)));
17
+ }
18
+ const where = conditions.length ? and(...conditions) : undefined;
19
+ return paginate(db
20
+ .select()
21
+ .from(productExtras)
22
+ .where(where)
23
+ .limit(query.limit)
24
+ .offset(query.offset)
25
+ .orderBy(asc(productExtras.sortOrder), asc(productExtras.name)), db.select({ count: sql `count(*)::int` }).from(productExtras).where(where), query.limit, query.offset);
26
+ },
27
+ async getProductExtraById(db, id) {
28
+ const [row] = await db.select().from(productExtras).where(eq(productExtras.id, id)).limit(1);
29
+ return row ?? null;
30
+ },
31
+ async createProductExtra(db, data) {
32
+ const [row] = await db.insert(productExtras).values(data).returning();
33
+ return row ?? null;
34
+ },
35
+ async updateProductExtra(db, id, data) {
36
+ const [row] = await db
37
+ .update(productExtras)
38
+ .set({ ...data, updatedAt: new Date() })
39
+ .where(eq(productExtras.id, id))
40
+ .returning();
41
+ return row ?? null;
42
+ },
43
+ async deleteProductExtra(db, id) {
44
+ const [row] = await db
45
+ .delete(productExtras)
46
+ .where(eq(productExtras.id, id))
47
+ .returning({ id: productExtras.id });
48
+ return row ?? null;
49
+ },
50
+ async listOptionExtraConfigs(db, query) {
51
+ const conditions = [];
52
+ if (query.optionId)
53
+ conditions.push(eq(optionExtraConfigs.optionId, query.optionId));
54
+ if (query.productExtraId)
55
+ conditions.push(eq(optionExtraConfigs.productExtraId, query.productExtraId));
56
+ if (query.active !== undefined)
57
+ conditions.push(eq(optionExtraConfigs.active, query.active));
58
+ const where = conditions.length ? and(...conditions) : undefined;
59
+ return paginate(db
60
+ .select()
61
+ .from(optionExtraConfigs)
62
+ .where(where)
63
+ .limit(query.limit)
64
+ .offset(query.offset)
65
+ .orderBy(asc(optionExtraConfigs.sortOrder), desc(optionExtraConfigs.isDefault)), db.select({ count: sql `count(*)::int` }).from(optionExtraConfigs).where(where), query.limit, query.offset);
66
+ },
67
+ async getOptionExtraConfigById(db, id) {
68
+ const [row] = await db
69
+ .select()
70
+ .from(optionExtraConfigs)
71
+ .where(eq(optionExtraConfigs.id, id))
72
+ .limit(1);
73
+ return row ?? null;
74
+ },
75
+ async createOptionExtraConfig(db, data) {
76
+ const [row] = await db.insert(optionExtraConfigs).values(data).returning();
77
+ return row ?? null;
78
+ },
79
+ async updateOptionExtraConfig(db, id, data) {
80
+ const [row] = await db
81
+ .update(optionExtraConfigs)
82
+ .set({ ...data, updatedAt: new Date() })
83
+ .where(eq(optionExtraConfigs.id, id))
84
+ .returning();
85
+ return row ?? null;
86
+ },
87
+ async deleteOptionExtraConfig(db, id) {
88
+ const [row] = await db
89
+ .delete(optionExtraConfigs)
90
+ .where(eq(optionExtraConfigs.id, id))
91
+ .returning({ id: optionExtraConfigs.id });
92
+ return row ?? null;
93
+ },
94
+ async listBookingExtras(db, query) {
95
+ const conditions = [];
96
+ if (query.bookingId)
97
+ conditions.push(eq(bookingExtras.bookingId, query.bookingId));
98
+ if (query.productExtraId)
99
+ conditions.push(eq(bookingExtras.productExtraId, query.productExtraId));
100
+ if (query.optionExtraConfigId)
101
+ conditions.push(eq(bookingExtras.optionExtraConfigId, query.optionExtraConfigId));
102
+ if (query.status)
103
+ conditions.push(eq(bookingExtras.status, query.status));
104
+ const where = conditions.length ? and(...conditions) : undefined;
105
+ return paginate(db
106
+ .select()
107
+ .from(bookingExtras)
108
+ .where(where)
109
+ .limit(query.limit)
110
+ .offset(query.offset)
111
+ .orderBy(desc(bookingExtras.updatedAt)), db.select({ count: sql `count(*)::int` }).from(bookingExtras).where(where), query.limit, query.offset);
112
+ },
113
+ async getBookingExtraById(db, id) {
114
+ const [row] = await db.select().from(bookingExtras).where(eq(bookingExtras.id, id)).limit(1);
115
+ return row ?? null;
116
+ },
117
+ async createBookingExtra(db, data) {
118
+ const [row] = await db.insert(bookingExtras).values(data).returning();
119
+ return row ?? null;
120
+ },
121
+ async updateBookingExtra(db, id, data) {
122
+ const [row] = await db
123
+ .update(bookingExtras)
124
+ .set({ ...data, updatedAt: new Date() })
125
+ .where(eq(bookingExtras.id, id))
126
+ .returning();
127
+ return row ?? null;
128
+ },
129
+ async deleteBookingExtra(db, id) {
130
+ const [row] = await db
131
+ .delete(bookingExtras)
132
+ .where(eq(bookingExtras.id, id))
133
+ .returning({ id: bookingExtras.id });
134
+ return row ?? null;
135
+ },
136
+ };