@managesome/eposmatic-toolkit 0.2.655 → 0.2.657
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.
|
@@ -67,8 +67,6 @@ export declare const SUBSCRIPTION_STATUS_COLOR: {
|
|
|
67
67
|
EXPIRED: string;
|
|
68
68
|
DUE_SOON: string;
|
|
69
69
|
};
|
|
70
|
-
export declare const SPECIALS_CATEGORY_ID = "680437e050ad8ba788150b32";
|
|
71
|
-
export declare const SPECIALS_CATEGORY_NAME = "Specials";
|
|
72
70
|
export declare const WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = "wallet_cashback_redemption";
|
|
73
71
|
export declare const WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = "Wallet Cashback";
|
|
74
72
|
export declare const WALLET_CASHBACK_LOYALTY_REFERENCE = "WALLET_CASHBACK";
|
package/lib/constants/COMMON.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STRAIGHT_LINE_ROAD_MULTIPLIER = exports.WALLET_CASHBACK_LOYALTY_REFERENCE = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = exports.
|
|
3
|
+
exports.STRAIGHT_LINE_ROAD_MULTIPLIER = exports.WALLET_CASHBACK_LOYALTY_REFERENCE = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = exports.SUBSCRIPTION_STATUS_COLOR = exports.AUTO_DELIVERY_CHARGES_PLATFORMS = exports.TAX_INVOICE_PROVIDER_CHARGES_MAP = exports.PAYMENT_CHARGES_MAP = exports.NOTIFICATION_CHARGES_MAP = exports.WHATSAPP_CHARGES_MAP = exports.SMS_CHARGES_MAP = exports.SMS_UNIT_LENGTH = exports.PROVIDER_OPERATIONAL_COUNTRIES = exports.ALL_PLAFORMS_OBJ = exports.LOW_VALUE_CURRENCY_COUNTRIES = void 0;
|
|
4
4
|
const ENUMS_1 = require("./ENUMS");
|
|
5
5
|
/**
|
|
6
6
|
* Countries with low-value currencies that should have:
|
|
@@ -366,8 +366,6 @@ exports.SUBSCRIPTION_STATUS_COLOR = {
|
|
|
366
366
|
[ENUMS_1.SUBSCRIPTION_STATUS_ENUM.EXPIRED]: '#ff0000',
|
|
367
367
|
[ENUMS_1.SUBSCRIPTION_STATUS_ENUM.DUE_SOON]: '#ffb300',
|
|
368
368
|
};
|
|
369
|
-
exports.SPECIALS_CATEGORY_ID = '680437e050ad8ba788150b32';
|
|
370
|
-
exports.SPECIALS_CATEGORY_NAME = 'Specials';
|
|
371
369
|
exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = 'wallet_cashback_redemption';
|
|
372
370
|
exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = 'Wallet Cashback';
|
|
373
371
|
exports.WALLET_CASHBACK_LOYALTY_REFERENCE = 'WALLET_CASHBACK';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PLATFORMS_ENUM } from '../../constants';
|
|
2
|
-
import { IHalfHalfSetup, IItem } from '../../schemas';
|
|
2
|
+
import { IHalfHalfSetup, IItem, IOrderItem } from '../../schemas';
|
|
3
3
|
import { ISimplifiedCatalogItem } from '../types';
|
|
4
4
|
export declare function getHalfHalfPostedData(data: IHalfHalfSetup[], payload: IHalfHalfSetup): IHalfHalfSetup[];
|
|
5
5
|
export declare function renderBulkHalfHalfUpdate(data: IHalfHalfSetup[], payload: Partial<IHalfHalfSetup>[]): IHalfHalfSetup[];
|
|
@@ -20,3 +20,42 @@ export type IWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem> = {
|
|
|
20
20
|
items: T[];
|
|
21
21
|
};
|
|
22
22
|
export declare function convertHalfHalfSetupToWorkableHalfHalfSetup<T extends IItem | ISimplifiedCatalogItem>(halfhalfSetups: IHalfHalfSetup[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableHalfHalfSetup<T>[];
|
|
23
|
+
/**
|
|
24
|
+
* Converts an IHalfHalfSetup into an IItem so it can flow through the standard
|
|
25
|
+
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
26
|
+
*
|
|
27
|
+
* Each segment becomes a single-select IModifier (one option per available
|
|
28
|
+
* item, priced as `(item price + upsells) / segments`), so duplicates across
|
|
29
|
+
* segments are allowed and each segment must be filled exactly once.
|
|
30
|
+
*
|
|
31
|
+
* Returns null if the halfhalf setup is inactive, doesn't match platform/tenant,
|
|
32
|
+
* or has no applicable schedule / no resolvable items.
|
|
33
|
+
*/
|
|
34
|
+
export declare function convertHalfHalfToItem(halfhalfSetup: IHalfHalfSetup, itemsMap: Record<string, IItem>, platform: PLATFORMS_ENUM, tenant_id: string): IItem | null;
|
|
35
|
+
interface IConvertHalfHalfToOrderItem {
|
|
36
|
+
halfHalfItem: IWorkableHalfHalfSetup<IItem>;
|
|
37
|
+
selectedHalfHalfItems: (IOrderItem | null)[];
|
|
38
|
+
quantity: number;
|
|
39
|
+
platform: PLATFORMS_ENUM;
|
|
40
|
+
existingOrderItem?: IOrderItem;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
44
|
+
* single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
|
|
45
|
+
* (stable id `${halfHalfItem._id}_segment_${s}`) with the chosen item as its
|
|
46
|
+
* single option, so it can be de-structured back on edit.
|
|
47
|
+
*/
|
|
48
|
+
export declare function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }: IConvertHalfHalfToOrderItem): IOrderItem;
|
|
49
|
+
/**
|
|
50
|
+
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
51
|
+
* selection format used by the HalfHalfScreen selection flow.
|
|
52
|
+
*
|
|
53
|
+
* Matches each order modifier to its segment via the stable
|
|
54
|
+
* `${halfHalfItem._id}_segment_${s}` id/ref. Returns null if the order item
|
|
55
|
+
* doesn't belong to the provided halfhalf setup.
|
|
56
|
+
*/
|
|
57
|
+
export declare function deStructureHalfHalfOrderItem(orderItem: IOrderItem, halfHalfItem: IWorkableHalfHalfSetup<IItem>): {
|
|
58
|
+
selectedHalfHalfItems: (IOrderItem | null)[];
|
|
59
|
+
quantity: number;
|
|
60
|
+
} | null;
|
|
61
|
+
export {};
|
|
@@ -6,6 +6,10 @@ exports.getHalfHalfUpdatedData = getHalfHalfUpdatedData;
|
|
|
6
6
|
exports.getHalfHalfDeletedData = getHalfHalfDeletedData;
|
|
7
7
|
exports.getHalfhalfSetupWithPrice = getHalfhalfSetupWithPrice;
|
|
8
8
|
exports.convertHalfHalfSetupToWorkableHalfHalfSetup = convertHalfHalfSetupToWorkableHalfHalfSetup;
|
|
9
|
+
exports.convertHalfHalfToItem = convertHalfHalfToItem;
|
|
10
|
+
exports.convertHalfHalfToOrderItem = convertHalfHalfToOrderItem;
|
|
11
|
+
exports.deStructureHalfHalfOrderItem = deStructureHalfHalfOrderItem;
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
9
13
|
const store_1 = require("../store");
|
|
10
14
|
const platform_catalog_1 = require("./platform-catalog");
|
|
11
15
|
const platform_num_1 = require("./platform-num");
|
|
@@ -131,3 +135,227 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
131
135
|
}
|
|
132
136
|
return halfhalfMenu;
|
|
133
137
|
}
|
|
138
|
+
// ====================================================================================================
|
|
139
|
+
/**
|
|
140
|
+
* Converts an IHalfHalfSetup into an IItem so it can flow through the standard
|
|
141
|
+
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
142
|
+
*
|
|
143
|
+
* Each segment becomes a single-select IModifier (one option per available
|
|
144
|
+
* item, priced as `(item price + upsells) / segments`), so duplicates across
|
|
145
|
+
* segments are allowed and each segment must be filled exactly once.
|
|
146
|
+
*
|
|
147
|
+
* Returns null if the halfhalf setup is inactive, doesn't match platform/tenant,
|
|
148
|
+
* or has no applicable schedule / no resolvable items.
|
|
149
|
+
*/
|
|
150
|
+
function convertHalfHalfToItem(halfhalfSetup, itemsMap, platform, tenant_id) {
|
|
151
|
+
// ── Guard: active, tenant, platform ────────────────────────────
|
|
152
|
+
if (!halfhalfSetup.active ||
|
|
153
|
+
!halfhalfSetup.tenants.includes(tenant_id) ||
|
|
154
|
+
!halfhalfSetup.included_platforms.includes(platform)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
// ── Schedule resolution ────────────────────────────────────────
|
|
158
|
+
const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(halfhalfSetup.item_special_hours, platform);
|
|
159
|
+
if (applicableSchedule === false)
|
|
160
|
+
return null;
|
|
161
|
+
let upsell_price = halfhalfSetup.upsell_price;
|
|
162
|
+
let discount_amount = halfhalfSetup.discount_amount;
|
|
163
|
+
if (applicableSchedule !== true) {
|
|
164
|
+
if (applicableSchedule.price != null)
|
|
165
|
+
upsell_price = applicableSchedule.price;
|
|
166
|
+
if (applicableSchedule.discount_amount != null) {
|
|
167
|
+
discount_amount = applicableSchedule.discount_amount;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// ── Build shared option list (segment-neutral ids) ─────────────
|
|
171
|
+
const halfHalfItems = [...halfhalfSetup.items].sort((a, b) => a.sort_id - b.sort_id);
|
|
172
|
+
const baseOptions = [];
|
|
173
|
+
for (let i = 0; i < halfHalfItems.length; i++) {
|
|
174
|
+
const halfHalfItem = halfHalfItems[i];
|
|
175
|
+
const catalogItem = itemsMap[halfHalfItem.item_id];
|
|
176
|
+
if (!catalogItem)
|
|
177
|
+
continue;
|
|
178
|
+
const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id);
|
|
179
|
+
if (!workableItem)
|
|
180
|
+
continue;
|
|
181
|
+
let optionPrice = workableItem.price;
|
|
182
|
+
if (upsell_price != null)
|
|
183
|
+
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, upsell_price);
|
|
184
|
+
if (halfHalfItem.upsell_price != null) {
|
|
185
|
+
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, halfHalfItem.upsell_price);
|
|
186
|
+
}
|
|
187
|
+
optionPrice = (0, platform_num_1.convertPriceObjToSegmentPrice)(optionPrice, halfhalfSetup.segments);
|
|
188
|
+
baseOptions.push({
|
|
189
|
+
_id: `${halfhalfSetup._id}_${catalogItem._id}`,
|
|
190
|
+
ref: catalogItem._id,
|
|
191
|
+
name: catalogItem.name,
|
|
192
|
+
active: catalogItem.active,
|
|
193
|
+
sold_out: catalogItem.sold_out,
|
|
194
|
+
sort_id: halfHalfItem.sort_id,
|
|
195
|
+
excluded_platforms: [],
|
|
196
|
+
price: optionPrice,
|
|
197
|
+
modifiers: workableItem.modifiers,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (baseOptions.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
// ── Build one single-select modifier per segment ───────────────
|
|
203
|
+
const modifiers = [];
|
|
204
|
+
for (let s = 0; s < halfhalfSetup.segments; s++) {
|
|
205
|
+
modifiers.push({
|
|
206
|
+
_id: `${halfhalfSetup._id}_segment_${s}`,
|
|
207
|
+
ref: `${halfhalfSetup._id}_segment_${s}`,
|
|
208
|
+
name: `Segment ${s + 1}`,
|
|
209
|
+
description: '',
|
|
210
|
+
active: true,
|
|
211
|
+
sold_out: [],
|
|
212
|
+
sort_id: s,
|
|
213
|
+
min_num_options: 1,
|
|
214
|
+
max_num_options: 1,
|
|
215
|
+
num_free_options: null,
|
|
216
|
+
options: baseOptions.map((option) => ({
|
|
217
|
+
...option,
|
|
218
|
+
_id: `${halfhalfSetup._id}_segment_${s}_${option.ref}`,
|
|
219
|
+
})),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// ── Assemble the IItem ─────────────────────────────────────────
|
|
223
|
+
const item = {
|
|
224
|
+
_id: halfhalfSetup._id,
|
|
225
|
+
brand_id: halfhalfSetup.brand_id,
|
|
226
|
+
tenants: halfhalfSetup.tenants,
|
|
227
|
+
category_id: halfhalfSetup.category_id,
|
|
228
|
+
included_platforms: halfhalfSetup.included_platforms,
|
|
229
|
+
name: halfhalfSetup.name,
|
|
230
|
+
hide_name: false,
|
|
231
|
+
description: halfhalfSetup.description,
|
|
232
|
+
active: halfhalfSetup.active,
|
|
233
|
+
sold_out: halfhalfSetup.sold_out,
|
|
234
|
+
sort_id: 0,
|
|
235
|
+
price: null,
|
|
236
|
+
discount_amount,
|
|
237
|
+
is_discount_percentage: halfhalfSetup.is_discount_percentage,
|
|
238
|
+
caveats: [],
|
|
239
|
+
dietary_preferences: [],
|
|
240
|
+
tax_rate: null,
|
|
241
|
+
keywords: [],
|
|
242
|
+
image_url: halfhalfSetup.image_url,
|
|
243
|
+
ingredients: null,
|
|
244
|
+
item_special_hours: null, // already resolved into upsell_price / discount_amount
|
|
245
|
+
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
246
|
+
is_featured: false,
|
|
247
|
+
featured_sort_id: 0,
|
|
248
|
+
display_price: null,
|
|
249
|
+
show_starting_from: false,
|
|
250
|
+
use_source_ingredients: false,
|
|
251
|
+
createdAt: halfhalfSetup.createdAt,
|
|
252
|
+
updatedAt: halfhalfSetup.updatedAt,
|
|
253
|
+
};
|
|
254
|
+
return item;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
258
|
+
* single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
|
|
259
|
+
* (stable id `${halfHalfItem._id}_segment_${s}`) with the chosen item as its
|
|
260
|
+
* single option, so it can be de-structured back on edit.
|
|
261
|
+
*/
|
|
262
|
+
function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform: _platform, existingOrderItem, }) {
|
|
263
|
+
const modifiers = [];
|
|
264
|
+
let menu_id;
|
|
265
|
+
for (let s = 0; s < selectedHalfHalfItems.length; s++) {
|
|
266
|
+
const selectedItem = selectedHalfHalfItems[s];
|
|
267
|
+
if (!selectedItem)
|
|
268
|
+
continue;
|
|
269
|
+
if (selectedItem.menu_id != null && menu_id == null) {
|
|
270
|
+
menu_id = selectedItem.menu_id;
|
|
271
|
+
}
|
|
272
|
+
modifiers.push({
|
|
273
|
+
_id: `${halfHalfItem._id}_segment_${s}`,
|
|
274
|
+
ref: `${halfHalfItem._id}_segment_${s}`,
|
|
275
|
+
name: `Segment ${s + 1}`,
|
|
276
|
+
options: [
|
|
277
|
+
{
|
|
278
|
+
_id: selectedItem._id,
|
|
279
|
+
ref: selectedItem.item_id,
|
|
280
|
+
name: selectedItem.name,
|
|
281
|
+
price: selectedItem.price,
|
|
282
|
+
quantity: selectedItem.quantity,
|
|
283
|
+
modifiers: selectedItem.modifiers,
|
|
284
|
+
is_free: false,
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const orderItem = {
|
|
290
|
+
item_discount_details: null,
|
|
291
|
+
special_instructions: '',
|
|
292
|
+
_net_amount: 0,
|
|
293
|
+
_gross_amount: 0,
|
|
294
|
+
_gst_amount: 0,
|
|
295
|
+
_discount_amount: 0,
|
|
296
|
+
...existingOrderItem,
|
|
297
|
+
_id: halfHalfItem._id,
|
|
298
|
+
item_id: halfHalfItem._id,
|
|
299
|
+
menu_id,
|
|
300
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
301
|
+
name: halfHalfItem.name,
|
|
302
|
+
price: 0,
|
|
303
|
+
subtotal: 0,
|
|
304
|
+
tax_rate: 0,
|
|
305
|
+
quantity,
|
|
306
|
+
modifiers,
|
|
307
|
+
};
|
|
308
|
+
const { itemSubtotal, item_discount_details } = (0, store_1.calculateItemTotalWithTax)(orderItem);
|
|
309
|
+
orderItem.subtotal = itemSubtotal;
|
|
310
|
+
orderItem.item_discount_details = item_discount_details;
|
|
311
|
+
return orderItem;
|
|
312
|
+
}
|
|
313
|
+
// ====================================================================================================
|
|
314
|
+
/**
|
|
315
|
+
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
316
|
+
* selection format used by the HalfHalfScreen selection flow.
|
|
317
|
+
*
|
|
318
|
+
* Matches each order modifier to its segment via the stable
|
|
319
|
+
* `${halfHalfItem._id}_segment_${s}` id/ref. Returns null if the order item
|
|
320
|
+
* doesn't belong to the provided halfhalf setup.
|
|
321
|
+
*/
|
|
322
|
+
function deStructureHalfHalfOrderItem(orderItem, halfHalfItem) {
|
|
323
|
+
if (orderItem.item_id !== halfHalfItem._id)
|
|
324
|
+
return null;
|
|
325
|
+
const selectedHalfHalfItems = new Array(halfHalfItem.segments).fill(null);
|
|
326
|
+
const orderModifiers = orderItem.modifiers ?? [];
|
|
327
|
+
for (let i = 0; i < orderModifiers.length; i++) {
|
|
328
|
+
const orderModifier = orderModifiers[i];
|
|
329
|
+
const segmentMatch = (orderModifier.ref ?? orderModifier._id ?? '').match(/_segment_(\d+)$/);
|
|
330
|
+
let segmentIndex = segmentMatch != null ? Number(segmentMatch[1]) : NaN;
|
|
331
|
+
if (Number.isNaN(segmentIndex) || segmentIndex < 0 || segmentIndex >= selectedHalfHalfItems.length) {
|
|
332
|
+
// Fallback: assign to the first empty slot
|
|
333
|
+
segmentIndex = selectedHalfHalfItems.findIndex((item) => item === null);
|
|
334
|
+
if (segmentIndex === -1)
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const option = orderModifier.options[0];
|
|
338
|
+
if (option == null)
|
|
339
|
+
continue;
|
|
340
|
+
selectedHalfHalfItems[segmentIndex] = {
|
|
341
|
+
_id: option._id,
|
|
342
|
+
item_id: option.ref,
|
|
343
|
+
menu_id: orderItem.menu_id ?? null,
|
|
344
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
345
|
+
name: option.name,
|
|
346
|
+
price: option.price,
|
|
347
|
+
subtotal: option.price,
|
|
348
|
+
tax_rate: 0,
|
|
349
|
+
quantity: option.quantity,
|
|
350
|
+
special_instructions: '',
|
|
351
|
+
item_discount_details: null,
|
|
352
|
+
modifiers: option.modifiers ?? null,
|
|
353
|
+
// These values will be auto calculated
|
|
354
|
+
_discount_amount: 0,
|
|
355
|
+
_gross_amount: 0,
|
|
356
|
+
_gst_amount: 0,
|
|
357
|
+
_net_amount: 0,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return { selectedHalfHalfItems, quantity: orderItem.quantity };
|
|
361
|
+
}
|
|
@@ -374,7 +374,7 @@ function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
|
374
374
|
_id: special._id,
|
|
375
375
|
brand_id: special.brand_id,
|
|
376
376
|
tenants: special.tenants,
|
|
377
|
-
category_id: special.category_id
|
|
377
|
+
category_id: special.category_id,
|
|
378
378
|
included_platforms: special.included_platforms,
|
|
379
379
|
name: special.name,
|
|
380
380
|
hide_name: false,
|