@managesome/eposmatic-toolkit 0.2.699 → 0.2.701
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,6 +1,7 @@
|
|
|
1
1
|
import { PLATFORMS_ENUM } from '../../constants';
|
|
2
2
|
import { IHalfHalfSetup, IItem, IModifier, IOrderItem, IPrice } from '../../schemas';
|
|
3
3
|
import { ISimplifiedCatalogItem } from '../types';
|
|
4
|
+
import { IOrderEngineItem } from '../types/order-engine';
|
|
4
5
|
export declare function getHalfHalfPostedData(data: IHalfHalfSetup[], payload: IHalfHalfSetup): IHalfHalfSetup[];
|
|
5
6
|
export declare function renderBulkHalfHalfUpdate(data: IHalfHalfSetup[], payload: Partial<IHalfHalfSetup>[]): IHalfHalfSetup[];
|
|
6
7
|
export declare function getHalfHalfUpdatedData(data: IHalfHalfSetup[], payload: Partial<IHalfHalfSetup>): IHalfHalfSetup[];
|
|
@@ -86,6 +87,30 @@ interface IConvertHalfHalfToOrderItem {
|
|
|
86
87
|
* chosen item's `_id`, allowing the item to be de-structured back on edit.
|
|
87
88
|
*/
|
|
88
89
|
export declare function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }: IConvertHalfHalfToOrderItem): IOrderItem;
|
|
90
|
+
interface IConvertHalfHalfToOrderEngineItem {
|
|
91
|
+
halfHalfItem: IWorkableHalfHalfSetup<IItem>;
|
|
92
|
+
selectedHalfHalfItems: (IOrderItem | null)[];
|
|
93
|
+
quantity: number;
|
|
94
|
+
platform: PLATFORMS_ENUM;
|
|
95
|
+
existingOrderItem?: IOrderItem;
|
|
96
|
+
orderItemId?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
100
|
+
* single HALF_HALF IOrderEngineItem — the SAME representation the classic
|
|
101
|
+
* item-options drawer builds — so callers can run it through
|
|
102
|
+
* `convertOrderEngineItemToOrderItem` and `setAddItemToCart`. This keeps a
|
|
103
|
+
* single pipeline for both classic and modern half-half flows, so the cart
|
|
104
|
+
* receives structurally identical order items (same fields, same modifier
|
|
105
|
+
* ids/refs) and merges/dedupes them consistently.
|
|
106
|
+
*
|
|
107
|
+
* Each chosen segment becomes a depth-0 engine modifier (segment `_id` as
|
|
108
|
+
* ref, min/max 1) with exactly one selected option (the chosen item, option
|
|
109
|
+
* `_id`/`ref` = the item id — consistent with the classic drawer). The item's
|
|
110
|
+
* own modifier tree is carried as nested selected engine modifiers; all
|
|
111
|
+
* options are kept selected (they were chosen), so sync/error checks pass.
|
|
112
|
+
*/
|
|
113
|
+
export declare function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }: IConvertHalfHalfToOrderEngineItem): IOrderEngineItem;
|
|
89
114
|
/**
|
|
90
115
|
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
91
116
|
* selection format used by the HalfHalfScreen selection flow.
|
|
@@ -12,6 +12,7 @@ exports.divideItemPriceBySegments = divideItemPriceBySegments;
|
|
|
12
12
|
exports.convertHalfHalfSetupToWorkableHalfHalfSetup = convertHalfHalfSetupToWorkableHalfHalfSetup;
|
|
13
13
|
exports.convertHalfHalfToItem = convertHalfHalfToItem;
|
|
14
14
|
exports.convertHalfHalfToOrderItem = convertHalfHalfToOrderItem;
|
|
15
|
+
exports.convertHalfHalfToOrderEngineItem = convertHalfHalfToOrderEngineItem;
|
|
15
16
|
exports.deStructureHalfHalfOrderItem = deStructureHalfHalfOrderItem;
|
|
16
17
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
17
18
|
const constants_1 = require("../../constants");
|
|
@@ -505,6 +506,131 @@ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quant
|
|
|
505
506
|
orderItem.item_discount_details = item_discount_details;
|
|
506
507
|
return orderItem;
|
|
507
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
511
|
+
* single HALF_HALF IOrderEngineItem — the SAME representation the classic
|
|
512
|
+
* item-options drawer builds — so callers can run it through
|
|
513
|
+
* `convertOrderEngineItemToOrderItem` and `setAddItemToCart`. This keeps a
|
|
514
|
+
* single pipeline for both classic and modern half-half flows, so the cart
|
|
515
|
+
* receives structurally identical order items (same fields, same modifier
|
|
516
|
+
* ids/refs) and merges/dedupes them consistently.
|
|
517
|
+
*
|
|
518
|
+
* Each chosen segment becomes a depth-0 engine modifier (segment `_id` as
|
|
519
|
+
* ref, min/max 1) with exactly one selected option (the chosen item, option
|
|
520
|
+
* `_id`/`ref` = the item id — consistent with the classic drawer). The item's
|
|
521
|
+
* own modifier tree is carried as nested selected engine modifiers; all
|
|
522
|
+
* options are kept selected (they were chosen), so sync/error checks pass.
|
|
523
|
+
*/
|
|
524
|
+
function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }) {
|
|
525
|
+
let menu_id;
|
|
526
|
+
const toEngineModifiers = (modifiers, depth) => (modifiers ?? []).map((modifier) => {
|
|
527
|
+
const options = modifier.options ?? [];
|
|
528
|
+
const engineOptions = options.map((option) => ({
|
|
529
|
+
_id: option._id,
|
|
530
|
+
ref: option.ref,
|
|
531
|
+
name: option.name,
|
|
532
|
+
price: option.price,
|
|
533
|
+
quantity: option.quantity || 1,
|
|
534
|
+
is_free: option.is_free ?? false,
|
|
535
|
+
default: true,
|
|
536
|
+
loyalty_applied: false,
|
|
537
|
+
voucher_applied: false,
|
|
538
|
+
active: true,
|
|
539
|
+
sold_out: [],
|
|
540
|
+
sort_id: 0,
|
|
541
|
+
excluded_platforms: [],
|
|
542
|
+
modifiers: toEngineModifiers(option.modifiers, depth + 1),
|
|
543
|
+
}));
|
|
544
|
+
return {
|
|
545
|
+
_id: modifier._id,
|
|
546
|
+
ref: modifier.ref,
|
|
547
|
+
name: modifier.name,
|
|
548
|
+
description: '',
|
|
549
|
+
depth,
|
|
550
|
+
default: true,
|
|
551
|
+
active: true,
|
|
552
|
+
sold_out: [],
|
|
553
|
+
sort_id: 0,
|
|
554
|
+
min_num_options: 1,
|
|
555
|
+
max_num_options: options.length || 1,
|
|
556
|
+
options: engineOptions,
|
|
557
|
+
};
|
|
558
|
+
});
|
|
559
|
+
const modifiers = [];
|
|
560
|
+
for (let s = 0; s < selectedHalfHalfItems.length; s++) {
|
|
561
|
+
const selectedItem = selectedHalfHalfItems[s];
|
|
562
|
+
if (!selectedItem)
|
|
563
|
+
continue;
|
|
564
|
+
if (selectedItem.menu_id != null && menu_id == null) {
|
|
565
|
+
menu_id = selectedItem.menu_id;
|
|
566
|
+
}
|
|
567
|
+
const segment = halfHalfItem.segments[s];
|
|
568
|
+
const segmentOptions = [
|
|
569
|
+
{
|
|
570
|
+
_id: selectedItem.item_id,
|
|
571
|
+
ref: selectedItem.item_id,
|
|
572
|
+
name: selectedItem.name,
|
|
573
|
+
price: selectedItem.price,
|
|
574
|
+
quantity: selectedItem.quantity || 1,
|
|
575
|
+
is_free: false,
|
|
576
|
+
default: true,
|
|
577
|
+
loyalty_applied: false,
|
|
578
|
+
voucher_applied: false,
|
|
579
|
+
active: true,
|
|
580
|
+
sold_out: [],
|
|
581
|
+
sort_id: 0,
|
|
582
|
+
excluded_platforms: [],
|
|
583
|
+
modifiers: toEngineModifiers(selectedItem.modifiers, 1),
|
|
584
|
+
},
|
|
585
|
+
];
|
|
586
|
+
const segmentModifier = {
|
|
587
|
+
_id: segment?._id ?? halfHalfItem._id,
|
|
588
|
+
ref: segment?._id ?? halfHalfItem._id,
|
|
589
|
+
name: segment?.name || `Segment ${s + 1}`,
|
|
590
|
+
description: '',
|
|
591
|
+
depth: 0,
|
|
592
|
+
default: true,
|
|
593
|
+
active: true,
|
|
594
|
+
sold_out: [],
|
|
595
|
+
sort_id: 0,
|
|
596
|
+
min_num_options: 1,
|
|
597
|
+
max_num_options: 1,
|
|
598
|
+
options: segmentOptions,
|
|
599
|
+
};
|
|
600
|
+
modifiers.push(segmentModifier);
|
|
601
|
+
}
|
|
602
|
+
const orderEngineItem = {
|
|
603
|
+
_id: existingOrderItem?._id ?? orderItemId ?? (0, bson_objectid_1.default)().toHexString(),
|
|
604
|
+
category_id: halfHalfItem.category_id,
|
|
605
|
+
item_id: halfHalfItem._id,
|
|
606
|
+
menu_id: menu_id ?? null,
|
|
607
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
608
|
+
is_ready: existingOrderItem?.is_ready ?? false,
|
|
609
|
+
// Match the classic engine conversion exactly: these fields are only
|
|
610
|
+
// carried when they already exist on the order item (undefined on create
|
|
611
|
+
// so they're omitted from the payload, same as convertCatalogItemTo-
|
|
612
|
+
// OrderEngineItem). Explicit null/false defaults here caused a shape
|
|
613
|
+
// mismatch (null vs undefined) between classic and modern lines.
|
|
614
|
+
is_split: existingOrderItem?.is_split,
|
|
615
|
+
moved_to_order_id: existingOrderItem?.moved_to_order_id,
|
|
616
|
+
moved_from_order_id: existingOrderItem?.moved_from_order_id,
|
|
617
|
+
ready_minutes: existingOrderItem?.ready_minutes,
|
|
618
|
+
name: halfHalfItem.name,
|
|
619
|
+
description: halfHalfItem.description,
|
|
620
|
+
loyalty_applied: false,
|
|
621
|
+
voucher_applied: false,
|
|
622
|
+
price: (0, platform_catalog_1.getPriceEnum)(halfHalfItem.upsell_price, platform),
|
|
623
|
+
gross_total: 0,
|
|
624
|
+
subtotal: 0,
|
|
625
|
+
tax_rate: existingOrderItem?.tax_rate ?? 0,
|
|
626
|
+
quantity,
|
|
627
|
+
image_url: halfHalfItem.image_url,
|
|
628
|
+
special_instructions: existingOrderItem?.special_instructions ?? '',
|
|
629
|
+
item_discount_details: (0, order_engine_1.convertItemDiscountToOrderItemDiscount)(halfHalfItem.discount_amount, halfHalfItem.is_discount_percentage, platform, halfHalfItem._id),
|
|
630
|
+
modifiers,
|
|
631
|
+
};
|
|
632
|
+
return (0, order_engine_1.syncOrderEngineItem)(orderEngineItem);
|
|
633
|
+
}
|
|
508
634
|
// ====================================================================================================
|
|
509
635
|
/**
|
|
510
636
|
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|