@managesome/eposmatic-toolkit 0.2.693 → 0.2.694
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/utils/halfhalf-setup-helpers.d.ts +12 -3
- package/lib/helpers/utils/halfhalf-setup-helpers.js +36 -43
- package/lib/helpers/utils/platform-catalog.d.ts +46 -0
- package/lib/helpers/utils/platform-catalog.js +61 -0
- package/lib/helpers/utils/specials-helpers.d.ts +14 -3
- package/lib/helpers/utils/specials-helpers.js +44 -37
- package/package.json +1 -1
|
@@ -31,10 +31,19 @@ export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends II
|
|
|
31
31
|
* item, priced as `(item price + upsells) / segments`), so duplicates across
|
|
32
32
|
* segments are allowed and each segment must be filled exactly once.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
35
|
+
* included_platforms) and no special-hours / platform-based price
|
|
36
|
+
* resolution happens here. Setup fields are copied through as-is:
|
|
37
|
+
* - `item_special_hours` is preserved on the output item,
|
|
38
|
+
* - each option's `excluded_platforms` is derived (complement) from its
|
|
39
|
+
* source item's `included_platforms`, so platform availability can be
|
|
40
|
+
* applied by the filter layer downstream,
|
|
41
|
+
* - `choose_expensive_segment_price` compares segment prices by `BASE_PRICE`
|
|
42
|
+
* (platform-neutral) and copies the actual IPrice object through.
|
|
43
|
+
*
|
|
44
|
+
* Returns null only when no option can be resolved from the items map.
|
|
36
45
|
*/
|
|
37
|
-
export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem
|
|
46
|
+
export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>): IItem | null;
|
|
38
47
|
interface IConvertHalfHalfToOrderItem {
|
|
39
48
|
halfHalfItem: IWorkableHalfHalfSetup<IItem>;
|
|
40
49
|
selectedHalfHalfItems: (IOrderItem | null)[];
|
|
@@ -187,32 +187,23 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
187
187
|
* item, priced as `(item price + upsells) / segments`), so duplicates across
|
|
188
188
|
* segments are allowed and each segment must be filled exactly once.
|
|
189
189
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
190
|
+
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
191
|
+
* included_platforms) and no special-hours / platform-based price
|
|
192
|
+
* resolution happens here. Setup fields are copied through as-is:
|
|
193
|
+
* - `item_special_hours` is preserved on the output item,
|
|
194
|
+
* - each option's `excluded_platforms` is derived (complement) from its
|
|
195
|
+
* source item's `included_platforms`, so platform availability can be
|
|
196
|
+
* applied by the filter layer downstream,
|
|
197
|
+
* - `choose_expensive_segment_price` compares segment prices by `BASE_PRICE`
|
|
198
|
+
* (platform-neutral) and copies the actual IPrice object through.
|
|
199
|
+
*
|
|
200
|
+
* Returns null only when no option can be resolved from the items map.
|
|
192
201
|
*/
|
|
193
|
-
function convertHalfHalfToItem(halfhalfSetup, itemsMap
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
// ── Schedule resolution ────────────────────────────────────────
|
|
201
|
-
const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(halfhalfSetup.item_special_hours, platform);
|
|
202
|
-
if (applicableSchedule === false)
|
|
203
|
-
return null;
|
|
204
|
-
let upsell_price = halfhalfSetup.upsell_price;
|
|
205
|
-
let discount_amount = halfhalfSetup.discount_amount;
|
|
206
|
-
let is_discount_percentage = halfhalfSetup.is_discount_percentage;
|
|
207
|
-
if (applicableSchedule !== true) {
|
|
208
|
-
if (applicableSchedule.price != null)
|
|
209
|
-
upsell_price = applicableSchedule.price;
|
|
210
|
-
if (applicableSchedule.discount_amount != null) {
|
|
211
|
-
discount_amount = applicableSchedule.discount_amount;
|
|
212
|
-
// the schedule also carries the percentage flag (same as IItem)
|
|
213
|
-
is_discount_percentage = applicableSchedule.is_discount_percentage;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
202
|
+
function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
|
|
203
|
+
// Fields are carried through as-is (no schedule resolution here).
|
|
204
|
+
const upsell_price = halfhalfSetup.upsell_price;
|
|
205
|
+
const discount_amount = halfhalfSetup.discount_amount;
|
|
206
|
+
const is_discount_percentage = halfhalfSetup.is_discount_percentage;
|
|
216
207
|
// ── Build shared option list (segment-neutral ids) ─────────────
|
|
217
208
|
const halfHalfItems = [...halfhalfSetup.items]
|
|
218
209
|
// Respect excluded_refs: items whose item_id (ref) is listed are removed
|
|
@@ -230,38 +221,35 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
230
221
|
const catalogItem = itemsMap[halfHalfItem.item_id];
|
|
231
222
|
if (!catalogItem)
|
|
232
223
|
continue;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
allKeywords.push(...(workableItem.keywords ?? []));
|
|
237
|
-
allCaveats.push(...(workableItem.caveats ?? []));
|
|
238
|
-
allDietaryPreferences.push(...(workableItem.dietary_preferences ?? []));
|
|
224
|
+
allKeywords.push(...(catalogItem.keywords ?? []));
|
|
225
|
+
allCaveats.push(...(catalogItem.caveats ?? []));
|
|
226
|
+
allDietaryPreferences.push(...(catalogItem.dietary_preferences ?? []));
|
|
239
227
|
optionEntries.push({
|
|
240
|
-
workableItem,
|
|
241
|
-
itemUpsell: halfHalfItem.upsell_price,
|
|
242
228
|
catalogItem,
|
|
229
|
+
itemUpsell: halfHalfItem.upsell_price,
|
|
243
230
|
sortId: halfHalfItem.sort_id,
|
|
244
231
|
});
|
|
245
232
|
}
|
|
246
233
|
// choose_expensive_segment_price: copy the most expensive segment's BASE
|
|
247
234
|
// price into every segment's base price (each half still keeps its own
|
|
248
|
-
// item-level upsell).
|
|
235
|
+
// item-level upsell). Comparison uses BASE_PRICE (platform-neutral); the
|
|
236
|
+
// actual IPrice object is copied through unresolved.
|
|
249
237
|
let expensiveBasePrice = null;
|
|
250
238
|
if (halfhalfSetup.choose_expensive_segment_price && optionEntries.length > 0) {
|
|
251
|
-
expensiveBasePrice = optionEntries[0].
|
|
252
|
-
let maxValue =
|
|
239
|
+
expensiveBasePrice = optionEntries[0].catalogItem.price;
|
|
240
|
+
let maxValue = expensiveBasePrice?.BASE_PRICE ?? 0;
|
|
253
241
|
for (const entry of optionEntries) {
|
|
254
|
-
const value =
|
|
242
|
+
const value = entry.catalogItem.price?.BASE_PRICE ?? 0;
|
|
255
243
|
if (value > maxValue) {
|
|
256
244
|
maxValue = value;
|
|
257
|
-
expensiveBasePrice = entry.
|
|
245
|
+
expensiveBasePrice = entry.catalogItem.price;
|
|
258
246
|
}
|
|
259
247
|
}
|
|
260
248
|
}
|
|
261
249
|
const baseOptions = [];
|
|
262
250
|
for (const entry of optionEntries) {
|
|
263
|
-
const {
|
|
264
|
-
let optionPrice = expensiveBasePrice != null ? expensiveBasePrice :
|
|
251
|
+
const { catalogItem, itemUpsell, sortId } = entry;
|
|
252
|
+
let optionPrice = expensiveBasePrice != null ? expensiveBasePrice : catalogItem.price;
|
|
265
253
|
// Each half keeps its own item-level upsell. The half-half upsell is a
|
|
266
254
|
// ONE-TIME addition on the item price, not merged per segment.
|
|
267
255
|
if (itemUpsell != null) {
|
|
@@ -280,9 +268,14 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
280
268
|
active: catalogItem.active,
|
|
281
269
|
sold_out: catalogItem.sold_out,
|
|
282
270
|
sort_id: sortId,
|
|
283
|
-
|
|
271
|
+
// Derived from the source item's included platforms (pure mapping),
|
|
272
|
+
// so platform availability can be applied by the filter layer downstream.
|
|
273
|
+
excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
|
|
274
|
+
// Carry the source item's special hours so the filter layer can apply
|
|
275
|
+
// schedule availability (pure mapping, no resolution here).
|
|
276
|
+
item_modifier_option_special_hours: catalogItem.item_special_hours,
|
|
284
277
|
price: optionPrice,
|
|
285
|
-
modifiers: (0, specials_helpers_1.applyModifierSpecialRefRules)(
|
|
278
|
+
modifiers: (0, specials_helpers_1.applyModifierSpecialRefRules)(catalogItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs),
|
|
286
279
|
});
|
|
287
280
|
}
|
|
288
281
|
if (baseOptions.length === 0)
|
|
@@ -336,7 +329,7 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
|
336
329
|
keywords: Array.from(new Set(allKeywords)),
|
|
337
330
|
image_url: halfhalfSetup.image_url,
|
|
338
331
|
ingredients: null,
|
|
339
|
-
item_special_hours:
|
|
332
|
+
item_special_hours: halfhalfSetup.item_special_hours, // preserved for the availability layer
|
|
340
333
|
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
341
334
|
is_featured: false,
|
|
342
335
|
featured_sort_id: 0,
|
|
@@ -5,8 +5,54 @@ import { ICatalog, ISimplifiedCatalog, ISimplifiedCatalogItem } from '../types';
|
|
|
5
5
|
export declare function getPriceEnum(price: IPrice | null | undefined, platform: PLATFORMS_ENUM | null | undefined): number;
|
|
6
6
|
export declare function areAllSchedulesExpired(special_hours: IItemSpecialHour[] | null | undefined): boolean;
|
|
7
7
|
export declare function findApplicableSchedule(special_hours: IItemSpecialHour[] | null | undefined, platform: PLATFORMS_ENUM): IItemSpecialHour | boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Pure mapping: converts a list of platforms an entity is INCLUDED in into the
|
|
10
|
+
* list of platforms it is EXCLUDED from (complement over all platforms).
|
|
11
|
+
* Used by convert*ToItem to surface a source item's platform membership on
|
|
12
|
+
* the produced options, so the platform filter layer can apply it without
|
|
13
|
+
* the converter itself knowing the target platform.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getExcludedPlatformsFromIncludedPlatforms(includedPlatforms: PLATFORMS_ENUM[]): PLATFORMS_ENUM[];
|
|
16
|
+
/**
|
|
17
|
+
* Availability predicate for entities that share the special / half-half
|
|
18
|
+
* availability shape (active + tenant membership + platform membership +
|
|
19
|
+
* an applicable special-hours schedule right now).
|
|
20
|
+
*
|
|
21
|
+
* Pure conversion functions must NOT perform these checks; availability-aware
|
|
22
|
+
* consumers compose this predicate with the pure converters instead.
|
|
23
|
+
*/
|
|
24
|
+
export interface ISetupApplicabilityContext {
|
|
25
|
+
tenant_id: string;
|
|
26
|
+
platform: PLATFORMS_ENUM;
|
|
27
|
+
}
|
|
28
|
+
type ISetupWithAvailability = {
|
|
29
|
+
active: boolean;
|
|
30
|
+
tenants: string[];
|
|
31
|
+
included_platforms: PLATFORMS_ENUM[];
|
|
32
|
+
item_special_hours: IItemSpecialHour[] | null | undefined;
|
|
33
|
+
};
|
|
34
|
+
export declare function isSetupApplicable(setup: ISetupWithAvailability, { tenant_id, platform }: ISetupApplicabilityContext): boolean;
|
|
8
35
|
export declare function getPlatformModifierOptions(options: IModifierOption[], platform: PLATFORMS_ENUM, excludeIds?: string[]): IModifierOption[];
|
|
9
36
|
export declare function getPlatformModifiers(modifiers: IModifier[] | null | undefined, platform: PLATFORMS_ENUM | undefined, excludeIds?: string[]): IModifier[] | null;
|
|
10
37
|
export declare function convertItemToWorkableItem<T extends IItem | ISimplifiedCatalogItem>(item: T, platform: PLATFORMS_ENUM, tenantId: string | undefined, omitSchedule?: boolean, omitSchedulePricing?: boolean): T | null;
|
|
11
38
|
export declare function convertOptionToWorkableOption(option: IModifierOption, platform: PLATFORMS_ENUM): IModifierOption | null;
|
|
12
39
|
export declare function convertCatalogToWorkableCatalog<T extends ICatalog | ISimplifiedCatalog>(catalogs: T[], platform: PLATFORMS_ENUM | undefined, tenantId: string | undefined): T[];
|
|
40
|
+
/**
|
|
41
|
+
* Filters a converted item's modifier groups down to the ones that have at
|
|
42
|
+
* least one platform-available option (reuses getPlatformModifierOptions:
|
|
43
|
+
* active + excluded_platforms + option schedule).
|
|
44
|
+
*/
|
|
45
|
+
export declare function getPlatformAvailableModifiers(modifiers: IModifier[] | null | undefined, platform: PLATFORMS_ENUM): IModifier[];
|
|
46
|
+
/**
|
|
47
|
+
* True when the converted item has at least one selectable (platform-available)
|
|
48
|
+
* option anywhere. Used for half-half: a half-half is invalid/not selectable
|
|
49
|
+
* when none of its portion items are available for the platform.
|
|
50
|
+
*/
|
|
51
|
+
export declare function hasPlatformAvailableOptions(item: IItem, platform: PLATFORMS_ENUM): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* True when EVERY modifier group of the converted item has at least one
|
|
54
|
+
* platform-available option. Used for specials: a special is invalid/not
|
|
55
|
+
* selectable when any of its modifier groups ends up with zero items.
|
|
56
|
+
*/
|
|
57
|
+
export declare function hasAllModifierOptionsAvailable(item: IItem, platform: PLATFORMS_ENUM): boolean;
|
|
58
|
+
export {};
|
|
@@ -3,11 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getPriceEnum = getPriceEnum;
|
|
4
4
|
exports.areAllSchedulesExpired = areAllSchedulesExpired;
|
|
5
5
|
exports.findApplicableSchedule = findApplicableSchedule;
|
|
6
|
+
exports.getExcludedPlatformsFromIncludedPlatforms = getExcludedPlatformsFromIncludedPlatforms;
|
|
7
|
+
exports.isSetupApplicable = isSetupApplicable;
|
|
6
8
|
exports.getPlatformModifierOptions = getPlatformModifierOptions;
|
|
7
9
|
exports.getPlatformModifiers = getPlatformModifiers;
|
|
8
10
|
exports.convertItemToWorkableItem = convertItemToWorkableItem;
|
|
9
11
|
exports.convertOptionToWorkableOption = convertOptionToWorkableOption;
|
|
10
12
|
exports.convertCatalogToWorkableCatalog = convertCatalogToWorkableCatalog;
|
|
13
|
+
exports.getPlatformAvailableModifiers = getPlatformAvailableModifiers;
|
|
14
|
+
exports.hasPlatformAvailableOptions = hasPlatformAvailableOptions;
|
|
15
|
+
exports.hasAllModifierOptionsAvailable = hasAllModifierOptionsAvailable;
|
|
11
16
|
const constants_1 = require("../../constants");
|
|
12
17
|
/* ==========================================================><==================================================== */
|
|
13
18
|
function getPriceEnum(price, platform) {
|
|
@@ -99,6 +104,24 @@ function findApplicableSchedule(special_hours, platform) {
|
|
|
99
104
|
availableSchedulesForDayAndTime.some((schedule) => !schedule.disabled_outside_date_range));
|
|
100
105
|
}
|
|
101
106
|
// ==========================================================><====================================================
|
|
107
|
+
/**
|
|
108
|
+
* Pure mapping: converts a list of platforms an entity is INCLUDED in into the
|
|
109
|
+
* list of platforms it is EXCLUDED from (complement over all platforms).
|
|
110
|
+
* Used by convert*ToItem to surface a source item's platform membership on
|
|
111
|
+
* the produced options, so the platform filter layer can apply it without
|
|
112
|
+
* the converter itself knowing the target platform.
|
|
113
|
+
*/
|
|
114
|
+
function getExcludedPlatformsFromIncludedPlatforms(includedPlatforms) {
|
|
115
|
+
return Object.values(constants_1.PLATFORMS_ENUM).filter((platform) => !includedPlatforms.includes(platform));
|
|
116
|
+
}
|
|
117
|
+
function isSetupApplicable(setup, { tenant_id, platform }) {
|
|
118
|
+
if (!setup.active || !setup.tenants.includes(tenant_id) || !setup.included_platforms.includes(platform)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const applicableSchedule = findApplicableSchedule(setup.item_special_hours, platform);
|
|
122
|
+
return applicableSchedule !== false;
|
|
123
|
+
}
|
|
124
|
+
// ==========================================================><====================================================
|
|
102
125
|
function getPlatformModifierOptions(options, platform, excludeIds = []) {
|
|
103
126
|
const platformOptions = [];
|
|
104
127
|
const optionsLength = options.length;
|
|
@@ -248,3 +271,41 @@ function convertCatalogToWorkableCatalog(catalogs, platform, tenantId) {
|
|
|
248
271
|
return catalogItems;
|
|
249
272
|
}
|
|
250
273
|
// ==========================================================><====================================================
|
|
274
|
+
/**
|
|
275
|
+
* Filters a converted item's modifier groups down to the ones that have at
|
|
276
|
+
* least one platform-available option (reuses getPlatformModifierOptions:
|
|
277
|
+
* active + excluded_platforms + option schedule).
|
|
278
|
+
*/
|
|
279
|
+
function getPlatformAvailableModifiers(modifiers, platform) {
|
|
280
|
+
if (!modifiers || modifiers.length === 0)
|
|
281
|
+
return [];
|
|
282
|
+
const availableModifiers = [];
|
|
283
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
284
|
+
const modifier = modifiers[i];
|
|
285
|
+
const options = getPlatformModifierOptions(modifier.options, platform);
|
|
286
|
+
if (options.length === 0)
|
|
287
|
+
continue;
|
|
288
|
+
availableModifiers.push({ ...modifier, options });
|
|
289
|
+
}
|
|
290
|
+
return availableModifiers;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* True when the converted item has at least one selectable (platform-available)
|
|
294
|
+
* option anywhere. Used for half-half: a half-half is invalid/not selectable
|
|
295
|
+
* when none of its portion items are available for the platform.
|
|
296
|
+
*/
|
|
297
|
+
function hasPlatformAvailableOptions(item, platform) {
|
|
298
|
+
return getPlatformAvailableModifiers(item.modifiers, platform).length > 0;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* True when EVERY modifier group of the converted item has at least one
|
|
302
|
+
* platform-available option. Used for specials: a special is invalid/not
|
|
303
|
+
* selectable when any of its modifier groups ends up with zero items.
|
|
304
|
+
*/
|
|
305
|
+
function hasAllModifierOptionsAvailable(item, platform) {
|
|
306
|
+
const modifiers = item.modifiers;
|
|
307
|
+
if (!modifiers || modifiers.length === 0)
|
|
308
|
+
return false;
|
|
309
|
+
return getPlatformAvailableModifiers(modifiers, platform).length === modifiers.length;
|
|
310
|
+
}
|
|
311
|
+
// ==========================================================><====================================================
|
|
@@ -74,14 +74,25 @@ export declare function deStructureSpecialOrderItem(orderItem: IOrderItem, speci
|
|
|
74
74
|
* Each `IModifierSpecial` becomes an `IModifier` on the item, and each
|
|
75
75
|
* item within a modifier special becomes an `IModifierOption`.
|
|
76
76
|
*
|
|
77
|
+
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
78
|
+
* included_platforms) and no special-hours / platform-based price
|
|
79
|
+
* resolution happens here. Setup fields are copied through as-is:
|
|
80
|
+
* - `item_special_hours` is preserved on the output item,
|
|
81
|
+
* - each option's `excluded_platforms` is derived (complement) from its
|
|
82
|
+
* source item's `included_platforms`, so platform availability can be
|
|
83
|
+
* applied by the filter layer downstream.
|
|
84
|
+
*
|
|
85
|
+
* Availability-aware consumers compose this with `isSetupApplicable(...)`
|
|
86
|
+
* (and `convertItemToWorkableItem(...)` / `getPlatformModifiers(...)` for
|
|
87
|
+
* schedule/pricing).
|
|
88
|
+
*
|
|
77
89
|
* Pricing model (mirrors convertSpecialsToWorkableSpecials):
|
|
78
90
|
* - Special-level price overrides individual item prices (options get null price).
|
|
79
91
|
* - Upsell prices are merged on top.
|
|
80
92
|
* - num_free_items → num_free_options (drawer handles free vs paid).
|
|
81
93
|
* - Item modifiers are pre-filtered by excluded_refs / exclusive_refs.
|
|
82
94
|
*
|
|
83
|
-
* Returns null
|
|
84
|
-
* or has no applicable schedule.
|
|
95
|
+
* Returns null only when no option can be resolved from the items map.
|
|
85
96
|
*/
|
|
86
|
-
export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem
|
|
97
|
+
export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>): IItem | null;
|
|
87
98
|
export {};
|
|
@@ -142,6 +142,7 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
142
142
|
is_discount_percentage = applicableSchedule.is_discount_percentage;
|
|
143
143
|
}
|
|
144
144
|
const modifierSpecials = [];
|
|
145
|
+
let hasEmptyGroup = false;
|
|
145
146
|
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
146
147
|
const modifierSpecial = special.modifier_specials[j];
|
|
147
148
|
const omitItemLevelSchedule = modifierSpecial.omit_items_schedule;
|
|
@@ -168,8 +169,12 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
168
169
|
workableItem.modifiers = applyModifierSpecialRefRules(workableItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
169
170
|
items.push(workableItem);
|
|
170
171
|
}
|
|
171
|
-
|
|
172
|
+
// A modifier group with zero items makes the special invalid (cannot be
|
|
173
|
+
// completed) — the whole special is not selectable.
|
|
174
|
+
if (items.length === 0) {
|
|
175
|
+
hasEmptyGroup = true;
|
|
172
176
|
continue;
|
|
177
|
+
}
|
|
173
178
|
modifierSpecials.push({
|
|
174
179
|
_id: modifierSpecial._id,
|
|
175
180
|
name: modifierSpecial.name,
|
|
@@ -180,6 +185,9 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
|
|
|
180
185
|
items,
|
|
181
186
|
});
|
|
182
187
|
}
|
|
188
|
+
// Not selectable if any modifier group is empty (or there are no groups).
|
|
189
|
+
if (hasEmptyGroup || modifierSpecials.length === 0)
|
|
190
|
+
continue;
|
|
183
191
|
const specialMenu = {
|
|
184
192
|
_id: special._id,
|
|
185
193
|
name: special.name,
|
|
@@ -372,35 +380,31 @@ function deStructureSpecialOrderItem(orderItem, specialItem) {
|
|
|
372
380
|
* Each `IModifierSpecial` becomes an `IModifier` on the item, and each
|
|
373
381
|
* item within a modifier special becomes an `IModifierOption`.
|
|
374
382
|
*
|
|
383
|
+
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
384
|
+
* included_platforms) and no special-hours / platform-based price
|
|
385
|
+
* resolution happens here. Setup fields are copied through as-is:
|
|
386
|
+
* - `item_special_hours` is preserved on the output item,
|
|
387
|
+
* - each option's `excluded_platforms` is derived (complement) from its
|
|
388
|
+
* source item's `included_platforms`, so platform availability can be
|
|
389
|
+
* applied by the filter layer downstream.
|
|
390
|
+
*
|
|
391
|
+
* Availability-aware consumers compose this with `isSetupApplicable(...)`
|
|
392
|
+
* (and `convertItemToWorkableItem(...)` / `getPlatformModifiers(...)` for
|
|
393
|
+
* schedule/pricing).
|
|
394
|
+
*
|
|
375
395
|
* Pricing model (mirrors convertSpecialsToWorkableSpecials):
|
|
376
396
|
* - Special-level price overrides individual item prices (options get null price).
|
|
377
397
|
* - Upsell prices are merged on top.
|
|
378
398
|
* - num_free_items → num_free_options (drawer handles free vs paid).
|
|
379
399
|
* - Item modifiers are pre-filtered by excluded_refs / exclusive_refs.
|
|
380
400
|
*
|
|
381
|
-
* Returns null
|
|
382
|
-
* or has no applicable schedule.
|
|
401
|
+
* Returns null only when no option can be resolved from the items map.
|
|
383
402
|
*/
|
|
384
|
-
function convertSpecialToItem(special, itemsMap
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
// ── Schedule resolution ────────────────────────────────────────
|
|
390
|
-
const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(special.item_special_hours, platform);
|
|
391
|
-
if (applicableSchedule === false)
|
|
392
|
-
return null;
|
|
393
|
-
let price = special.price;
|
|
394
|
-
if (applicableSchedule !== true && applicableSchedule.price) {
|
|
395
|
-
price = applicableSchedule.price;
|
|
396
|
-
}
|
|
397
|
-
let discount_amount = special.discount_amount;
|
|
398
|
-
let is_discount_percentage = special.is_discount_percentage;
|
|
399
|
-
if (applicableSchedule !== true && applicableSchedule.discount_amount) {
|
|
400
|
-
discount_amount = applicableSchedule.discount_amount;
|
|
401
|
-
// the schedule also carries the percentage flag (same as IItem)
|
|
402
|
-
is_discount_percentage = applicableSchedule.is_discount_percentage;
|
|
403
|
-
}
|
|
403
|
+
function convertSpecialToItem(special, itemsMap) {
|
|
404
|
+
// Fields are carried through as-is (no schedule resolution here).
|
|
405
|
+
const price = special.price;
|
|
406
|
+
const discount_amount = special.discount_amount;
|
|
407
|
+
const is_discount_percentage = special.is_discount_percentage;
|
|
404
408
|
// ── Build modifiers from modifier_specials ─────────────────────
|
|
405
409
|
const modifiers = [];
|
|
406
410
|
const allKeywords = [];
|
|
@@ -408,7 +412,6 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
408
412
|
const allDietaryPreferences = [];
|
|
409
413
|
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
410
414
|
const modifierSpecial = special.modifier_specials[j];
|
|
411
|
-
const omitItemLevelSchedule = modifierSpecial.omit_items_schedule;
|
|
412
415
|
const modifierSpecialItems = [...modifierSpecial.items];
|
|
413
416
|
modifierSpecialItems.sort((a, b) => a.sort_id - b.sort_id);
|
|
414
417
|
const options = [];
|
|
@@ -417,24 +420,21 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
417
420
|
const catalogItem = itemsMap[specialItem.item_id];
|
|
418
421
|
if (!catalogItem)
|
|
419
422
|
continue;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
allKeywords.push(...(workableItem.keywords ?? []));
|
|
424
|
-
allCaveats.push(...(workableItem.caveats ?? []));
|
|
425
|
-
allDietaryPreferences.push(...(workableItem.dietary_preferences ?? []));
|
|
423
|
+
allKeywords.push(...(catalogItem.keywords ?? []));
|
|
424
|
+
allCaveats.push(...(catalogItem.caveats ?? []));
|
|
425
|
+
allDietaryPreferences.push(...(catalogItem.dietary_preferences ?? []));
|
|
426
426
|
// Determine option price:
|
|
427
427
|
// special has its own price → options carry null price
|
|
428
428
|
// (num_free_options in the drawer handles free-vs-paid)
|
|
429
429
|
// no special price → use item's own price
|
|
430
430
|
// upsell_price is always merged on top
|
|
431
|
-
let optionPrice = special.price != null ? null :
|
|
431
|
+
let optionPrice = special.price != null ? null : catalogItem.price;
|
|
432
432
|
if (specialItem.upsell_price != null) {
|
|
433
433
|
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, specialItem.upsell_price);
|
|
434
434
|
}
|
|
435
|
-
//
|
|
436
|
-
//
|
|
437
|
-
const itemModifiers = applyModifierSpecialRefRules(
|
|
435
|
+
// Apply the modifier-special group's ref rules to the source item's own
|
|
436
|
+
// modifiers (excluded_refs removes, exclusive_refs zeroes price).
|
|
437
|
+
const itemModifiers = applyModifierSpecialRefRules(catalogItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
438
438
|
options.push({
|
|
439
439
|
// `_id` is the real item `_id` (like a catalog option id —
|
|
440
440
|
// deterministic, identical across lines of the same selection);
|
|
@@ -445,13 +445,20 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
445
445
|
active: catalogItem.active,
|
|
446
446
|
sold_out: catalogItem.sold_out,
|
|
447
447
|
sort_id: specialItem.sort_id,
|
|
448
|
-
|
|
448
|
+
// Derived from the source item's included platforms (pure mapping),
|
|
449
|
+
// so platform availability can be applied by the filter layer downstream.
|
|
450
|
+
excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
|
|
451
|
+
// Carry the source item's special hours so the filter layer can apply
|
|
452
|
+
// schedule availability (pure mapping, no resolution here).
|
|
453
|
+
item_modifier_option_special_hours: catalogItem.item_special_hours,
|
|
449
454
|
price: optionPrice,
|
|
450
455
|
modifiers: itemModifiers,
|
|
451
456
|
});
|
|
452
457
|
}
|
|
458
|
+
// A modifier group with zero resolvable items makes the special invalid
|
|
459
|
+
// (cannot be completed) — the whole conversion fails.
|
|
453
460
|
if (options.length === 0)
|
|
454
|
-
|
|
461
|
+
return null;
|
|
455
462
|
modifiers.push({
|
|
456
463
|
// `_id` is the real modifier-special `_id` (like a catalog modifier id);
|
|
457
464
|
// `ref` points to the same source modifier-special.
|
|
@@ -490,7 +497,7 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
490
497
|
keywords: Array.from(new Set(allKeywords)),
|
|
491
498
|
image_url: special.image_url,
|
|
492
499
|
ingredients: null,
|
|
493
|
-
item_special_hours:
|
|
500
|
+
item_special_hours: special.item_special_hours, // preserved for the availability layer
|
|
494
501
|
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
495
502
|
is_featured: false,
|
|
496
503
|
featured_sort_id: 0,
|