@managesome/eposmatic-toolkit 0.2.707 → 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.
@@ -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
+ }
@@ -22,3 +22,15 @@ export declare function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalf
22
22
  * `convertHalfHalfToItem`).
23
23
  */
24
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;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertHalfHalfSetupToSimplifiedHalfHalfSetup = convertHalfHalfSetupToSimplifiedHalfHalfSetup;
4
4
  exports.convertHalfHalfSetupsToSimplifiedHalfHalfSetups = convertHalfHalfSetupsToSimplifiedHalfHalfSetups;
5
5
  exports.convertSimplifiedHalfHalfToSimplifiedItem = convertSimplifiedHalfHalfToSimplifiedItem;
6
+ exports.getSimplifiedHalfHalfSetupWithPrice = getSimplifiedHalfHalfSetupWithPrice;
6
7
  const minified_catalog_1 = require("./minified-catalog");
7
8
  const platform_num_1 = require("./platform-num");
8
9
  function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup, tenantId) {
@@ -78,3 +79,27 @@ function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup) {
78
79
  image_url: halfhalfSetup.image_url,
79
80
  };
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
+ }
@@ -21,3 +21,17 @@ export declare function convertSpecialsToSimplifiedSpecials(specials: ISpecial[]
21
21
  * simplified setup).
22
22
  */
23
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;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertSpecialToSimplifiedSpecial = convertSpecialToSimplifiedSpecial;
4
4
  exports.convertSpecialsToSimplifiedSpecials = convertSpecialsToSimplifiedSpecials;
5
5
  exports.convertSimplifiedSpecialToSimplifiedItem = convertSimplifiedSpecialToSimplifiedItem;
6
+ exports.getSimplifiedSpecialWithPrice = getSimplifiedSpecialWithPrice;
6
7
  const minified_catalog_1 = require("./minified-catalog");
7
8
  const platform_num_1 = require("./platform-num");
8
9
  const price_conversion_1 = require("./price-conversion");
@@ -82,3 +83,30 @@ function convertSimplifiedSpecialToSimplifiedItem(special) {
82
83
  image_url: special.image_url,
83
84
  };
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
+ }
@@ -143,3 +143,33 @@ describe('convertSimplifiedHalfHalfToSimplifiedItem', () => {
143
143
  ]);
144
144
  });
145
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
+ });
@@ -119,3 +119,35 @@ describe('convertSimplifiedSpecialToSimplifiedItem', () => {
119
119
  ]);
120
120
  });
121
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);
152
+ });
153
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.707",
3
+ "version": "0.2.708",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",