@managesome/eposmatic-toolkit 0.2.746 → 0.2.748

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.
@@ -183,14 +183,26 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
183
183
  // `convertHalfHalfToOrderEngineItem`) against the definition prices as
184
184
  // the original references.
185
185
  const entries = [];
186
+ // Items that exist for this platform but are outside their own schedule
187
+ // right now. Item schedules filter the SELECTABLE segment options — they
188
+ // must not invalidate the setup at menu level; the setup's own schedule is
189
+ // that gate.
190
+ let hasScheduledOutItem = false;
186
191
  for (let j = 0; j < halfhalfItems.length; j++) {
187
192
  const item = halfhalfItems[j];
188
193
  const catalogItem = itemsMap[item.item_id];
189
194
  if (!catalogItem)
190
195
  continue;
191
196
  const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id);
192
- if (!workableItem)
197
+ if (!workableItem) {
198
+ // The item failed ONLY its own schedule: probe without the schedule
199
+ // check to tell "scheduled out right now" apart from "structurally
200
+ // unavailable" (inactive / platform / tenant filtered).
201
+ if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true) != null) {
202
+ hasScheduledOutItem = true;
203
+ }
193
204
  continue;
205
+ }
194
206
  if (discount_amount != null) {
195
207
  workableItem.discount_amount = null;
196
208
  }
@@ -221,7 +233,10 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
221
233
  }
222
234
  items.push(workableItem);
223
235
  }
224
- if (items.length === 0)
236
+ // A setup whose items are all outside their own schedule right now still
237
+ // belongs to the menu (the setup's own schedule is the menu-level gate);
238
+ // item schedules only filter the segment options.
239
+ if (items.length === 0 && !hasScheduledOutItem)
225
240
  continue;
226
241
  halfhalfMenu.push({
227
242
  _id: halfhalfSetup._id,
@@ -160,6 +160,11 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
160
160
  // they are rendered/selected through the classic preview separately, but
161
161
  // they keep the group non-empty so the special stays selectable.
162
162
  let hasHalfHalfRef = false;
163
+ // Items that exist for this platform but are outside their own schedule
164
+ // right now (only possible with `omit_items_schedule === false`). Item
165
+ // schedules filter the SELECTABLE options — they must not invalidate the
166
+ // special at menu level; the special's own schedule is that gate.
167
+ let hasScheduledOutItem = false;
163
168
  for (let k = 0; k < modifierSpecialItems.length; k++) {
164
169
  const item = modifierSpecial.items[k];
165
170
  const catalogItem = itemsMap[item.item_id];
@@ -170,8 +175,15 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
170
175
  continue;
171
176
  }
172
177
  const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true);
173
- if (!workableItem)
178
+ if (!workableItem) {
179
+ // The item failed ONLY its own schedule: probe without the schedule
180
+ // check to tell "scheduled out right now" apart from "structurally
181
+ // unavailable" (inactive / platform / tenant filtered).
182
+ if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true) != null) {
183
+ hasScheduledOutItem = true;
184
+ }
174
185
  continue;
186
+ }
175
187
  workableItem.discount_amount = null;
176
188
  if (special.price != null) {
177
189
  workableItem.price = null;
@@ -186,8 +198,11 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
186
198
  }
187
199
  // A modifier group with zero resolvable items makes the special invalid
188
200
  // (cannot be completed) — unless it only references half-half setups
