@managesome/eposmatic-toolkit 0.2.656 → 0.2.658

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.
@@ -1,5 +1,5 @@
1
1
  import { PLATFORMS_ENUM } from '../../constants';
2
- import { IHalfHalfSetup, IItem } from '../../schemas';
2
+ import { IHalfHalfSetup, IItem, IOrderItem } from '../../schemas';
3
3
  import { ISimplifiedCatalogItem } from '../types';
4
4
  export declare function getHalfHalfPostedData(data: IHalfHalfSetup[], payload: IHalfHalfSetup): IHalfHalfSetup[];
5
5
  export declare function renderBulkHalfHalfUpdate(data: IHalfHalfSetup[], payload: Partial<IHalfHalfSetup>[]): IHalfHalfSetup[];
@@ -20,3 +20,42 @@ export type IWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem> = {
20
20
  items: T[];
21
21
  };
22
22
  export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem>(halfhalfSetups: IHalfHalfSetup[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableHalfHalfSetup<T>[];
23
+ /**
24
+ * Converts an IHalfHalfSetup into an IItem so it can flow through the standard
25
+ * catalog → drawer → cart pipeline just like a regular catalog item.
26
+ *
27
+ * Each segment becomes a single-select IModifier (one option per available
28
+ * item, priced as `(item price + upsells) / segments`), so duplicates across
29
+ * segments are allowed and each segment must be filled exactly once.
30
+ *
31
+ * Returns null if the halfhalf setup is inactive, doesn't match platform/tenant,
32
+ * or has no applicable schedule / no resolvable items.
33
+ */
34
+ export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>, platform: PLATFORMS_ENUM, tenant_id: string): IItem | null;
35
+ interface IConvertHalfHalfToOrderItem {
36
+ halfHalfItem: IWorkableHalfHalfSetup<IItem>;
37
+ selectedHalfHalfItems: (IOrderItem | null)[];
38
+ quantity: number;
39
+ platform: PLATFORMS_ENUM;
40
+ existingOrderItem?: IOrderItem;
41
+ }
42
+ /**
43
+ * Converts the legacy half-half selection (per-segment IOrderItems) into a
44
+ * single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
45
+ * (stable id `${halfHalfItem._id}_segment_${s}`) with the chosen item as its
46
+ * single option, so it can be de-structured back on edit.
47
+ */
48
+ export declare function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }: IConvertHalfHalfToOrderItem): IOrderItem;
49
+ /**
50
+ * De-structures a HALF_HALF IOrderItem back into the legacy per-segment
51
+ * selection format used by the HalfHalfScreen selection flow.
52
+ *
53
+ * Matches each order modifier to its segment via the stable
54
+ * `${halfHalfItem._id}_segment_${s}` id/ref. Returns null if the order item
55
+ * doesn't belong to the provided halfhalf setup.
56
+ */
57
+ export declare function deStructureHalfHalfOrderItem(orderItem: IOrderItem, halfHalfItem: IWorkableHalfHalfSetup<IItem>): {
58
+ selectedHalfHalfItems: (IOrderItem | null)[];
59
+ quantity: number;
60
+ } | null;
61
+ export {};
@@ -6,6 +6,10 @@ exports.getHalfHalfUpdatedData = getHalfHalfUpdatedData;
6
6
  exports.getHalfHalfDeletedData = getHalfHalfDeletedData;
7
7
  exports.getHalfhalfSetupWithPrice = getHalfhalfSetupWithPrice;
8
8
  exports.convertHalfHalfSetupToWorkableHalfHalfSetup = convertHalfHalfSetupToWorkableHalfHalfSetup;
9
+ exports.convertHalfHalfToItem = convertHalfHalfToItem;
10
+ exports.convertHalfHalfToOrderItem = convertHalfHalfToOrderItem;
11
+ exports.deStructureHalfHalfOrderItem = deStructureHalfHalfOrderItem;
12
+ const constants_1 = require("../../constants");
9
13
  const store_1 = require("../store");
10
14
  const platform_catalog_1 = require("./platform-catalog");
11
15
  const platform_num_1 = require("./platform-num");
@@ -131,3 +135,227 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
131
135
  }
132
136
  return halfhalfMenu;
133
137
  }
