@managesome/eposmatic-toolkit 0.2.658 → 0.2.674
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/lib/helpers/types/order-engine.d.ts +3 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.d.ts +8 -5
- package/lib/helpers/utils/halfhalf-setup-helpers.js +65 -27
- package/lib/helpers/utils/order-engine.js +7 -1
- package/lib/helpers/utils/specials-helpers.d.ts +13 -2
- package/lib/helpers/utils/specials-helpers.js +94 -27
- package/lib/schemas/models/halfhalf_setup.d.ts +58 -3
- package/lib/schemas/models/halfhalf_setup.js +24 -4
- package/lib/schemas/models/orders.d.ts +324 -0
- package/lib/schemas/models/orders.js +12 -0
- package/lib/schemas/models/specials.js +2 -0
- package/lib/schemas/types/halfhalf_setup.d.ts +6 -1
- package/lib/schemas/types/orders.d.ts +3 -0
- package/package.json +1 -1
|
@@ -21,6 +21,9 @@ export interface IOrderEngineItem {
|
|
|
21
21
|
item_type: ORDER_ITEM_TYPE_ENUM;
|
|
22
22
|
is_ready?: boolean;
|
|
23
23
|
is_split?: boolean;
|
|
24
|
+
moved_to_order_id?: string | null;
|
|
25
|
+
moved_from_order_id?: string | null;
|
|
26
|
+
ready_minutes?: number | null;
|
|
24
27
|
name: string;
|
|
25
28
|
description: string;
|
|
26
29
|
loyalty_applied: boolean;
|
|
@@ -38,20 +38,23 @@ interface IConvertHalfHalfToOrderItem {
|
|
|
38
38
|
quantity: number;
|
|
39
39
|
platform: PLATFORMS_ENUM;
|
|
40
40
|
existingOrderItem?: IOrderItem;
|
|
41
|
+
orderItemId?: string;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
44
45
|
* single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
|
|
45
|
-
*
|
|
46
|
-
*
|
|
46
|
+
* whose `_id` is a fresh BSON ObjectId (generated on create, like regular
|
|
47
|
+
* items) and whose `ref` is the segment's deterministic `_id` — so it is the
|
|
48
|
+
* same every time this half-half is punched. Each option's `ref` is the
|
|
49
|
+
* chosen item's `_id`, allowing the item to be de-structured back on edit.
|
|
47
50
|
*/
|
|
48
|
-
export declare function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }: IConvertHalfHalfToOrderItem): IOrderItem;
|
|
51
|
+
export declare function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, orderItemId, }: IConvertHalfHalfToOrderItem): IOrderItem;
|
|
49
52
|
/**
|
|
50
53
|
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
51
54
|
* selection format used by the HalfHalfScreen selection flow.
|
|
52
55
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
56
|
+
* Segment identity: the modifier's ref = the segment's real `_id`. Position
|
|
57
|
+
* and first-empty-slot are kept as fallbacks. Returns null if the order item
|
|
55
58
|
* doesn't belong to the provided halfhalf setup.
|
|
56
59
|
*/
|
|
57
60
|
export declare function deStructureHalfHalfOrderItem(orderItem: IOrderItem, halfHalfItem: IWorkableHalfHalfSetup<IItem>): {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getHalfHalfPostedData = getHalfHalfPostedData;
|
|
4
7
|
exports.renderBulkHalfHalfUpdate = renderBulkHalfHalfUpdate;
|
|
@@ -9,6 +12,7 @@ exports.convertHalfHalfSetupToWorkableHalfHalfSetup = convertHalfHalfSetupToWork
|
|
|
9
12
|
exports.convertHalfHalfToItem = convertHalfHalfToItem;
|
|
10
13
|
exports.convertHalfHalfToOrderItem = convertHalfHalfToOrderItem;
|
|
11
14
|
exports.deStructureHalfHalfOrderItem = deStructureHalfHalfOrderItem;
|
|
15
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
12
16
|
const constants_1 = require("../../constants");
|
|
13
17
|
const store_1 = require("../store");
|
|
14
18
|
const platform_catalog_1 = require("./platform-catalog");
|
|
@@ -103,7 +107,7 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
103
107
|
if (!workableItem)
|
|
104
108
|
continue;
|
|
105
109
|
if (upsell_price != null) {
|
|
106
|
-
workableItem.price = (0, platform_num_1.mergePriceObjs)(workableItem.price,
|
|
110
|
+
workableItem.price = (0, platform_num_1.mergePriceObjs)(workableItem.price, upsell_price);
|
|
107
111
|
}
|
|
108
112
|
if (discount_amount != null) {
|
|
109
113
|
workableItem.discount_amount = null;
|
|
@@ -112,9 +116,9 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
112
116
|
workableItem.price = (0, platform_num_1.mergePriceObjs)(workableItem.price, item.upsell_price);
|
|
113
117
|
}
|
|
114
118
|
// we divide the price by the number of segments
|
|
115
|
-
workableItem.price = (0, platform_num_1.convertPriceObjToSegmentPrice)(workableItem.price, halfhalfSetup.segments);
|
|
119
|
+
workableItem.price = (0, platform_num_1.convertPriceObjToSegmentPrice)(workableItem.price, halfhalfSetup.segments.length);
|
|
116
120
|
// we divide the discount_amount by the number of segments
|
|
117
|
-
workableItem.discount_amount = (0, platform_num_1.convertPriceObjToSegmentPrice)(workableItem.discount_amount, halfhalfSetup.segments);
|
|
121
|
+
workableItem.discount_amount = (0, platform_num_1.convertPriceObjToSegmentPrice)(workableItem.discount_amount, halfhalfSetup.segments.length);
|
|
118
122
|
items.push(workableItem);
|
|
119
123
|
}
|
|
120
124
|
if (items.length === 0)
|
|
@@ -169,6 +173,11 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
169
173
|
}
|
|
170
174
|
// ── Build shared option list (segment-neutral ids) ─────────────
|
|
171
175
|
const halfHalfItems = [...halfhalfSetup.items].sort((a, b) => a.sort_id - b.sort_id);
|
|
176
|
+
// Aggregate the union of keywords/caveats/dietary_preferences across all
|
|
177
|
+
// constituent items so the half-half shows them too.
|
|
178
|
+
const allKeywords = [];
|
|
179
|
+
const allCaveats = [];
|
|
180
|
+
const allDietaryPreferences = [];
|
|
172
181
|
const baseOptions = [];
|
|
173
182
|
for (let i = 0; i < halfHalfItems.length; i++) {
|
|
174
183
|
const halfHalfItem = halfHalfItems[i];
|
|
@@ -178,15 +187,20 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
178
187
|
const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id);
|
|
179
188
|
if (!workableItem)
|
|
180
189
|
continue;
|
|
190
|
+
allKeywords.push(...(workableItem.keywords ?? []));
|
|
191
|
+
allCaveats.push(...(workableItem.caveats ?? []));
|
|
192
|
+
allDietaryPreferences.push(...(workableItem.dietary_preferences ?? []));
|
|
181
193
|
let optionPrice = workableItem.price;
|
|
182
194
|
if (upsell_price != null)
|
|
183
195
|
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, upsell_price);
|
|
184
196
|
if (halfHalfItem.upsell_price != null) {
|
|
185
197
|
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, halfHalfItem.upsell_price);
|
|
186
198
|
}
|
|
187
|
-
optionPrice = (0, platform_num_1.convertPriceObjToSegmentPrice)(optionPrice, halfhalfSetup.segments);
|
|
199
|
+
optionPrice = (0, platform_num_1.convertPriceObjToSegmentPrice)(optionPrice, halfhalfSetup.segments.length);
|
|
188
200
|
baseOptions.push({
|
|
189
|
-
_id
|
|
201
|
+
// `_id` is a generated BSON ObjectId (unique); `ref` is the actual
|
|
202
|
+
// item `_id` (deterministic, used for reporting).
|
|
203
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
190
204
|
ref: catalogItem._id,
|
|
191
205
|
name: catalogItem.name,
|
|
192
206
|
active: catalogItem.active,
|
|
@@ -201,21 +215,27 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
201
215
|
return null;
|
|
202
216
|
// ── Build one single-select modifier per segment ───────────────
|
|
203
217
|
const modifiers = [];
|
|
204
|
-
for (let s = 0; s < halfhalfSetup.segments; s++) {
|
|
218
|
+
for (let s = 0; s < halfhalfSetup.segments.length; s++) {
|
|
219
|
+
const segment = halfhalfSetup.segments[s];
|
|
205
220
|
modifiers.push({
|
|
206
|
-
_id
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
// `_id` is a generated BSON ObjectId (unique per creation); `ref` is the
|
|
222
|
+
// segment's real `_id` — deterministic, unique per portion and the same
|
|
223
|
+
// every time this half-half is punched.
|
|
224
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
225
|
+
ref: segment._id,
|
|
226
|
+
name: segment.name || `Segment ${s + 1}`,
|
|
209
227
|
description: '',
|
|
210
228
|
active: true,
|
|
211
229
|
sold_out: [],
|
|
212
|
-
sort_id: s,
|
|
230
|
+
sort_id: segment.sort_id ?? s,
|
|
213
231
|
min_num_options: 1,
|
|
214
232
|
max_num_options: 1,
|
|
215
233
|
num_free_options: null,
|
|
216
234
|
options: baseOptions.map((option) => ({
|
|
217
235
|
...option,
|
|
218
|
-
_id
|
|
236
|
+
// `_id` is a generated BSON ObjectId (unique); `ref` stays the item
|
|
237
|
+
// `_id` (deterministic, used for reporting).
|
|
238
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
219
239
|
})),
|
|
220
240
|
});
|
|
221
241
|
}
|
|
@@ -235,10 +255,10 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
235
255
|
price: null,
|
|
236
256
|
discount_amount,
|
|
237
257
|
is_discount_percentage: halfhalfSetup.is_discount_percentage,
|
|
238
|
-
caveats:
|
|
239
|
-
dietary_preferences:
|
|
258
|
+
caveats: Array.from(new Set(allCaveats)),
|
|
259
|
+
dietary_preferences: Array.from(new Set(allDietaryPreferences)),
|
|
240
260
|
tax_rate: null,
|
|
241
|
-
keywords:
|
|
261
|
+
keywords: Array.from(new Set(allKeywords)),
|
|
242
262
|
image_url: halfhalfSetup.image_url,
|
|
243
263
|
ingredients: null,
|
|
244
264
|
item_special_hours: null, // already resolved into upsell_price / discount_amount
|
|
@@ -256,23 +276,32 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
256
276
|
/**
|
|
257
277
|
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
258
278
|
* single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
|
|
259
|
-
*
|
|
260
|
-
*
|
|
279
|
+
* whose `_id` is a fresh BSON ObjectId (generated on create, like regular
|
|
280
|
+
* items) and whose `ref` is the segment's deterministic `_id` — so it is the
|
|
281
|
+
* same every time this half-half is punched. Each option's `ref` is the
|
|
282
|
+
* chosen item's `_id`, allowing the item to be de-structured back on edit.
|
|
261
283
|
*/
|
|
262
|
-
function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }) {
|
|
284
|
+
function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, orderItemId, }) {
|
|
263
285
|
const modifiers = [];
|
|
264
286
|
let menu_id;
|
|
265
287
|
for (let s = 0; s < selectedHalfHalfItems.length; s++) {
|
|
266
288
|
const selectedItem = selectedHalfHalfItems[s];
|
|
267
289
|
if (!selectedItem)
|
|
268
290
|
continue;
|
|
291
|
+
// The selected menu id (each selection item carries it) — the half-half
|
|
292
|
+
// belongs to the selected menu; only its constituent items (segments)
|
|
293
|
+
// bypass the menu filter.
|
|
269
294
|
if (selectedItem.menu_id != null && menu_id == null) {
|
|
270
295
|
menu_id = selectedItem.menu_id;
|
|
271
296
|
}
|
|
272
297
|
modifiers.push({
|
|
273
|
-
_id
|
|
274
|
-
|
|
275
|
-
|
|
298
|
+
// `_id` must be a BSON ObjectId — generated on create, same as regular
|
|
299
|
+
// order items (convertItemToOrderItem).
|
|
300
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
301
|
+
// Deterministic ref = the segment's real `_id` — unique per portion and
|
|
302
|
+
// the same every time this half-half is punched.
|
|
303
|
+
ref: halfHalfItem.segments[s]?._id ?? halfHalfItem._id,
|
|
304
|
+
name: halfHalfItem.segments[s]?.name || `Segment ${s + 1}`,
|
|
276
305
|
options: [
|
|
277
306
|
{
|
|
278
307
|
_id: selectedItem._id,
|
|
@@ -294,8 +323,13 @@ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quant
|
|
|
294
323
|
_gst_amount: 0,
|
|
295
324
|
_discount_amount: 0,
|
|
296
325
|
...existingOrderItem,
|
|
297
|
-
|
|
326
|
+
// Keep the original order-item id on edit (otherwise getCartItemsObj would
|
|
327
|
+
// treat it as removed + new); generate a fresh ObjectId on create, same as
|
|
328
|
+
// regular items.
|
|
329
|
+
_id: existingOrderItem?._id ?? orderItemId ?? (0, bson_objectid_1.default)().toHexString(),
|
|
298
330
|
item_id: halfHalfItem._id,
|
|
331
|
+
// The half-half belongs to the selected menu; only its constituent items
|
|
332
|
+
// (segments) bypass the menu filter.
|
|
299
333
|
menu_id,
|
|
300
334
|
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
301
335
|
name: halfHalfItem.name,
|
|
@@ -315,20 +349,24 @@ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quant
|
|
|
315
349
|
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
316
350
|
* selection format used by the HalfHalfScreen selection flow.
|
|
317
351
|
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
352
|
+
* Segment identity: the modifier's ref = the segment's real `_id`. Position
|
|
353
|
+
* and first-empty-slot are kept as fallbacks. Returns null if the order item
|
|
320
354
|
* doesn't belong to the provided halfhalf setup.
|
|
321
355
|
*/
|
|
322
356
|
function deStructureHalfHalfOrderItem(orderItem, halfHalfItem) {
|
|
323
357
|
if (orderItem.item_id !== halfHalfItem._id)
|
|
324
358
|
return null;
|
|
325
|
-
const selectedHalfHalfItems = new Array(halfHalfItem.segments).fill(null);
|
|
359
|
+
const selectedHalfHalfItems = new Array(halfHalfItem.segments.length).fill(null);
|
|
326
360
|
const orderModifiers = orderItem.modifiers ?? [];
|
|
327
361
|
for (let i = 0; i < orderModifiers.length; i++) {
|
|
328
362
|
const orderModifier = orderModifiers[i];
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
363
|
+
// Segment identity: the modifier ref = the segment's real `_id`; position
|
|
364
|
+
// and first-empty-slot are fallbacks for edge cases.
|
|
365
|
+
const modifierRef = orderModifier.ref ?? orderModifier._id ?? '';
|
|
366
|
+
let segmentIndex = halfHalfItem.segments.findIndex((segment) => segment._id === modifierRef);
|
|
367
|
+
if (segmentIndex === -1)
|
|
368
|
+
segmentIndex = i;
|
|
369
|
+
if (segmentIndex < 0 || segmentIndex >= selectedHalfHalfItems.length) {
|
|
332
370
|
// Fallback: assign to the first empty slot
|
|
333
371
|
segmentIndex = selectedHalfHalfItems.findIndex((item) => item === null);
|
|
334
372
|
if (segmentIndex === -1)
|
|
@@ -487,6 +487,9 @@ function convertOrderEngineItemToOrderItem(orderItem, tenantId, offers, giftCard
|
|
|
487
487
|
item_type: orderItem.item_type,
|
|
488
488
|
is_ready: orderItem.is_ready,
|
|
489
489
|
is_split: orderItem.is_split,
|
|
490
|
+
moved_to_order_id: orderItem.moved_to_order_id,
|
|
491
|
+
moved_from_order_id: orderItem.moved_from_order_id,
|
|
492
|
+
ready_minutes: orderItem.ready_minutes,
|
|
490
493
|
name: orderItem.name,
|
|
491
494
|
price: orderItem.price,
|
|
492
495
|
subtotal: orderItem.price,
|
|
@@ -570,7 +573,7 @@ function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenant
|
|
|
570
573
|
}
|
|
571
574
|
const { _id = (0, bson_objectid_1.default)().toHexString(), menu_id = defaultMenuId,
|
|
572
575
|
// For New Item, If zeroPriceRefs is present then we set the price to 0
|
|
573
|
-
price = defaultItemPrice, tax_rate = (0, platform_catalog_1.getPriceEnum)(item.tax_rate, platform), quantity = 1, subtotal = 0, special_instructions = '', item_discount_details = convertItemDiscountToOrderItemDiscount(discount_amount, is_special_discount_percentage, platform, item._id), item_type = orderItemType, is_ready, is_split, } = orderItem ?? {};
|
|
576
|
+
price = defaultItemPrice, tax_rate = (0, platform_catalog_1.getPriceEnum)(item.tax_rate, platform), quantity = 1, subtotal = 0, special_instructions = '', item_discount_details = convertItemDiscountToOrderItemDiscount(discount_amount, is_special_discount_percentage, platform, item._id), item_type = orderItemType, is_ready, is_split, moved_to_order_id, moved_from_order_id, ready_minutes, } = orderItem ?? {};
|
|
574
577
|
const loyaltyApplied = applyLoyalty != null && applyLoyalty.refs.includes(item._id);
|
|
575
578
|
const voucherApplied = applyVoucher != null && applyVoucher.refs.includes(item._id);
|
|
576
579
|
let mergedItemDiscountDetails = item_discount_details;
|
|
@@ -616,6 +619,9 @@ function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenant
|
|
|
616
619
|
item_type,
|
|
617
620
|
is_ready,
|
|
618
621
|
is_split,
|
|
622
|
+
moved_to_order_id,
|
|
623
|
+
moved_from_order_id,
|
|
624
|
+
ready_minutes,
|
|
619
625
|
price,
|
|
620
626
|
tax_rate,
|
|
621
627
|
quantity,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PLATFORMS_ENUM } from '../../constants';
|
|
2
|
-
import { IItem, IOrderItem, ISpecial } from '../../schemas';
|
|
2
|
+
import { IItem, IModifier, IOrderItem, ISpecial } from '../../schemas';
|
|
3
3
|
import { ISimplifiedCatalogItem } from '../types';
|
|
4
4
|
export declare function getSpecialsPostedData(data: ISpecial[], payload: ISpecial): ISpecial[];
|
|
5
5
|
export declare function renderBulkSpecialsUpdate(data: ISpecial[], payload: Partial<ISpecial>[]): ISpecial[];
|
|
@@ -29,6 +29,16 @@ export type IWorkableSpecialMenu<T extends IItem | ISimplifiedCatalogItem> = {
|
|
|
29
29
|
show_starting_from: ISpecial['show_starting_from'];
|
|
30
30
|
modifier_specials: IWorkableModifierSpecial<T>[];
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Applies a modifier-special group's reference rules to a constituent item's
|
|
34
|
+
* own modifiers:
|
|
35
|
+
* - excluded_refs: modifiers/options whose ref is listed are REMOVED.
|
|
36
|
+
* - exclusive_refs: modifiers/options whose ref is listed have their PRICE
|
|
37
|
+
* REMOVED (set to null → treated as free) but stay selectable.
|
|
38
|
+
*
|
|
39
|
+
* Returns null when nothing is left after exclusion.
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyModifierSpecialRefRules(modifiers: IModifier[] | null | undefined, exclusiveRefs: string[], excludedRefs: string[]): IModifier[] | null;
|
|
32
42
|
export declare function convertSpecialsToWorkableSpecials<T extends IItem | ISimplifiedCatalogItem>(specials: ISpecial[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableSpecialMenu<T>[];
|
|
33
43
|
interface IModifierSpecials {
|
|
34
44
|
_id: string;
|
|
@@ -40,8 +50,9 @@ interface IConvertSpecialItemToOrderItem {
|
|
|
40
50
|
quantity: number;
|
|
41
51
|
platform: PLATFORMS_ENUM;
|
|
42
52
|
existingOrderItem?: IOrderItem;
|
|
53
|
+
orderItemId?: string;
|
|
43
54
|
}
|
|
44
|
-
export declare function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, }: IConvertSpecialItemToOrderItem): IOrderItem;
|
|
55
|
+
export declare function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, orderItemId, }: IConvertSpecialItemToOrderItem): IOrderItem;
|
|
45
56
|
/**
|
|
46
57
|
* De-structures a special IOrderItem back into the legacy selection format
|
|
47
58
|
* used by the SpecialsScreen selection flow (edit without classic preview).
|
|
@@ -8,6 +8,7 @@ exports.renderBulkSpecialsUpdate = renderBulkSpecialsUpdate;
|
|
|
8
8
|
exports.getSpecialsUpdatedData = getSpecialsUpdatedData;
|
|
9
9
|
exports.getSpecialsDeletedData = getSpecialsDeletedData;
|
|
10
10
|
exports.getSpecialWithPrice = getSpecialWithPrice;
|
|
11
|
+
exports.applyModifierSpecialRefRules = applyModifierSpecialRefRules;
|
|
11
12
|
exports.convertSpecialsToWorkableSpecials = convertSpecialsToWorkableSpecials;
|
|
12
13
|
exports.convertSpecialItemToOrderItem = convertSpecialItemToOrderItem;
|
|
13
14
|
exports.deStructureSpecialOrderItem = deStructureSpecialOrderItem;
|
|
@@ -18,6 +19,7 @@ const store_1 = require("../store");
|
|
|
18
19
|
const order_engine_1 = require("./order-engine");
|
|
19
20
|
const platform_catalog_1 = require("./platform-catalog");
|
|
20
21
|
const platform_num_1 = require("./platform-num");
|
|
22
|
+
const price_conversion_1 = require("./price-conversion");
|
|
21
23
|
function getSpecialsPostedData(data, payload) {
|
|
22
24
|
return data.some((special) => special._id === payload._id)
|
|
23
25
|
? data
|
|
@@ -50,10 +52,12 @@ function getSpecialsDeletedData(data, payload) {
|
|
|
50
52
|
function getSpecialWithPrice(special, writeable) {
|
|
51
53
|
const convertToPrice = writeable ? platform_num_1.convertPriceObjToCents : platform_num_1.convertPriceObjFromCents;
|
|
52
54
|
const convertItemSpecialHours = writeable ? platform_num_1.convertSpecialHoursToCents : platform_num_1.convertSpecialHoursFromCents;
|
|
55
|
+
const convertNumPrice = writeable ? price_conversion_1.convertPriceToCents : price_conversion_1.convertPriceFromCents;
|
|
53
56
|
return {
|
|
54
57
|
...special,
|
|
55
58
|
...(special.price != null ? { price: convertToPrice(special.price) } : {}),
|
|
56
59
|
...(special.discount_amount != null ? { discount_amount: convertToPrice(special.discount_amount) } : {}),
|
|
60
|
+
...(special.display_price != null ? { display_price: convertNumPrice(special.display_price) } : {}),
|
|
57
61
|
...(special.item_special_hours != null
|
|
58
62
|
? {
|
|
59
63
|
item_special_hours: convertItemSpecialHours(special.item_special_hours),
|
|
@@ -72,6 +76,39 @@ function getSpecialWithPrice(special, writeable) {
|
|
|
72
76
|
: {}),
|
|
73
77
|
};
|
|
74
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Applies a modifier-special group's reference rules to a constituent item's
|
|
81
|
+
* own modifiers:
|
|
82
|
+
* - excluded_refs: modifiers/options whose ref is listed are REMOVED.
|
|
83
|
+
* - exclusive_refs: modifiers/options whose ref is listed have their PRICE
|
|
84
|
+
* REMOVED (set to null → treated as free) but stay selectable.
|
|
85
|
+
*
|
|
86
|
+
* Returns null when nothing is left after exclusion.
|
|
87
|
+
*/
|
|
88
|
+
function applyModifierSpecialRefRules(modifiers, exclusiveRefs, excludedRefs) {
|
|
89
|
+
if (!modifiers || modifiers.length === 0)
|
|
90
|
+
return null;
|
|
91
|
+
let result = modifiers.map((modifier) => {
|
|
92
|
+
const isModifierExclusive = exclusiveRefs.includes(modifier.ref);
|
|
93
|
+
const options = modifier.options.map((option) => {
|
|
94
|
+
if (isModifierExclusive || exclusiveRefs.includes(option.ref)) {
|
|
95
|
+
return { ...option, price: null };
|
|
96
|
+
}
|
|
97
|
+
return option;
|
|
98
|
+
});
|
|
99
|
+
return { ...modifier, options };
|
|
100
|
+
});
|
|
101
|
+
if (excludedRefs.length > 0) {
|
|
102
|
+
result = result
|
|
103
|
+
.filter((modifier) => !excludedRefs.includes(modifier.ref))
|
|
104
|
+
.map((modifier) => ({
|
|
105
|
+
...modifier,
|
|
106
|
+
options: modifier.options.filter((option) => !excludedRefs.includes(option.ref)),
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
const withOptions = result.filter((modifier) => modifier.options.length > 0);
|
|
110
|
+
return withOptions.length > 0 ? withOptions : null;
|
|
111
|
+
}
|
|
75
112
|
function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_id) {
|
|
76
113
|
if (!platform || !tenant_id)
|
|
77
114
|
return [];
|
|
@@ -122,6 +159,9 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
122
159
|
if (item.upsell_price != null) {
|
|
123
160
|
workableItem.price = (0, platform_num_1.mergePriceObjs)(workableItem.price, item.upsell_price);
|
|
124
161
|
}
|
|
162
|
+
// Apply the group's reference rules to the item's own modifiers:
|
|
163
|
+
// excluded_refs removes modifiers/options, exclusive_refs removes their price.
|
|
164
|
+
workableItem.modifiers = applyModifierSpecialRefRules(workableItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
125
165
|
items.push(workableItem);
|
|
126
166
|
}
|
|
127
167
|
if (items.length === 0)
|
|
@@ -154,7 +194,7 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
154
194
|
}
|
|
155
195
|
return specialsMenu;
|
|
156
196
|
}
|
|
157
|
-
function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, }) {
|
|
197
|
+
function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, orderItemId, }) {
|
|
158
198
|
const modifiers = [];
|
|
159
199
|
let menu_id;
|
|
160
200
|
for (let i = 0; i < modifierSpecials.length; i++) {
|
|
@@ -167,7 +207,16 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
|
|
|
167
207
|
const selectedItem = modifierSpecial.selectedItems[j];
|
|
168
208
|
if (!selectedItem)
|
|
169
209
|
continue;
|
|
170
|
-
|
|
210
|
+
// The selected menu id (each selection item carries it) — the special
|
|
211
|
+
// belongs to the selected menu; only its constituent items (modifiers)
|
|
212
|
+
// bypass the menu filter.
|
|
213
|
+
if (selectedItem.menu_id != null && menu_id == null) {
|
|
214
|
+
menu_id = selectedItem.menu_id;
|
|
215
|
+
}
|
|
216
|
+
// `_id` must be a BSON ObjectId (backend rejects plain strings). The
|
|
217
|
+
// selection item already carries a valid ObjectId — random on create and
|
|
218
|
+
// stable across edit round-trips. Determinism lives in `ref`.
|
|
219
|
+
options.push({
|
|
171
220
|
_id: selectedItem._id,
|
|
172
221
|
ref: selectedItem.item_id,
|
|
173
222
|
name: selectedItem.name,
|
|
@@ -175,12 +224,25 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
|
|
|
175
224
|
quantity: selectedItem.quantity,
|
|
176
225
|
modifiers: selectedItem.modifiers,
|
|
177
226
|
is_free: false,
|
|
178
|
-
};
|
|
179
|
-
options.push(option);
|
|
180
|
-
if (selectedItem.menu_id != null && menu_id == null) {
|
|
181
|
-
menu_id = selectedItem.menu_id;
|
|
182
|
-
}
|
|
227
|
+
});
|
|
183
228
|
}
|
|
229
|
+
// Mark the cheapest N selected items as free (num_free_items), same as the
|
|
230
|
+
// classic drawer flow (makeSpaceForFreeOptions semantics). Slot order kept.
|
|
231
|
+
const numFreeItems = originalModifierSpecial.num_free_items || 0;
|
|
232
|
+
if (numFreeItems > 0 && options.length > 0) {
|
|
233
|
+
const freeIndexes = new Set(options
|
|
234
|
+
.map((option, index) => ({ index, value: (option.price || 0) * (option.quantity || 1) }))
|
|
235
|
+
.sort((a, b) => a.value - b.value)
|
|
236
|
+
.slice(0, numFreeItems)
|
|
237
|
+
.map((entry) => entry.index));
|
|
238
|
+
options.forEach((option, index) => {
|
|
239
|
+
if (freeIndexes.has(index)) {
|
|
240
|
+
option.is_free = true;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
// Modifier `_id` must be a BSON ObjectId — generated on create (same as the
|
|
245
|
+
// order engine). Edit matching uses the deterministic `ref`.
|
|
184
246
|
const modifier = {
|
|
185
247
|
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
186
248
|
ref: originalModifierSpecial._id,
|
|
@@ -197,8 +259,13 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
|
|
|
197
259
|
_gst_amount: 0,
|
|
198
260
|
_discount_amount: 0,
|
|
199
261
|
...existingOrderItem,
|
|
200
|
-
|
|
262
|
+
// Keep the original order-item id on edit (otherwise getCartItemsObj would
|
|
263
|
+
// treat it as removed + new); generate a fresh ObjectId on create, same as
|
|
264
|
+
// regular items.
|
|
265
|
+
_id: existingOrderItem?._id ?? orderItemId ?? (0, bson_objectid_1.default)().toHexString(),
|
|
201
266
|
item_id: specialItem._id,
|
|
267
|
+
// The special belongs to the selected menu; only its constituent items
|
|
268
|
+
// (modifiers) bypass the menu filter.
|
|
202
269
|
menu_id,
|
|
203
270
|
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
204
271
|
/*
|
|
@@ -306,6 +373,9 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
306
373
|
}
|
|
307
374
|
// ── Build modifiers from modifier_specials ─────────────────────
|
|
308
375
|
const modifiers = [];
|
|
376
|
+
const allKeywords = [];
|
|
377
|
+
const allCaveats = [];
|
|
378
|
+
const allDietaryPreferences = [];
|
|
309
379
|
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
310
380
|
const modifierSpecial = special.modifier_specials[j];
|
|
311
381
|
const omitItemLevelSchedule = modifierSpecial.omit_items_schedule;
|
|
@@ -320,6 +390,9 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
320
390
|
const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true);
|
|
321
391
|
if (!workableItem)
|
|
322
392
|
continue;
|
|
393
|
+
allKeywords.push(...(workableItem.keywords ?? []));
|
|
394
|
+
allCaveats.push(...(workableItem.caveats ?? []));
|
|
395
|
+
allDietaryPreferences.push(...(workableItem.dietary_preferences ?? []));
|
|
323
396
|
// Determine option price:
|
|
324
397
|
// special has its own price → options carry null price
|
|
325
398
|
// (num_free_options in the drawer handles free-vs-paid)
|
|
@@ -329,22 +402,13 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
329
402
|
if (specialItem.upsell_price != null) {
|
|
330
403
|
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, specialItem.upsell_price);
|
|
331
404
|
}
|
|
332
|
-
// Pre-filter the item's own modifiers using excluded_refs / exclusive_refs
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
let filtered = workableItem.modifiers;
|
|
336
|
-
if (modifierSpecial.exclusive_refs.length > 0) {
|
|
337
|
-
// Only keep modifiers whose ref is in exclusive_refs
|
|
338
|
-
filtered = filtered.filter((m) => modifierSpecial.exclusive_refs.includes(m.ref));
|
|
339
|
-
}
|
|
340
|
-
else if (modifierSpecial.excluded_refs.length > 0) {
|
|
341
|
-
// Remove modifiers whose ref is in excluded_refs
|
|
342
|
-
filtered = filtered.filter((m) => !modifierSpecial.excluded_refs.includes(m.ref));
|
|
343
|
-
}
|
|
344
|
-
itemModifiers = filtered.length > 0 ? filtered : null;
|
|
345
|
-
}
|
|
405
|
+
// Pre-filter the item's own modifiers using excluded_refs / exclusive_refs:
|
|
406
|
+
// excluded_refs removes modifiers/options, exclusive_refs removes their price.
|
|
407
|
+
const itemModifiers = applyModifierSpecialRefRules(workableItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
346
408
|
options.push({
|
|
347
|
-
_id
|
|
409
|
+
// `_id` is a generated BSON ObjectId (unique); `ref` is the actual
|
|
410
|
+
// item `_id` (deterministic, used for reporting).
|
|
411
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
348
412
|
ref: catalogItem._id,
|
|
349
413
|
name: catalogItem.name,
|
|
350
414
|
active: catalogItem.active,
|
|
@@ -358,7 +422,10 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
358
422
|
if (options.length === 0)
|
|
359
423
|
continue;
|
|
360
424
|
modifiers.push({
|
|
361
|
-
_id
|
|
425
|
+
// `_id` is a generated BSON ObjectId — unique identifier of this
|
|
426
|
+
// modifier instance; `ref` is the source modifier-special `_id`
|
|
427
|
+
// (deterministic, used for matching/reporting).
|
|
428
|
+
_id: (0, bson_objectid_1.default)().toHexString(),
|
|
362
429
|
ref: modifierSpecial._id,
|
|
363
430
|
name: modifierSpecial.name,
|
|
364
431
|
description: '',
|
|
@@ -387,10 +454,10 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
387
454
|
price,
|
|
388
455
|
discount_amount,
|
|
389
456
|
is_discount_percentage: special.is_discount_percentage,
|
|
390
|
-
caveats:
|
|
391
|
-
dietary_preferences:
|
|
457
|
+
caveats: Array.from(new Set(allCaveats)),
|
|
458
|
+
dietary_preferences: Array.from(new Set(allDietaryPreferences)),
|
|
392
459
|
tax_rate: null,
|
|
393
|
-
keywords:
|
|
460
|
+
keywords: Array.from(new Set(allKeywords)),
|
|
394
461
|
image_url: special.image_url,
|
|
395
462
|
ingredients: null,
|
|
396
463
|
item_special_hours: null, // already resolved into price / discount_amount
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
+
export declare const HalfHalfSegmentSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
3
|
+
minimize: false;
|
|
4
|
+
}, {
|
|
5
|
+
_id: import("mongoose").Types.ObjectId;
|
|
6
|
+
name: string;
|
|
7
|
+
sort_id: number;
|
|
8
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
9
|
+
_id: import("mongoose").Types.ObjectId;
|
|
10
|
+
name: string;
|
|
11
|
+
sort_id: number;
|
|
12
|
+
}>> & import("mongoose").FlatRecord<{
|
|
13
|
+
_id: import("mongoose").Types.ObjectId;
|
|
14
|
+
name: string;
|
|
15
|
+
sort_id: number;
|
|
16
|
+
}> & Required<{
|
|
17
|
+
_id: import("mongoose").Types.ObjectId;
|
|
18
|
+
}> & {
|
|
19
|
+
__v: number;
|
|
20
|
+
}>;
|
|
2
21
|
export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
3
22
|
timestamps: true;
|
|
4
23
|
versionKey: false;
|
|
@@ -490,7 +509,19 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
490
509
|
}>;
|
|
491
510
|
excluded_refs: string[];
|
|
492
511
|
exclusive_refs: string[];
|
|
493
|
-
segments:
|
|
512
|
+
segments: import("mongoose").Types.DocumentArray<{
|
|
513
|
+
_id: import("mongoose").Types.ObjectId;
|
|
514
|
+
name: string;
|
|
515
|
+
sort_id: number;
|
|
516
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
517
|
+
_id: import("mongoose").Types.ObjectId;
|
|
518
|
+
name: string;
|
|
519
|
+
sort_id: number;
|
|
520
|
+
}> & {
|
|
521
|
+
_id: import("mongoose").Types.ObjectId;
|
|
522
|
+
name: string;
|
|
523
|
+
sort_id: number;
|
|
524
|
+
}>;
|
|
494
525
|
upsell_price: {
|
|
495
526
|
"POS_WALK-IN": number;
|
|
496
527
|
"POS_TAKE-AWAY": number;
|
|
@@ -1022,7 +1053,19 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1022
1053
|
}>;
|
|
1023
1054
|
excluded_refs: string[];
|
|
1024
1055
|
exclusive_refs: string[];
|
|
1025
|
-
segments:
|
|
1056
|
+
segments: import("mongoose").Types.DocumentArray<{
|
|
1057
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1058
|
+
name: string;
|
|
1059
|
+
sort_id: number;
|
|
1060
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
1061
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1062
|
+
name: string;
|
|
1063
|
+
sort_id: number;
|
|
1064
|
+
}> & {
|
|
1065
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1066
|
+
name: string;
|
|
1067
|
+
sort_id: number;
|
|
1068
|
+
}>;
|
|
1026
1069
|
upsell_price: {
|
|
1027
1070
|
"POS_WALK-IN": number;
|
|
1028
1071
|
"POS_TAKE-AWAY": number;
|
|
@@ -1554,7 +1597,19 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1554
1597
|
}>;
|
|
1555
1598
|
excluded_refs: string[];
|
|
1556
1599
|
exclusive_refs: string[];
|
|
1557
|
-
segments:
|
|
1600
|
+
segments: import("mongoose").Types.DocumentArray<{
|
|
1601
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1602
|
+
name: string;
|
|
1603
|
+
sort_id: number;
|
|
1604
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
1605
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1606
|
+
name: string;
|
|
1607
|
+
sort_id: number;
|
|
1608
|
+
}> & {
|
|
1609
|
+
_id: import("mongoose").Types.ObjectId;
|
|
1610
|
+
name: string;
|
|
1611
|
+
sort_id: number;
|
|
1612
|
+
}>;
|
|
1558
1613
|
upsell_price: {
|
|
1559
1614
|
"POS_WALK-IN": number;
|
|
1560
1615
|
"POS_TAKE-AWAY": number;
|