189
- // (selectable via the classic preview, kept as a selectable group).
190
- if (items.length === 0 && !hasHalfHalfRef) {
201
+ // (selectable via the classic preview, kept as a selectable group) or
202
+ // its items are merely outside their own schedule right now. Item
203
+ // schedules filter the selectable options at selection time; menu-level
204
+ // validity is governed by the special's own schedule.
205
+ if (items.length === 0 && !hasHalfHalfRef && !hasScheduledOutItem) {
191
206
  hasEmptyGroup = true;
192
207
  continue;
193
208
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const halfhalf_setup_helpers_1 = require("../helpers/utils/halfhalf-setup-helpers");
5
+ const specials_helpers_1 = require("../helpers/utils/specials-helpers");
6
+ // ============================================================================
7
+ // Menu-level schedule gating, split from selection-level:
8
+ //
9
+ // - MENU visibility of a special / half-half is governed by its OWN
10
+ // schedule only. Item schedules must never remove the special / setup
11
+ // from the menu (they used to: an item failing its own schedule made a
12
+ // modifier group "empty" -> `hasEmptyGroup` -> special dropped; all items
13
+ // scheduled out -> `items.length === 0` -> setup dropped).
14
+ // - ITEM schedules filter the SELECTABLE options (specials only when
15
+ // `omit_items_schedule === false`) — the selection screens render exactly
16
+ // the items converted here.
17
+ // ============================================================================
18
+ const TENANT_ID = 'tenant-1';
19
+ const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
20
+ /**
21
+ * Never-applicable schedule: no days at all, so `findApplicableSchedule`
22
+ * finds no schedule for the current day and returns `false`.
23
+ */
24
+ function makeScheduledOutHours() {
25
+ return [
26
+ {
27
+ days_index: [],
28
+ disabled_outside_date_range: false,
29
+ start_time: 0,
30
+ end_time: 24 * 3600000,
31
+ start_date: null,
32
+ end_date: null,
33
+ price: null,
34
+ is_discount_percentage: false,
35
+ excluded_platforms: [],
36
+ },
37
+ ];
38
+ }
39
+ /** Always-applicable schedule (all days, full day). */
40
+ function makeAlwaysApplicableHours() {
41
+ return [
42
+ {
43
+ days_index: Object.values(constants_1.DAY_INDEX_ENUM),
44
+ disabled_outside_date_range: false,
45
+ start_time: 0,
46
+ end_time: 24 * 3600000,
47
+ start_date: null,
48
+ end_date: null,
49
+ price: null,
50
+ is_discount_percentage: false,
51
+ excluded_platforms: [],
52
+ },
53
+ ];
54
+ }
55
+ function makeItem(id, overrides = {}) {
56
+ return {
57
+ _id: id,
58
+ brand_id: 'brand-1',
59
+ tenants: [TENANT_ID],
60
+ category_id: 'pizza-cat',
61
+ included_platforms: [PLATFORM],
62
+ name: `Item ${id}`,
63
+ active: true,
64
+ sold_out: [],
65
+ sort_id: 1,
66
+ image_url: `https://example.com/${id}.jpg`,
67
+ price: { BASE_PRICE: 1000 },
68
+ discount_amount: null,
69
+ is_discount_percentage: false,
70
+ tax_rate: null,
71
+ keywords: [],
72
+ caveats: [],
73
+ dietary_preferences: [],
74
+ hide_name: false,
75
+ description: '',
76
+ ingredients: null,
77
+ is_featured: false,
78
+ featured_sort_id: 0,
79
+ item_special_hours: null,
80
+ display_price: null,
81
+ show_starting_from: false,
82
+ createdAt: new Date('2024-01-01'),
83
+ updatedAt: new Date('2024-01-02'),
84
+ modifiers: null,
85
+ ...overrides,
86
+ };
87
+ }
88
+ function makeHalfHalfSetup(overrides = {}) {
89
+ return {
90
+ _id: 'halfhalf-1',
91
+ brand_id: 'brand-1',
92
+ tenants: [TENANT_ID],
93
+ category_id: 'pizza-cat',
94
+ included_platforms: [PLATFORM],
95
+ name: 'Half/Half Pizza Large',
96
+ description: 'Two halves',
97
+ active: true,
98
+ sold_out: [],
99
+ image_url: 'https://example.com/halfhalf.jpg',
100
+ upsell_price: null,
101
+ discount_amount: null,
102
+ is_discount_percentage: false,
103
+ sort_id: 1,
104
+ choose_expensive_segment_price: true,
105
+ segments: [
106
+ { _id: 'seg-1', name: 'First Pizza', sort_id: 1 },
107
+ { _id: 'seg-2', name: 'Second Pizza', sort_id: 2 },
108
+ ],
109
+ items: [
110
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
111
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
112
+ ],
113
+ exclusive_refs: [],
114
+ excluded_refs: [],
115
+ item_special_hours: null,
116
+ createdAt: new Date('2024-01-01'),
117
+ updatedAt: new Date('2024-01-02'),
118
+ ...overrides,
119
+ };
120
+ }
121
+ function makeModifierSpecial(overrides = {}) {
122
+ return {
123
+ _id: 'mod-pizza',
124
+ name: 'First Pizza',
125
+ sort_id: 1,
126
+ quantity: 1,
127
+ num_free_items: 0,
128
+ excluded_refs: [],
129
+ exclusive_refs: [],
130
+ omit_items_schedule: false,
131
+ items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
132
+ ...overrides,
133
+ };
134
+ }
135
+ function makeSpecialWithModifier(overrides = {}) {
136
+ return {
137
+ _id: 'special-1',
138
+ brand_id: 'brand-1',
139
+ tenants: [TENANT_ID],
140
+ category_id: 'combo-cat',
141
+ included_platforms: [PLATFORM],
142
+ name: 'Buy 1 Pizza Get 1 Free',
143
+ description: 'Deal',
144
+ active: true,
145
+ sold_out: [],
146
+ sort_id: 1,
147
+ image_url: 'https://example.com/special.jpg',
148
+ price: { BASE_PRICE: 1500 },
149
+ discount_amount: null,
150
+ is_discount_percentage: false,
151
+ display_price: null,
152
+ show_starting_from: false,
153
+ item_special_hours: null,
154
+ modifier_specials: [makeModifierSpecial()],
155
+ createdAt: new Date('2024-01-01'),
156
+ updatedAt: new Date('2024-01-02'),
157
+ ...overrides,
158
+ };
159
+ }
160
+ describe('specials: menu visibility follows the special schedule only', () => {
161
+ it('keeps the special when a group is empty only because its items are scheduled out', () => {
162
+ const itemsMap = {
163
+ milan: makeItem('milan', { item_special_hours: makeScheduledOutHours() }),
164
+ };
165
+ const [special] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
166
+ // The special's own schedule applies -> the special stays in the menu...
167
+ expect(special).toBeDefined();
168
+ expect(special.modifier_specials).toHaveLength(1);
169
+ // ...while the scheduled-out item is filtered from the selectable options.
170
+ expect(special.modifier_specials[0].items).toHaveLength(0);
171
+ });
172
+ it('keeps the special when only some items are scheduled out', () => {
173
+ const itemsMap = {
174
+ milan: makeItem('milan', { item_special_hours: makeScheduledOutHours() }),
175
+ torent: makeItem('torent'),
176
+ };
177
+ const special = makeSpecialWithModifier({
178
+ modifier_specials: [
179
+ makeModifierSpecial({
180
+ items: [
181
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
182
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
183
+ ],
184
+ }),
185
+ ],
186
+ });
187
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
188
+ expect(workable).toBeDefined();
189
+ expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
190
+ });
191
+ it('keeps scheduled-out items when omit_items_schedule is true', () => {
192
+ const itemsMap = {
193
+ milan: makeItem('milan', { item_special_hours: makeScheduledOutHours() }),
194
+ };
195
+ const special = makeSpecialWithModifier({
196
+ modifier_specials: [makeModifierSpecial({ omit_items_schedule: true })],
197
+ });
198
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
199
+ expect(workable).toBeDefined();
200
+ expect(workable.modifier_specials[0].items).toHaveLength(1);
201
+ });
202
+ it('still hides the special when the group has no resolvable items at all', () => {
203
+ const [special] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], {}, PLATFORM, TENANT_ID);
204
+ expect(special).toBeUndefined();
205
+ });
206
+ it("still hides the special when the special's own schedule is not applicable", () => {
207
+ const itemsMap = { milan: makeItem('milan') };
208
+ const special = makeSpecialWithModifier({ item_special_hours: makeScheduledOutHours() });
209
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
210
+ expect(workable).toBeUndefined();
211
+ });
212
+ it('keeps items in schedule when the special schedule applies', () => {
213
+ const itemsMap = {
214
+ milan: makeItem('milan', { item_special_hours: makeAlwaysApplicableHours() }),
215
+ };
216
+ const special = makeSpecialWithModifier({ item_special_hours: makeAlwaysApplicableHours() });
217
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
218
+ expect(workable).toBeDefined();
219
+ expect(workable.modifier_specials[0].items).toHaveLength(1);
220
+ });
221
+ });
222
+ describe('half-half: menu visibility follows the setup schedule only', () => {
223
+ it('keeps the setup when all its items are scheduled out', () => {
224
+ const itemsMap = {
225
+ milan: makeItem('milan', { item_special_hours: makeScheduledOutHours() }),
226
+ torent: makeItem('torent', { item_special_hours: makeScheduledOutHours() }),
227
+ };
228
+ const [setup] = (0, halfhalf_setup_helpers_1.convertHalfHalfSetupToWorkableHalfHalfSetup)([makeHalfHalfSetup()], itemsMap, PLATFORM, TENANT_ID);
229
+ // The setup's own schedule applies -> the setup stays in the menu...
230
+ expect(setup).toBeDefined();
231
+ // ...while the scheduled-out items are filtered from the selectable list.
232
+ expect(setup.items).toHaveLength(0);
233
+ });
234
+ it('keeps in-schedule items selectable while siblings are scheduled out', () => {
235
+ const itemsMap = {
236
+ milan: makeItem('milan', { item_special_hours: makeScheduledOutHours() }),
237
+ torent: makeItem('torent'),
238
+ };
239
+ const [setup] = (0, halfhalf_setup_helpers_1.convertHalfHalfSetupToWorkableHalfHalfSetup)([makeHalfHalfSetup()], itemsMap, PLATFORM, TENANT_ID);
240
+ expect(setup).toBeDefined();
241
+ expect(setup.items.map((item) => item._id)).toEqual(['torent']);
242
+ });
243
+ it('still hides the setup when no referenced item is resolvable', () => {
244
+ const [setup] = (0, halfhalf_setup_helpers_1.convertHalfHalfSetupToWorkableHalfHalfSetup)([makeHalfHalfSetup()], {}, PLATFORM, TENANT_ID);
245
+ expect(setup).toBeUndefined();
246
+ });
247
+ it("still hides the setup when the setup's own schedule is not applicable", () => {
248
+ const itemsMap = { milan: makeItem('milan'), torent: makeItem('torent') };
249
+ const setup = makeHalfHalfSetup({ item_special_hours: makeScheduledOutHours() });
250
+ const [workable] = (0, halfhalf_setup_helpers_1.convertHalfHalfSetupToWorkableHalfHalfSetup)([setup], itemsMap, PLATFORM, TENANT_ID);
251
+ expect(workable).toBeUndefined();
252
+ });
253
+ it('still hides the setup when its referenced items are structurally unavailable', () => {
254
+ const itemsMap = {
255
+ milan: makeItem('milan', { active: false }),
256
+ torent: makeItem('torent', { included_platforms: [constants_1.PLATFORMS_ENUM.POS_TAKE_AWAY] }),
257
+ };
258
+ const [setup] = (0, halfhalf_setup_helpers_1.convertHalfHalfSetupToWorkableHalfHalfSetup)([makeHalfHalfSetup()], itemsMap, PLATFORM, TENANT_ID);
259
+ expect(setup).toBeUndefined();
260
+ });
261
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.746",
3
+ "version": "0.2.748",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",