138
+ // ====================================================================================================
139
+ /**
140
+ * Converts an IHalfHalfSetup into an IItem so it can flow through the standard
141
+ * catalog → drawer → cart pipeline just like a regular catalog item.
142
+ *
143
+ * Each segment becomes a single-select IModifier (one option per available
144
+ * item, priced as `(item price + upsells) / segments`), so duplicates across
145
+ * segments are allowed and each segment must be filled exactly once.
146
+ *
147
+ * Returns null if the halfhalf setup is inactive, doesn't match platform/tenant,
148
+ * or has no applicable schedule / no resolvable items.
149
+ */
150
+ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
151
+ // ── Guard: active, tenant, platform ────────────────────────────
152
+ if (!halfhalfSetup.active ||
153
+ !halfhalfSetup.tenants.includes(tenant_id) ||
154
+ !halfhalfSetup.included_platforms.includes(platform)) {
155
+ return null;
156
+ }
157
+ // ── Schedule resolution ────────────────────────────────────────
158
+ const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(halfhalfSetup.item_special_hours, platform);
159
+ if (applicableSchedule === false)
160
+ return null;
161
+ let upsell_price = halfhalfSetup.upsell_price;
162
+ let discount_amount = halfhalfSetup.discount_amount;
163
+ if (applicableSchedule !== true) {
164
+ if (applicableSchedule.price != null)
165
+ upsell_price = applicableSchedule.price;
166
+ if (applicableSchedule.discount_amount != null) {
167
+ discount_amount = applicableSchedule.discount_amount;
168
+ }
169
+ }
170
+ // ── Build shared option list (segment-neutral ids) ─────────────
171
+ const halfHalfItems = [...halfhalfSetup.items].sort((a, b) => a.sort_id - b.sort_id);
172
+ const baseOptions = [];
173
+ for (let i = 0; i < halfHalfItems.length; i++) {
174
+ const halfHalfItem = halfHalfItems[i];
175
+ const catalogItem = itemsMap[halfHalfItem.item_id];
176
+ if (!catalogItem)
177
+ continue;
178
+ const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id);
179
+ if (!workableItem)
180
+ continue;
181
+ let optionPrice = workableItem.price;
182
+ if (upsell_price != null)
183
+ optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, upsell_price);
184
+ if (halfHalfItem.upsell_price != null) {
185
+ optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, halfHalfItem.upsell_price);
186
+ }
187
+ optionPrice = (0, platform_num_1.convertPriceObjToSegmentPrice)(optionPrice, halfhalfSetup.segments);
188
+ baseOptions.push({
189
+ _id: `${halfhalfSetup._id}_${catalogItem._id}`,
190
+ ref: catalogItem._id,
191
+ name: catalogItem.name,
192
+ active: catalogItem.active,
193
+ sold_out: catalogItem.sold_out,
194
+ sort_id: halfHalfItem.sort_id,
195
+ excluded_platforms: [],
196
+ price: optionPrice,
197
+ modifiers: workableItem.modifiers,
198
+ });
199
+ }
200
+ if (baseOptions.length === 0)
201
+ return null;
202
+ // ── Build one single-select modifier per segment ───────────────
203
+ const modifiers = [];
204
+ for (let s = 0; s < halfhalfSetup.segments; s++) {
205
+ modifiers.push({
206
+ _id: `${halfhalfSetup._id}_segment_${s}`,
207
+ ref: `${halfhalfSetup._id}_segment_${s}`,
208
+ name: `Segment ${s + 1}`,
209
+ description: '',
210
+ active: true,
211
+ sold_out: [],
212
+ sort_id: s,
213
+ min_num_options: 1,
214
+ max_num_options: 1,
215
+ num_free_options: null,
216
+ options: baseOptions.map((option) => ({
217
+ ...option,
218
+ _id: `${halfhalfSetup._id}_segment_${s}_${option.ref}`,
219
+ })),
220
+ });
221
+ }
222
+ // ── Assemble the IItem ─────────────────────────────────────────
223
+ const item = {
224
+ _id: halfhalfSetup._id,
225
+ brand_id: halfhalfSetup.brand_id,
226
+ tenants: halfhalfSetup.tenants,
227
+ category_id: halfhalfSetup.category_id,
228
+ included_platforms: halfhalfSetup.included_platforms,
229
+ name: halfhalfSetup.name,
230
+ hide_name: false,
231
+ description: halfhalfSetup.description,
232
+ active: halfhalfSetup.active,
233
+ sold_out: halfhalfSetup.sold_out,
234
+ sort_id: 0,
235
+ price: null,
236
+ discount_amount,
237
+ is_discount_percentage: halfhalfSetup.is_discount_percentage,
238
+ caveats: [],
239
+ dietary_preferences: [],
240
+ tax_rate: null,
241
+ keywords: [],
242
+ image_url: halfhalfSetup.image_url,
243
+ ingredients: null,
244
+ item_special_hours: null, // already resolved into upsell_price / discount_amount
245
+ modifiers: modifiers.length > 0 ? modifiers : null,
246
+ is_featured: false,
247
+ featured_sort_id: 0,
248
+ display_price: null,
249
+ show_starting_from: false,
250
+ use_source_ingredients: false,
251
+ createdAt: halfhalfSetup.createdAt,
252
+ updatedAt: halfhalfSetup.updatedAt,
253
+ };
254
+ return item;
255
+ }
256
+ /**
257
+ * Converts the legacy half-half selection (per-segment IOrderItems) into a
258
+ * single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
259
+ * (stable id `${halfHalfItem._id}_segment_${s}`) with the chosen item as its
260
+ * single option, so it can be de-structured back on edit.
261
+ */
262
+ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }) {
263
+ const modifiers = [];
264
+ let menu_id;
265
+ for (let s = 0; s < selectedHalfHalfItems.length; s++) {
266
+ const selectedItem = selectedHalfHalfItems[s];
267
+ if (!selectedItem)
268
+ continue;
269
+ if (selectedItem.menu_id != null && menu_id == null) {
270
+ menu_id = selectedItem.menu_id;
271
+ }
272
+ modifiers.push({
273
+ _id: `${halfHalfItem._id}_segment_${s}`,
274
+ ref: `${halfHalfItem._id}_segment_${s}`,
275
+ name: `Segment ${s + 1}`,
276
+ options: [
277
+ {
278
+ _id: selectedItem._id,
279
+ ref: selectedItem.item_id,
280
+ name: selectedItem.name,
281
+ price: selectedItem.price,
282
+ quantity: selectedItem.quantity,
283
+ modifiers: selectedItem.modifiers,
284
+ is_free: false,
285
+ },
286
+ ],
287
+ });
288
+ }
289
+ const orderItem = {
290
+ item_discount_details: null,
291
+ special_instructions: '',
292
+ _net_amount: 0,
293
+ _gross_amount: 0,
294
+ _gst_amount: 0,
295
+ _discount_amount: 0,
296
+ ...existingOrderItem,
297
+ _id: halfHalfItem._id,
298
+ item_id: halfHalfItem._id,
299
+ menu_id,
300
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
301
+ name: halfHalfItem.name,
302
+ price: 0,
303
+ subtotal: 0,
304
+ tax_rate: 0,
305
+ quantity,
306
+ modifiers,
307
+ };
308
+ const { itemSubtotal, item_discount_details } = (0, store_1.calculateItemTotalWithTax)(orderItem);
309
+ orderItem.subtotal = itemSubtotal;
310
+ orderItem.item_discount_details = item_discount_details;
311
+ return orderItem;
312
+ }
313
+ // ====================================================================================================
314
+ /**
315
+ * De-structures a HALF_HALF IOrderItem back into the legacy per-segment
316
+ * selection format used by the HalfHalfScreen selection flow.
317
+ *
318
+ * Matches each order modifier to its segment via the stable
319
+ * `${halfHalfItem._id}_segment_${s}` id/ref. Returns null if the order item
320
+ * doesn't belong to the provided halfhalf setup.
321
+ */
322
+ function deStructureHalfHalfOrderItem(orderItem, halfHalfItem) {
323
+ if (orderItem.item_id !== halfHalfItem._id)
324
+ return null;
325
+ const selectedHalfHalfItems = new Array(halfHalfItem.segments).fill(null);
326
+ const orderModifiers = orderItem.modifiers ?? [];
327
+ for (let i = 0; i < orderModifiers.length; i++) {
328
+ const orderModifier = orderModifiers[i];
329
+ const segmentMatch = (orderModifier.ref ?? orderModifier._id ?? '').match(/_segment_(\d+)$/);
330
+ let segmentIndex = segmentMatch != null ? Number(segmentMatch[1]) : NaN;
331
+ if (Number.isNaN(segmentIndex) || segmentIndex < 0 || segmentIndex >= selectedHalfHalfItems.length) {
332
+ // Fallback: assign to the first empty slot
333
+ segmentIndex = selectedHalfHalfItems.findIndex((item) => item === null);
334
+ if (segmentIndex === -1)
335
+ continue;
336
+ }
337
+ const option = orderModifier.options[0];
338
+ if (option == null)
339
+ continue;
340
+ selectedHalfHalfItems[segmentIndex] = {
341
+ _id: option._id,
342
+ item_id: option.ref,
343
+ menu_id: orderItem.menu_id ?? null,
344
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
345
+ name: option.name,
346
+ price: option.price,
347
+ subtotal: option.price,
348
+ tax_rate: 0,
349
+ quantity: option.quantity,
350
+ special_instructions: '',
351
+ item_discount_details: null,
352
+ modifiers: option.modifiers ?? null,
353
+ // These values will be auto calculated
354
+ _discount_amount: 0,
355
+ _gross_amount: 0,
356
+ _gst_amount: 0,
357
+ _net_amount: 0,
358
+ };
359
+ }
360
+ return { selectedHalfHalfItems, quantity: orderItem.quantity };
361
+ }
@@ -25,6 +25,8 @@ export type IWorkableSpecialMenu<T extends IItem | ISimplifiedCatalogItem> = {
25
25
  price: ISpecial['price'];
26
26
  discount_amount: ISpecial['discount_amount'];
27
27
  is_discount_percentage: ISpecial['is_discount_percentage'];
28
+ display_price: ISpecial['display_price'];
29
+ show_starting_from: ISpecial['show_starting_from'];
28
30
  modifier_specials: IWorkableModifierSpecial<T>[];
29
31
  };
