@managesome/eposmatic-toolkit 0.2.706 → 0.2.708
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/platform-num.d.ts +18 -0
- package/lib/helpers/utils/platform-num.js +55 -0
- package/lib/helpers/utils/simplified-halfhalf.d.ts +33 -1
- package/lib/helpers/utils/simplified-halfhalf.js +75 -0
- package/lib/helpers/utils/simplified-specials.d.ts +34 -1
- package/lib/helpers/utils/simplified-specials.js +80 -0
- package/lib/tests/simplified-halfhalf.test.js +91 -0
- package/lib/tests/simplified-specials.test.js +111 -43
- package/package.json +1 -1
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { IItemSpecialHour, IModifier } from '../../schemas';
|
|
2
2
|
import { IPrice } from '../../schemas/types/common';
|
|
3
|
+
import { IMinifiedItemSpecialHour, IMinifiedPrice } from '../types';
|
|
3
4
|
export declare function convertPriceObjToCents(price: IPrice | null | undefined): IPrice | null;
|
|
4
5
|
export declare function convertPriceObjFromCents(priceObj: IPrice | null | undefined): IPrice | null;
|
|
6
|
+
/**
|
|
7
|
+
* Scales a minified price (IMinifiedPrice: number when all platforms share
|
|
8
|
+
* one value, otherwise an IPrice object) between the cents domain and the
|
|
9
|
+
* dollar/UI domain while preserving the minified shape — a scalar stays a
|
|
10
|
+
* scalar, an object stays an object. The counterpart of
|
|
11
|
+
* `convertPriceObjToCents` / `convertPriceObjFromCents` for minified values.
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertMinifiedPriceToCents(price: IMinifiedPrice | undefined): IMinifiedPrice | undefined;
|
|
14
|
+
export declare function convertMinifiedPriceFromCents(price: IMinifiedPrice | undefined): IMinifiedPrice | undefined;
|
|
5
15
|
export declare function mergePriceObjs(priceObj1: IPrice | null, priceObj2: IPrice | null): IPrice | null;
|
|
6
16
|
export declare function convertPriceObjToSegmentPrice(priceObj: IPrice | null, segments: number): IPrice | null;
|
|
7
17
|
export declare function convertModifiersPriceToCents(modifiers: IModifier[] | null | undefined): IModifier[] | null;
|
|
8
18
|
export declare function convertSpecialHoursToCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
9
19
|
export declare function convertSpecialHoursFromCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
20
|
+
/**
|
|
21
|
+
* Same as `convertSpecialHoursToCents` / `convertSpecialHoursFromCents` but for
|
|
22
|
+
* the minified special-hours form (each schedule's `price`/`discount_amount`
|
|
23
|
+
* are IMinifiedPrice values). An empty/missing list stays `undefined` — the
|
|
24
|
+
* simplified payloads do not carry a null special-hours list.
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertMinifiedSpecialHoursToCents(specialHours: IMinifiedItemSpecialHour[] | null | undefined): IMinifiedItemSpecialHour[] | undefined;
|
|
27
|
+
export declare function convertMinifiedSpecialHoursFromCents(specialHours: IMinifiedItemSpecialHour[] | null | undefined): IMinifiedItemSpecialHour[] | undefined;
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertPriceObjToCents = convertPriceObjToCents;
|
|
4
4
|
exports.convertPriceObjFromCents = convertPriceObjFromCents;
|
|
5
|
+
exports.convertMinifiedPriceToCents = convertMinifiedPriceToCents;
|
|
6
|
+
exports.convertMinifiedPriceFromCents = convertMinifiedPriceFromCents;
|
|
5
7
|
exports.mergePriceObjs = mergePriceObjs;
|
|
6
8
|
exports.convertPriceObjToSegmentPrice = convertPriceObjToSegmentPrice;
|
|
7
9
|
exports.convertModifiersPriceToCents = convertModifiersPriceToCents;
|
|
8
10
|
exports.convertSpecialHoursToCents = convertSpecialHoursToCents;
|
|
9
11
|
exports.convertSpecialHoursFromCents = convertSpecialHoursFromCents;
|
|
12
|
+
exports.convertMinifiedSpecialHoursToCents = convertMinifiedSpecialHoursToCents;
|
|
13
|
+
exports.convertMinifiedSpecialHoursFromCents = convertMinifiedSpecialHoursFromCents;
|
|
10
14
|
const catalog_conversion_1 = require("./catalog-conversion");
|
|
11
15
|
const common_1 = require("./common");
|
|
12
16
|
const ingredients_1 = require("./ingredients");
|
|
@@ -41,6 +45,28 @@ function convertPriceObjFromCents(priceObj) {
|
|
|
41
45
|
return keys.reduce((obj, key) => ({ ...obj, [key]: (0, price_conversion_1.convertPriceFromCents)(priceObj[key]) }), {});
|
|
42
46
|
}
|
|
43
47
|
// ====================================================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Scales a minified price (IMinifiedPrice: number when all platforms share
|
|
50
|
+
* one value, otherwise an IPrice object) between the cents domain and the
|
|
51
|
+
* dollar/UI domain while preserving the minified shape — a scalar stays a
|
|
52
|
+
* scalar, an object stays an object. The counterpart of
|
|
53
|
+
* `convertPriceObjToCents` / `convertPriceObjFromCents` for minified values.
|
|
54
|
+
*/
|
|
55
|
+
function convertMinifiedPriceToCents(price) {
|
|
56
|
+
if (price == null)
|
|
57
|
+
return price;
|
|
58
|
+
if (typeof price === 'number')
|
|
59
|
+
return (0, price_conversion_1.convertPriceToCents)(price);
|
|
60
|
+
return convertPriceObjToCents(price) ?? undefined;
|
|
61
|
+
}
|
|
62
|
+
function convertMinifiedPriceFromCents(price) {
|
|
63
|
+
if (price == null)
|
|
64
|
+
return price;
|
|
65
|
+
if (typeof price === 'number')
|
|
66
|
+
return (0, price_conversion_1.convertPriceFromCents)(price);
|
|
67
|
+
return convertPriceObjFromCents(price) ?? undefined;
|
|
68
|
+
}
|
|
69
|
+
// ====================================================================================================
|
|
44
70
|
function mergePriceObjs(priceObj1, priceObj2) {
|
|
45
71
|
if (!priceObj1 && !priceObj2)
|
|
46
72
|
return null;
|
|
@@ -126,3 +152,32 @@ function convertSpecialHoursFromCents(specialHours) {
|
|
|
126
152
|
discount_amount: convertPriceObjFromCents(specialHour.discount_amount),
|
|
127
153
|
}));
|
|
128
154
|
}
|
|
155
|
+
// ====================================================================================================
|
|
156
|
+
/**
|
|
157
|
+
* Same as `convertSpecialHoursToCents` / `convertSpecialHoursFromCents` but for
|
|
158
|
+
* the minified special-hours form (each schedule's `price`/`discount_amount`
|
|
159
|
+
* are IMinifiedPrice values). An empty/missing list stays `undefined` — the
|
|
160
|
+
* simplified payloads do not carry a null special-hours list.
|
|
161
|
+
*/
|
|
162
|
+
function convertMinifiedSpecialHoursToCents(specialHours) {
|
|
163
|
+
if (!specialHours || specialHours.length === 0)
|
|
164
|
+
return undefined;
|
|
165
|
+
return specialHours.map((specialHour) => ({
|
|
166
|
+
...specialHour,
|
|
167
|
+
...(specialHour.price != null ? { price: convertMinifiedPriceToCents(specialHour.price) } : {}),
|
|
168
|
+
...(specialHour.discount_amount != null
|
|
169
|
+
? { discount_amount: convertMinifiedPriceToCents(specialHour.discount_amount) }
|
|
170
|
+
: {}),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
function convertMinifiedSpecialHoursFromCents(specialHours) {
|
|
174
|
+
if (!specialHours || specialHours.length === 0)
|
|
175
|
+
return undefined;
|
|
176
|
+
return specialHours.map((specialHour) => ({
|
|
177
|
+
...specialHour,
|
|
178
|
+
...(specialHour.price != null ? { price: convertMinifiedPriceFromCents(specialHour.price) } : {}),
|
|
179
|
+
...(specialHour.discount_amount != null
|
|
180
|
+
? { discount_amount: convertMinifiedPriceFromCents(specialHour.discount_amount) }
|
|
181
|
+
: {}),
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
import { IHalfHalfSetup } from '../../schemas';
|
|
2
|
-
import { ISimplifiedHalfHalfSetup } from '../types';
|
|
2
|
+
import { ISimplifiedCatalogItem, ISimplifiedHalfHalfSetup } from '../types';
|
|
3
3
|
export declare function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup: IHalfHalfSetup, tenantId: string): ISimplifiedHalfHalfSetup;
|
|
4
4
|
export declare function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalfSetups: IHalfHalfSetup[], tenantId: string): ISimplifiedHalfHalfSetup[];
|
|
5
|
+
/**
|
|
6
|
+
* Converts an ISimplifiedHalfHalfSetup into an ISimplifiedCatalogItem so it
|
|
7
|
+
* can flow through the standard catalog → drawer → cart pipeline just like a
|
|
8
|
+
* regular simplified catalog item (the simplified counterpart of
|
|
9
|
+
* `convertHalfHalfToItem`).
|
|
10
|
+
*
|
|
11
|
+
* The simplified half-half payload carries only menu-list data — no segments,
|
|
12
|
+
* no constituent items, no upsell and no ref rules — so this is a pure field
|
|
13
|
+
* mapping of what ISimplifiedCatalogItem can represent:
|
|
14
|
+
* - item `price`/`tax_rate` are null (there is no base price on the payload;
|
|
15
|
+
* the per-segment prices come from the constituent items at selection time),
|
|
16
|
+
* - `discount_amount` and `item_special_hours` are converted back from the
|
|
17
|
+
* minified (cents) wire form to the original (dollar) representation used by
|
|
18
|
+
* ISimplifiedCatalogItem (same conversion as `getSimplifiedItemWithPrice`),
|
|
19
|
+
* - no `modifiers` are produced (selection structure isn't part of the
|
|
20
|
+
* simplified setup),
|
|
21
|
+
* - `sort_id` is not part of the payload, so it defaults to 0 (same as
|
|
22
|
+
* `convertHalfHalfToItem`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup: ISimplifiedHalfHalfSetup): ISimplifiedCatalogItem;
|
|
25
|
+
/**
|
|
26
|
+
* Converts an ISimplifiedHalfHalfSetup's minified money fields (and those
|
|
27
|
+
* nested in `item_special_hours`) between the cents (server) domain and the
|
|
28
|
+
* dollar/UI domain while preserving the simplified payload shape. Mirrors
|
|
29
|
+
* `getHalfhalfSetupWithPrice` for the full IHalfHalfSetup:
|
|
30
|
+
* - `discount_amount` (IMinifiedPrice) is scaled (a scalar stays a scalar),
|
|
31
|
+
* - `item_special_hours` prices are scaled in place.
|
|
32
|
+
*
|
|
33
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
34
|
+
* carries no upsell/items to convert).
|
|
35
|
+
*/
|
|
36
|
+
export declare function getSimplifiedHalfHalfSetupWithPrice<T extends Partial<ISimplifiedHalfHalfSetup> | ISimplifiedHalfHalfSetup>(halfhalfSetup: T, writeable?: boolean): T;
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertHalfHalfSetupToSimplifiedHalfHalfSetup = convertHalfHalfSetupToSimplifiedHalfHalfSetup;
|
|
4
4
|
exports.convertHalfHalfSetupsToSimplifiedHalfHalfSetups = convertHalfHalfSetupsToSimplifiedHalfHalfSetups;
|
|
5
|
+
exports.convertSimplifiedHalfHalfToSimplifiedItem = convertSimplifiedHalfHalfToSimplifiedItem;
|
|
6
|
+
exports.getSimplifiedHalfHalfSetupWithPrice = getSimplifiedHalfHalfSetupWithPrice;
|
|
5
7
|
const minified_catalog_1 = require("./minified-catalog");
|
|
8
|
+
const platform_num_1 = require("./platform-num");
|
|
6
9
|
function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup, tenantId) {
|
|
7
10
|
return {
|
|
8
11
|
sold_out: halfhalfSetup.sold_out.includes(tenantId) || undefined,
|
|
@@ -28,3 +31,75 @@ function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalfSetups, tenantI
|
|
|
28
31
|
}
|
|
29
32
|
return newHalfHalfSetups;
|
|
30
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts an ISimplifiedHalfHalfSetup into an ISimplifiedCatalogItem so it
|
|
36
|
+
* can flow through the standard catalog → drawer → cart pipeline just like a
|
|
37
|
+
* regular simplified catalog item (the simplified counterpart of
|
|
38
|
+
* `convertHalfHalfToItem`).
|
|
39
|
+
*
|
|
40
|
+
* The simplified half-half payload carries only menu-list data — no segments,
|
|
41
|
+
* no constituent items, no upsell and no ref rules — so this is a pure field
|
|
42
|
+
* mapping of what ISimplifiedCatalogItem can represent:
|
|
43
|
+
* - item `price`/`tax_rate` are null (there is no base price on the payload;
|
|
44
|
+
* the per-segment prices come from the constituent items at selection time),
|
|
45
|
+
* - `discount_amount` and `item_special_hours` are converted back from the
|
|
46
|
+
* minified (cents) wire form to the original (dollar) representation used by
|
|
47
|
+
* ISimplifiedCatalogItem (same conversion as `getSimplifiedItemWithPrice`),
|
|
48
|
+
* - no `modifiers` are produced (selection structure isn't part of the
|
|
49
|
+
* simplified setup),
|
|
50
|
+
* - `sort_id` is not part of the payload, so it defaults to 0 (same as
|
|
51
|
+
* `convertHalfHalfToItem`).
|
|
52
|
+
*/
|
|
53
|
+
function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup) {
|
|
54
|
+
// Minified (cents) wire values → original dollar representation.
|
|
55
|
+
const discount_amount = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(halfhalfSetup.discount_amount));
|
|
56
|
+
const item_special_hours = (0, platform_num_1.convertSpecialHoursFromCents)((0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(halfhalfSetup.item_special_hours));
|
|
57
|
+
return {
|
|
58
|
+
sold_out: halfhalfSetup.sold_out,
|
|
59
|
+
is_discount_percentage: halfhalfSetup.is_discount_percentage,
|
|
60
|
+
discount_amount,
|
|
61
|
+
item_special_hours,
|
|
62
|
+
// No base price / tax on the simplified payload; per-segment prices are
|
|
63
|
+
// resolved from the constituent items at selection time.
|
|
64
|
+
price: null,
|
|
65
|
+
tax_rate: null,
|
|
66
|
+
modifiers: null,
|
|
67
|
+
// sort_id is not part of the simplified payload (mirrors convertHalfHalfToItem).
|
|
68
|
+
sort_id: 0,
|
|
69
|
+
hide_name: false,
|
|
70
|
+
is_featured: false,
|
|
71
|
+
featured_sort_id: 0,
|
|
72
|
+
show_starting_from: false,
|
|
73
|
+
_id: halfhalfSetup._id,
|
|
74
|
+
category_id: halfhalfSetup.category_id,
|
|
75
|
+
name: halfhalfSetup.name,
|
|
76
|
+
included_platforms: halfhalfSetup.included_platforms,
|
|
77
|
+
description: halfhalfSetup.description,
|
|
78
|
+
active: halfhalfSetup.active,
|
|
79
|
+
image_url: halfhalfSetup.image_url,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Converts an ISimplifiedHalfHalfSetup's minified money fields (and those
|
|
84
|
+
* nested in `item_special_hours`) between the cents (server) domain and the
|
|
85
|
+
* dollar/UI domain while preserving the simplified payload shape. Mirrors
|
|
86
|
+
* `getHalfhalfSetupWithPrice` for the full IHalfHalfSetup:
|
|
87
|
+
* - `discount_amount` (IMinifiedPrice) is scaled (a scalar stays a scalar),
|
|
88
|
+
* - `item_special_hours` prices are scaled in place.
|
|
89
|
+
*
|
|
90
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
91
|
+
* carries no upsell/items to convert).
|
|
92
|
+
*/
|
|
93
|
+
function getSimplifiedHalfHalfSetupWithPrice(halfhalfSetup, writeable) {
|
|
94
|
+
const convertToPrice = writeable ? platform_num_1.convertMinifiedPriceToCents : platform_num_1.convertMinifiedPriceFromCents;
|
|
95
|
+
const convertItemSpecialHours = writeable ? platform_num_1.convertMinifiedSpecialHoursToCents : platform_num_1.convertMinifiedSpecialHoursFromCents;
|
|
96
|
+
return {
|
|
97
|
+
...halfhalfSetup,
|
|
98
|
+
...(halfhalfSetup.discount_amount != null
|
|
99
|
+
? { discount_amount: convertToPrice(halfhalfSetup.discount_amount) }
|
|
100
|
+
: {}),
|
|
101
|
+
...(halfhalfSetup.item_special_hours != null
|
|
102
|
+
? { item_special_hours: convertItemSpecialHours(halfhalfSetup.item_special_hours) }
|
|
103
|
+
: {}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
import { ISpecial } from '../../schemas';
|
|
2
|
-
import { ISimplifiedSpecial } from '../types';
|
|
2
|
+
import { ISimplifiedCatalogItem, ISimplifiedSpecial } from '../types';
|
|
3
3
|
export declare function convertSpecialToSimplifiedSpecial(special: ISpecial, tenantId: string): ISimplifiedSpecial;
|
|
4
4
|
export declare function convertSpecialsToSimplifiedSpecials(specials: ISpecial[], tenantId: string): ISimplifiedSpecial[];
|
|
5
|
+
/**
|
|
6
|
+
* Converts an ISimplifiedSpecial into an ISimplifiedCatalogItem so it can
|
|
7
|
+
* flow through the standard catalog → drawer → cart pipeline just like a
|
|
8
|
+
* regular simplified catalog item (the simplified counterpart of
|
|
9
|
+
* `convertSpecialToItem`).
|
|
10
|
+
*
|
|
11
|
+
* The simplified special payload carries only menu-list data — the
|
|
12
|
+
* modifier_specials selection structure is dropped — so this is a pure field
|
|
13
|
+
* mapping of what ISimplifiedCatalogItem can represent:
|
|
14
|
+
* - `price` / `discount_amount` / `item_special_hours` / `display_price` are
|
|
15
|
+
* converted back from the minified (cents) wire form to the original
|
|
16
|
+
* (dollar) representation used by ISimplifiedCatalogItem (same conversion
|
|
17
|
+
* as `getSimplifiedItemWithPrice`),
|
|
18
|
+
* - `tax_rate` is null (not part of the special payload, mirrors
|
|
19
|
+
* `convertSpecialToItem`),
|
|
20
|
+
* - no `modifiers` are produced (selection structure isn't part of the
|
|
21
|
+
* simplified setup).
|
|
22
|
+
*/
|
|
23
|
+
export declare function convertSimplifiedSpecialToSimplifiedItem(special: ISimplifiedSpecial): ISimplifiedCatalogItem;
|
|
24
|
+
/**
|
|
25
|
+
* Converts an ISimplifiedSpecial's minified money fields (and those nested in
|
|
26
|
+
* `item_special_hours`) between the cents (server) domain and the dollar/UI
|
|
27
|
+
* domain while preserving the simplified payload shape. Mirrors
|
|
28
|
+
* `getSpecialWithPrice` for the full ISpecial:
|
|
29
|
+
* - `price` / `discount_amount` (IMinifiedPrice) are scaled (a scalar stays a
|
|
30
|
+
* scalar),
|
|
31
|
+
* - `display_price` (scalar) is scaled,
|
|
32
|
+
* - `item_special_hours` prices are scaled in place.
|
|
33
|
+
*
|
|
34
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
35
|
+
* carries no modifier_specials to convert).
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSimplifiedSpecialWithPrice<T extends Partial<ISimplifiedSpecial> | ISimplifiedSpecial>(special: T, writeable?: boolean): T;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertSpecialToSimplifiedSpecial = convertSpecialToSimplifiedSpecial;
|
|
4
4
|
exports.convertSpecialsToSimplifiedSpecials = convertSpecialsToSimplifiedSpecials;
|
|
5
|
+
exports.convertSimplifiedSpecialToSimplifiedItem = convertSimplifiedSpecialToSimplifiedItem;
|
|
6
|
+
exports.getSimplifiedSpecialWithPrice = getSimplifiedSpecialWithPrice;
|
|
5
7
|
const minified_catalog_1 = require("./minified-catalog");
|
|
8
|
+
const platform_num_1 = require("./platform-num");
|
|
9
|
+
const price_conversion_1 = require("./price-conversion");
|
|
6
10
|
function convertSpecialToSimplifiedSpecial(special, tenantId) {
|
|
7
11
|
return {
|
|
8
12
|
sold_out: special.sold_out.includes(tenantId) || undefined,
|
|
@@ -30,3 +34,79 @@ function convertSpecialsToSimplifiedSpecials(specials, tenantId) {
|
|
|
30
34
|
}
|
|
31
35
|
return newSpecials;
|
|
32
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts an ISimplifiedSpecial into an ISimplifiedCatalogItem so it can
|
|
39
|
+
* flow through the standard catalog → drawer → cart pipeline just like a
|
|
40
|
+
* regular simplified catalog item (the simplified counterpart of
|
|
41
|
+
* `convertSpecialToItem`).
|
|
42
|
+
*
|
|
43
|
+
* The simplified special payload carries only menu-list data — the
|
|
44
|
+
* modifier_specials selection structure is dropped — so this is a pure field
|
|
45
|
+
* mapping of what ISimplifiedCatalogItem can represent:
|
|
46
|
+
* - `price` / `discount_amount` / `item_special_hours` / `display_price` are
|
|
47
|
+
* converted back from the minified (cents) wire form to the original
|
|
48
|
+
* (dollar) representation used by ISimplifiedCatalogItem (same conversion
|
|
49
|
+
* as `getSimplifiedItemWithPrice`),
|
|
50
|
+
* - `tax_rate` is null (not part of the special payload, mirrors
|
|
51
|
+
* `convertSpecialToItem`),
|
|
52
|
+
* - no `modifiers` are produced (selection structure isn't part of the
|
|
53
|
+
* simplified setup).
|
|
54
|
+
*/
|
|
55
|
+
function convertSimplifiedSpecialToSimplifiedItem(special) {
|
|
56
|
+
// Minified (cents) wire values → original dollar representation.
|
|
57
|
+
const price = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.price));
|
|
58
|
+
const discount_amount = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.discount_amount));
|
|
59
|
+
const item_special_hours = (0, platform_num_1.convertSpecialHoursFromCents)((0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(special.item_special_hours));
|
|
60
|
+
const display_price = special.display_price ? (0, price_conversion_1.convertPriceFromCents)(special.display_price) : undefined;
|
|
61
|
+
return {
|
|
62
|
+
sold_out: special.sold_out,
|
|
63
|
+
is_discount_percentage: special.is_discount_percentage,
|
|
64
|
+
show_starting_from: special.show_starting_from,
|
|
65
|
+
display_price,
|
|
66
|
+
price,
|
|
67
|
+
discount_amount,
|
|
68
|
+
item_special_hours,
|
|
69
|
+
// No tax on the special payload (mirrors convertSpecialToItem); no
|
|
70
|
+
// selection structure on the simplified payload.
|
|
71
|
+
tax_rate: null,
|
|
72
|
+
modifiers: null,
|
|
73
|
+
sort_id: special.sort_id,
|
|
74
|
+
hide_name: false,
|
|
75
|
+
is_featured: false,
|
|
76
|
+
featured_sort_id: 0,
|
|
77
|
+
_id: special._id,
|
|
78
|
+
category_id: special.category_id,
|
|
79
|
+
name: special.name,
|
|
80
|
+
included_platforms: special.included_platforms,
|
|
81
|
+
description: special.description,
|
|
82
|
+
active: special.active,
|
|
83
|
+
image_url: special.image_url,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts an ISimplifiedSpecial's minified money fields (and those nested in
|
|
88
|
+
* `item_special_hours`) between the cents (server) domain and the dollar/UI
|
|
89
|
+
* domain while preserving the simplified payload shape. Mirrors
|
|
90
|
+
* `getSpecialWithPrice` for the full ISpecial:
|
|
91
|
+
* - `price` / `discount_amount` (IMinifiedPrice) are scaled (a scalar stays a
|
|
92
|
+
* scalar),
|
|
93
|
+
* - `display_price` (scalar) is scaled,
|
|
94
|
+
* - `item_special_hours` prices are scaled in place.
|
|
95
|
+
*
|
|
96
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
97
|
+
* carries no modifier_specials to convert).
|
|
98
|
+
*/
|
|
99
|
+
function getSimplifiedSpecialWithPrice(special, writeable) {
|
|
100
|
+
const convertToPrice = writeable ? platform_num_1.convertMinifiedPriceToCents : platform_num_1.convertMinifiedPriceFromCents;
|
|
101
|
+
const convertItemSpecialHours = writeable ? platform_num_1.convertMinifiedSpecialHoursToCents : platform_num_1.convertMinifiedSpecialHoursFromCents;
|
|
102
|
+
const convertNumPrice = writeable ? price_conversion_1.convertPriceToCents : price_conversion_1.convertPriceFromCents;
|
|
103
|
+
return {
|
|
104
|
+
...special,
|
|
105
|
+
...(special.price != null ? { price: convertToPrice(special.price) } : {}),
|
|
106
|
+
...(special.discount_amount != null ? { discount_amount: convertToPrice(special.discount_amount) } : {}),
|
|
107
|
+
...(special.display_price != null ? { display_price: convertNumPrice(special.display_price) } : {}),
|
|
108
|
+
...(special.item_special_hours != null
|
|
109
|
+
? { item_special_hours: convertItemSpecialHours(special.item_special_hours) }
|
|
110
|
+
: {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -82,3 +82,94 @@ describe('convertHalfHalfSetupsToSimplifiedHalfHalfSetups', () => {
|
|
|
82
82
|
expect(simplifiedList.map((h) => h._id)).toEqual(['hh-1', 'hh-2']);
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
|
+
function makeSimplifiedHalfHalfSetup(overrides = {}) {
|
|
86
|
+
return {
|
|
87
|
+
_id: 'halfhalf-1',
|
|
88
|
+
category_id: 'category-1',
|
|
89
|
+
name: 'Half & Half',
|
|
90
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
|
|
91
|
+
description: 'Two halves combo',
|
|
92
|
+
active: true,
|
|
93
|
+
image_url: 'https://example.com/halfhalf.jpg',
|
|
94
|
+
...overrides,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
describe('convertSimplifiedHalfHalfToSimplifiedItem', () => {
|
|
98
|
+
it('maps identity fields and nulls out fields not present in the simplified payload', () => {
|
|
99
|
+
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup());
|
|
100
|
+
expect(item._id).toBe('halfhalf-1');
|
|
101
|
+
expect(item.category_id).toBe('category-1');
|
|
102
|
+
expect(item.name).toBe('Half & Half');
|
|
103
|
+
expect(item.description).toBe('Two halves combo');
|
|
104
|
+
expect(item.active).toBe(true);
|
|
105
|
+
expect(item.image_url).toBe('https://example.com/halfhalf.jpg');
|
|
106
|
+
expect(item.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
|
|
107
|
+
// simplified payload has no segments/items/upsell → no base price or modifiers
|
|
108
|
+
expect(item.price).toBeNull();
|
|
109
|
+
expect(item.tax_rate).toBeNull();
|
|
110
|
+
expect(item.discount_amount).toBeNull();
|
|
111
|
+
expect(item.item_special_hours).toBeNull();
|
|
112
|
+
expect(item.modifiers).toBeNull();
|
|
113
|
+
expect(item.sort_id).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
it('carries sold_out through', () => {
|
|
116
|
+
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ sold_out: true }));
|
|
117
|
+
expect(item.sold_out).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
it('converts minified discount_amount back to a dollar IPrice', () => {
|
|
120
|
+
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ discount_amount: 300, is_discount_percentage: true }));
|
|
121
|
+
expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
|
|
122
|
+
expect(item.is_discount_percentage).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
it('converts minified item_special_hours back to original special hours', () => {
|
|
125
|
+
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({
|
|
126
|
+
item_special_hours: [
|
|
127
|
+
{
|
|
128
|
+
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
129
|
+
start_time: 60,
|
|
130
|
+
end_time: 120,
|
|
131
|
+
price: 500,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
}));
|
|
135
|
+
expect(item.item_special_hours).toEqual([
|
|
136
|
+
expect.objectContaining({
|
|
137
|
+
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
138
|
+
start_time: 60,
|
|
139
|
+
end_time: 120,
|
|
140
|
+
price: { BASE_PRICE: 5 },
|
|
141
|
+
discount_amount: null,
|
|
142
|
+
}),
|
|
143
|
+
]);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('getSimplifiedHalfHalfSetupWithPrice', () => {
|
|
147
|
+
it('converts minified discount and special hours from cents to dollars by default', () => {
|
|
148
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
149
|
+
discount_amount: 300,
|
|
150
|
+
item_special_hours: [
|
|
151
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 500, discount_amount: 200 },
|
|
152
|
+
],
|
|
153
|
+
}));
|
|
154
|
+
expect(result.discount_amount).toBe(3);
|
|
155
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 5, discount_amount: 2 })]);
|
|
156
|
+
});
|
|
157
|
+
it('writeable converts dollar values back to cents', () => {
|
|
158
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
159
|
+
discount_amount: 3,
|
|
160
|
+
item_special_hours: [
|
|
161
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 5, discount_amount: 2 },
|
|
162
|
+
],
|
|
163
|
+
}), true);
|
|
164
|
+
expect(result.discount_amount).toBe(300);
|
|
165
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 500, discount_amount: 200 })]);
|
|
166
|
+
});
|
|
167
|
+
it('handles IPrice-object discounts and leaves absent fields untouched', () => {
|
|
168
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
169
|
+
discount_amount: { BASE_PRICE: 1200, [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 1500 },
|
|
170
|
+
}));
|
|
171
|
+
expect(result.discount_amount).toEqual({ BASE_PRICE: 12, [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 15 });
|
|
172
|
+
expect(result.item_special_hours).toBeUndefined();
|
|
173
|
+
expect(result._id).toBe('halfhalf-1');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -10,76 +10,144 @@ function makeSpecial(overrides = {}) {
|
|
|
10
10
|
tenants: ['tenant-1', 'tenant-2'],
|
|
11
11
|
category_id: 'category-1',
|
|
12
12
|
included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
description: 'Special combo',
|
|
13
|
+
name: 'Combo Special',
|
|
14
|
+
description: 'Special combo deal',
|
|
16
15
|
active: true,
|
|
17
16
|
sold_out: ['tenant-2'],
|
|
18
|
-
sort_id:
|
|
19
|
-
|
|
17
|
+
sort_id: 3,
|
|
18
|
+
image_url: 'https://example.com/special.jpg',
|
|
19
|
+
price: { BASE_PRICE: 1000 },
|
|
20
20
|
discount_amount: null,
|
|
21
21
|
is_discount_percentage: false,
|
|
22
|
-
display_price:
|
|
23
|
-
show_starting_from:
|
|
22
|
+
display_price: null,
|
|
23
|
+
show_starting_from: false,
|
|
24
24
|
item_special_hours: null,
|
|
25
|
-
modifier_specials: [
|
|
26
|
-
{
|
|
27
|
-
_id: 'ms-1',
|
|
28
|
-
name: 'Choose 1',
|
|
29
|
-
sort_id: 1,
|
|
30
|
-
quantity: 1,
|
|
31
|
-
num_free_items: 0,
|
|
32
|
-
excluded_refs: [],
|
|
33
|
-
exclusive_refs: [],
|
|
34
|
-
omit_items_schedule: false,
|
|
35
|
-
items: [{ item_id: 'item-1', sort_id: 1, upsell_price: null }],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
25
|
+
modifier_specials: [],
|
|
38
26
|
createdAt: new Date('2024-01-01'),
|
|
39
27
|
updatedAt: new Date('2024-01-02'),
|
|
40
28
|
...overrides,
|
|
41
29
|
};
|
|
42
30
|
}
|
|
31
|
+
function makeSimplifiedSpecial(overrides = {}) {
|
|
32
|
+
return {
|
|
33
|
+
_id: 'special-1',
|
|
34
|
+
category_id: 'category-1',
|
|
35
|
+
name: 'Combo Special',
|
|
36
|
+
included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
|
|
37
|
+
description: 'Special combo deal',
|
|
38
|
+
active: true,
|
|
39
|
+
sort_id: 3,
|
|
40
|
+
image_url: 'https://example.com/special.jpg',
|
|
41
|
+
...overrides,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
43
44
|
describe('convertSpecialToSimplifiedSpecial', () => {
|
|
44
45
|
it('drops full-only fields and resolves sold_out per tenant', () => {
|
|
45
46
|
const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial(), TENANT_ID);
|
|
46
47
|
expect(simplified._id).toBe('special-1');
|
|
47
48
|
expect(simplified.category_id).toBe('category-1');
|
|
48
|
-
expect(simplified.
|
|
49
|
-
expect(simplified.description).toBe('Special combo');
|
|
50
|
-
expect(simplified.active).toBe(true);
|
|
51
|
-
expect(simplified.sort_id).toBe(1);
|
|
52
|
-
expect(simplified.image_url).toBe('https://example.com/special.jpg');
|
|
49
|
+
expect(simplified.sort_id).toBe(3);
|
|
53
50
|
expect(simplified.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
|
|
54
|
-
// full-only fields are dropped
|
|
55
51
|
expect(simplified).not.toHaveProperty('brand_id');
|
|
56
52
|
expect(simplified).not.toHaveProperty('tenants');
|
|
57
53
|
expect(simplified).not.toHaveProperty('createdAt');
|
|
58
54
|
expect(simplified).not.toHaveProperty('updatedAt');
|
|
59
|
-
// sold_out resolved to boolean for the requested tenant (omitted when not sold out)
|
|
60
|
-
expect(simplified.sold_out).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
it('does not expose modifier_specials', () => {
|
|
63
|
-
const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial(), TENANT_ID);
|
|
64
55
|
expect(simplified).not.toHaveProperty('modifier_specials');
|
|
56
|
+
expect(simplified.sold_out).toBeUndefined();
|
|
65
57
|
});
|
|
66
|
-
it('minifies
|
|
67
|
-
const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({
|
|
68
|
-
|
|
69
|
-
discount_amount: { BASE_PRICE: 300 },
|
|
70
|
-
}), TENANT_ID);
|
|
71
|
-
expect(simplified.price).toBe(1500);
|
|
58
|
+
it('minifies setup prices', () => {
|
|
59
|
+
const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({ price: { BASE_PRICE: 1200 }, discount_amount: { BASE_PRICE: 300 } }), TENANT_ID);
|
|
60
|
+
expect(simplified.price).toBe(1200);
|
|
72
61
|
expect(simplified.discount_amount).toBe(300);
|
|
73
62
|
});
|
|
74
|
-
it('handles a special sold out for the tenant', () => {
|
|
75
|
-
const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({ sold_out: ['tenant-1'] }), TENANT_ID);
|
|
76
|
-
expect(simplified.sold_out).toBe(true);
|
|
77
|
-
});
|
|
78
63
|
});
|
|
79
64
|
describe('convertSpecialsToSimplifiedSpecials', () => {
|
|
80
65
|
it('maps every special', () => {
|
|
81
|
-
const simplifiedList = (0, simplified_specials_1.convertSpecialsToSimplifiedSpecials)([makeSpecial({ _id: '
|
|
66
|
+
const simplifiedList = (0, simplified_specials_1.convertSpecialsToSimplifiedSpecials)([makeSpecial({ _id: 'sp-1' }), makeSpecial({ _id: 'sp-2' })], TENANT_ID);
|
|
82
67
|
expect(simplifiedList).toHaveLength(2);
|
|
83
|
-
expect(simplifiedList.map((s) => s._id)).toEqual(['
|
|
68
|
+
expect(simplifiedList.map((s) => s._id)).toEqual(['sp-1', 'sp-2']);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('convertSimplifiedSpecialToSimplifiedItem', () => {
|
|
72
|
+
it('maps identity fields, tax_rate/modifiers null and carries sort_id', () => {
|
|
73
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial());
|
|
74
|
+
expect(item._id).toBe('special-1');
|
|
75
|
+
expect(item.category_id).toBe('category-1');
|
|
76
|
+
expect(item.name).toBe('Combo Special');
|
|
77
|
+
expect(item.description).toBe('Special combo deal');
|
|
78
|
+
expect(item.active).toBe(true);
|
|
79
|
+
expect(item.image_url).toBe('https://example.com/special.jpg');
|
|
80
|
+
expect(item.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
|
|
81
|
+
expect(item.sort_id).toBe(3);
|
|
82
|
+
// no modifier_specials on the simplified payload → no modifiers / tax
|
|
83
|
+
expect(item.modifiers).toBeNull();
|
|
84
|
+
expect(item.tax_rate).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
it('carries sold_out through', () => {
|
|
87
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ sold_out: true }));
|
|
88
|
+
expect(item.sold_out).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
it('converts minified price/discount_amount back to dollar IPrice', () => {
|
|
91
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ price: 1200, discount_amount: 300, is_discount_percentage: true }));
|
|
92
|
+
expect(item.price).toEqual({ BASE_PRICE: 12 });
|
|
93
|
+
expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
|
|
94
|
+
expect(item.is_discount_percentage).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
it('converts minified display_price from cents to dollars', () => {
|
|
97
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ display_price: 1250 }));
|
|
98
|
+
expect(item.display_price).toBe(12.5);
|
|
99
|
+
});
|
|
100
|
+
it('converts minified item_special_hours back to original special hours', () => {
|
|
101
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({
|
|
102
|
+
item_special_hours: [
|
|
103
|
+
{
|
|
104
|
+
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
105
|
+
start_time: 60,
|
|
106
|
+
end_time: 120,
|
|
107
|
+
price: 500,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
}));
|
|
111
|
+
expect(item.item_special_hours).toEqual([
|
|
112
|
+
expect.objectContaining({
|
|
113
|
+
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
114
|
+
start_time: 60,
|
|
115
|
+
end_time: 120,
|
|
116
|
+
price: { BASE_PRICE: 5 },
|
|
117
|
+
discount_amount: null,
|
|
118
|
+
}),
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('getSimplifiedSpecialWithPrice', () => {
|
|
123
|
+
it('converts minified price/discount/display and special hours from cents to dollars by default', () => {
|
|
124
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({
|
|
125
|
+
price: 1200,
|
|
126
|
+
discount_amount: 300,
|
|
127
|
+
display_price: 1250,
|
|
128
|
+
item_special_hours: [
|
|
129
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 500, discount_amount: 200 },
|
|
130
|
+
],
|
|
131
|
+
}));
|
|
132
|
+
expect(result.price).toBe(12);
|
|
133
|
+
expect(result.discount_amount).toBe(3);
|
|
134
|
+
expect(result.display_price).toBe(12.5);
|
|
135
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 5, discount_amount: 2 })]);
|
|
136
|
+
});
|
|
137
|
+
it('writeable converts dollar values back to cents', () => {
|
|
138
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({ price: 12, discount_amount: 3, display_price: 12.5 }), true);
|
|
139
|
+
expect(result.price).toBe(1200);
|
|
140
|
+
expect(result.discount_amount).toBe(300);
|
|
141
|
+
expect(result.display_price).toBe(1250);
|
|
142
|
+
});
|
|
143
|
+
it('handles IPrice-object prices and leaves absent fields untouched', () => {
|
|
144
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({
|
|
145
|
+
price: { BASE_PRICE: 1200, [constants_1.PLATFORMS_ENUM.POS_WALK_IN]: 1500 },
|
|
146
|
+
}));
|
|
147
|
+
expect(result.price).toEqual({ BASE_PRICE: 12, [constants_1.PLATFORMS_ENUM.POS_WALK_IN]: 15 });
|
|
148
|
+
expect(result.discount_amount).toBeUndefined();
|
|
149
|
+
expect(result.display_price).toBeUndefined();
|
|
150
|
+
expect(result._id).toBe('special-1');
|
|
151
|
+
expect(result.sort_id).toBe(3);
|
|
84
152
|
});
|
|
85
153
|
});
|