@managesome/eposmatic-toolkit 0.2.654 → 0.2.655
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.
|
@@ -40,6 +40,20 @@ interface IConvertSpecialItemToOrderItem {
|
|
|
40
40
|
existingOrderItem?: IOrderItem;
|
|
41
41
|
}
|
|
42
42
|
export declare function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, }: IConvertSpecialItemToOrderItem): IOrderItem;
|
|
43
|
+
/**
|
|
44
|
+
* De-structures a special IOrderItem back into the legacy selection format
|
|
45
|
+
* used by the SpecialsScreen selection flow (edit without classic preview).
|
|
46
|
+
*
|
|
47
|
+
* Each modifier on the order item maps back to its `IModifierSpecial` group
|
|
48
|
+
* (matched by ref or _id), and each selected option becomes a selection
|
|
49
|
+
* order item placed into the next free slot (up to modifier_special.quantity).
|
|
50
|
+
*
|
|
51
|
+
* Returns null if the order item doesn't belong to the provided special.
|
|
52
|
+
*/
|
|
53
|
+
export declare function deStructureSpecialOrderItem(orderItem: IOrderItem, specialItem: IWorkableSpecialMenu<IItem>): {
|
|
54
|
+
modifierSpecials: IModifierSpecials[];
|
|
55
|
+
quantity: number;
|
|
56
|
+
} | null;
|
|
43
57
|
/**
|
|
44
58
|
* Converts an ISpecial into an IItem so it can flow through the standard
|
|
45
59
|
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
@@ -10,6 +10,7 @@ exports.getSpecialsDeletedData = getSpecialsDeletedData;
|
|
|
10
10
|
exports.getSpecialWithPrice = getSpecialWithPrice;
|
|
11
11
|
exports.convertSpecialsToWorkableSpecials = convertSpecialsToWorkableSpecials;
|
|
12
12
|
exports.convertSpecialItemToOrderItem = convertSpecialItemToOrderItem;
|
|
13
|
+
exports.deStructureSpecialOrderItem = deStructureSpecialOrderItem;
|
|
13
14
|
exports.convertSpecialToItem = convertSpecialToItem;
|
|
14
15
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
15
16
|
const constants_1 = require("../../constants");
|
|
@@ -217,6 +218,57 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
|
|
|
217
218
|
return orderItem;
|
|
218
219
|
}
|
|
219
220
|
// ====================================================================================================
|
|
221
|
+
/**
|
|
222
|
+
* De-structures a special IOrderItem back into the legacy selection format
|
|
223
|
+
* used by the SpecialsScreen selection flow (edit without classic preview).
|
|
224
|
+
*
|
|
225
|
+
* Each modifier on the order item maps back to its `IModifierSpecial` group
|
|
226
|
+
* (matched by ref or _id), and each selected option becomes a selection
|
|
227
|
+
* order item placed into the next free slot (up to modifier_special.quantity).
|
|
228
|
+
*
|
|
229
|
+
* Returns null if the order item doesn't belong to the provided special.
|
|
230
|
+
*/
|
|
231
|
+
function deStructureSpecialOrderItem(orderItem, specialItem) {
|
|
232
|
+
if (orderItem.item_id !== specialItem._id)
|
|
233
|
+
return null;
|
|
234
|
+
const orderModifiers = orderItem.modifiers ?? [];
|
|
235
|
+
const modifierSpecials = [];
|
|
236
|
+
for (let i = 0; i < specialItem.modifier_specials.length; i++) {
|
|
237
|
+
const modifierSpecial = specialItem.modifier_specials[i];
|
|
238
|
+
const orderModifier = orderModifiers.find((modifier) => modifier.ref === modifierSpecial._id || modifier._id === modifierSpecial._id);
|
|
239
|
+
const selectedItems = new Array(modifierSpecial.quantity).fill(null);
|
|
240
|
+
if (orderModifier != null) {
|
|
241
|
+
for (let j = 0; j < orderModifier.options.length; j++) {
|
|
242
|
+
const option = orderModifier.options[j];
|
|
243
|
+
const slotIndex = selectedItems.findIndex((item) => item === null);
|
|
244
|
+
if (slotIndex === -1)
|
|
245
|
+
break;
|
|
246
|
+
selectedItems[slotIndex] = {
|
|
247
|
+
_id: option._id,
|
|
248
|
+
item_id: option.ref,
|
|
249
|
+
menu_id: orderItem.menu_id ?? null,
|
|
250
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
251
|
+
name: option.name,
|
|
252
|
+
price: option.price,
|
|
253
|
+
subtotal: option.price,
|
|
254
|
+
tax_rate: 0,
|
|
255
|
+
quantity: option.quantity,
|
|
256
|
+
special_instructions: '',
|
|
257
|
+
item_discount_details: null,
|
|
258
|
+
modifiers: option.modifiers ?? null,
|
|
259
|
+
// These values will be auto calculated
|
|
260
|
+
_discount_amount: 0,
|
|
261
|
+
_gross_amount: 0,
|
|
262
|
+
_gst_amount: 0,
|
|
263
|
+
_net_amount: 0,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
modifierSpecials.push({ _id: modifierSpecial._id, selectedItems });
|
|
268
|
+
}
|
|
269
|
+
return { modifierSpecials, quantity: orderItem.quantity };
|
|
270
|
+
}
|
|
271
|
+
// ====================================================================================================
|
|
220
272
|
/**
|
|
221
273
|
* Converts an ISpecial into an IItem so it can flow through the standard
|
|
222
274
|
* catalog → drawer → cart pipeline just like a regular catalog item.
|