30
32
  export declare function convertSpecialsToWorkableSpecials<T extends IItem | ISimplifiedCatalogItem>(specials: ISpecial[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableSpecialMenu<T>[];
@@ -146,6 +146,8 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
146
146
  price,
147
147
  discount_amount,
148
148
  is_discount_percentage: special.is_discount_percentage,
149
+ display_price: special.display_price,
150
+ show_starting_from: special.show_starting_from,
149
151
  modifier_specials: modifierSpecials,
150
152
  };
151
153
  specialsMenu.push(specialMenu);
@@ -395,8 +397,8 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
395
397
  modifiers: modifiers.length > 0 ? modifiers : null,
396
398
  is_featured: false,
397
399
  featured_sort_id: 0,
398
- display_price: null,
399
- show_starting_from: false,
400
+ display_price: special.display_price,
401
+ show_starting_from: special.show_starting_from,
400
402
  use_source_ingredients: false,
401
403
  createdAt: special.createdAt,
402
404
  updatedAt: special.updatedAt,
@@ -539,6 +539,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
539
539
  BASE_PRICE: number;
540
540
  } | null | undefined;
541
541
  }>;
542
+ display_price: number;
542
543
  modifier_specials: import("mongoose").Types.DocumentArray<{
543
544
  _id: import("mongoose").Types.ObjectId;
544
545
  name: string;
@@ -984,6 +985,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
984
985
  num_free_items: number;
985
986
  omit_items_schedule: boolean;
986
987
  }>;
988
+ show_starting_from?: boolean | null | undefined;
987
989
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
988
990
  createdAt: NativeDate;
989
991
  updatedAt: NativeDate;
@@ -1374,6 +1376,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
1374
1376
  BASE_PRICE: number;
1375
1377
  } | null | undefined;
1376
1378
  }>;
1379
+ display_price: number;
1377
1380
  modifier_specials: import("mongoose").Types.DocumentArray<{
1378
1381
  _id: import("mongoose").Types.ObjectId;
1379
1382
  name: string;
@@ -1819,6 +1822,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
1819
1822
  num_free_items: number;
1820
1823
  omit_items_schedule: boolean;
1821
1824
  }>;
1825
+ show_starting_from?: boolean | null | undefined;
1822
1826
  }>> & import("mongoose").FlatRecord<{
1823
1827
  createdAt: NativeDate;
1824
1828
  updatedAt: NativeDate;
@@ -2209,6 +2213,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
2209
2213
  BASE_PRICE: number;
2210
2214
  } | null | undefined;
2211
2215
  }>;
2216
+ display_price: number;
2212
2217
  modifier_specials: import("mongoose").Types.DocumentArray<{
2213
2218
  _id: import("mongoose").Types.ObjectId;
2214
2219
  name: string;
@@ -2654,6 +2659,7 @@ export declare const SpecialsSchema: Schema<any, import("mongoose").Model<any, a
2654
2659
  num_free_items: number;
2655
2660
  omit_items_schedule: boolean;
2656
2661
  }>;
2662
+ show_starting_from?: boolean | null | undefined;
2657
2663
  }> & Required<{
2658
2664
  _id: import("mongoose").Types.ObjectId;
2659
2665
  }> & {
@@ -124,6 +124,14 @@ exports.SpecialsSchema = new mongoose_1.Schema({
124
124
  type: Boolean,
125
125
  default: false,
126
126
  },
127
+ display_price: {
128
+ type: Number,
129
+ default: null,
130
+ },
131
+ show_starting_from: {
132
+ type: Boolean,
133
+ required: false,
134
+ },
127
135
  item_special_hours: {
128
136
  type: [items_1.SpecialHoursSchema],
129
137
  default: null,
@@ -32,6 +32,8 @@ export interface ISpecial {
32
32
  price: IPrice | null;
33
33
  discount_amount: IPrice | null;
34
34
  is_discount_percentage: boolean;
35
+ display_price?: number | null;
36
+ show_starting_from?: boolean;
35
37
  item_special_hours: IItemSpecialHour[] | null;
36
38
  modifier_specials: IModifierSpecial[];
37
39
  createdAt: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.656",
3
+ "version": "0.2.658",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",