@managesome/eposmatic-toolkit 0.2.769 → 0.2.771

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.
Files changed (57) hide show
  1. package/lib/helpers/utils/receipt-engine.js +10 -2
  2. package/lib/tests/classic-specials-quantity.test.js +7 -4
  3. package/lib/tests/receipt-engine.test.js +79 -0
  4. package/package.json +1 -1
  5. package/lib/constants/MATERIALIZED_REPORTS.d.ts +0 -44
  6. package/lib/constants/MATERIALIZED_REPORTS.js +0 -58
  7. package/lib/constants/WAREHOUSE_INVOICE.d.ts +0 -14
  8. package/lib/constants/WAREHOUSE_INVOICE.js +0 -35
  9. package/lib/helpers/offer/generate-offer.d.ts +0 -11
  10. package/lib/helpers/offer/generate-offer.js +0 -143
  11. package/lib/helpers/offer/index.d.ts +0 -1
  12. package/lib/helpers/offer/index.js +0 -17
  13. package/lib/helpers/order/generate-warehouse-invoice.d.ts +0 -11
  14. package/lib/helpers/order/generate-warehouse-invoice.js +0 -196
  15. package/lib/helpers/store/all-warehouse-invoice-actions.d.ts +0 -13
  16. package/lib/helpers/store/all-warehouse-invoice-actions.js +0 -58
  17. package/lib/helpers/store/common-warehouse-invoice-actions.d.ts +0 -31
  18. package/lib/helpers/store/common-warehouse-invoice-actions.js +0 -545
  19. package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +0 -24
  20. package/lib/helpers/store/warehouse-invoice-cart-actions.js +0 -486
  21. package/lib/helpers/types/sockets.d.ts +0 -6
  22. package/lib/helpers/types/sockets.js +0 -2
  23. package/lib/helpers/types/warehouse-invoice-cart-actions.d.ts +0 -26
  24. package/lib/helpers/types/warehouse-invoice-cart-actions.js +0 -2
  25. package/lib/helpers/utils/materialized-report-helpers.d.ts +0 -35
  26. package/lib/helpers/utils/materialized-report-helpers.js +0 -73
  27. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.d.ts +0 -3
  28. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.js +0 -38
  29. package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.d.ts +0 -13
  30. package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.js +0 -22
  31. package/lib/helpers/utils/warehouse-invoice-order-engine.d.ts +0 -11
  32. package/lib/helpers/utils/warehouse-invoice-order-engine.js +0 -39
  33. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.d.ts +0 -58
  34. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.js +0 -1432
  35. package/lib/schemas/models/inventory_department_transactions.d.ts +0 -86
  36. package/lib/schemas/models/inventory_department_transactions.js +0 -116
  37. package/lib/schemas/models/inventory_department_utilities.d.ts +0 -108
  38. package/lib/schemas/models/inventory_department_utilities.js +0 -88
  39. package/lib/schemas/models/inventory_departments.d.ts +0 -53
  40. package/lib/schemas/models/inventory_departments.js +0 -58
  41. package/lib/schemas/models/inventory_entries.d.ts +0 -152
  42. package/lib/schemas/models/inventory_entries.js +0 -142
  43. package/lib/schemas/models/materialized_reports.d.ts +0 -277
  44. package/lib/schemas/models/materialized_reports.js +0 -60
  45. package/lib/schemas/models/warehouse_invoices.d.ts +0 -2675
  46. package/lib/schemas/models/warehouse_invoices.js +0 -327
  47. package/lib/schemas/models/warehouse_void_invoice_items.d.ts +0 -176
  48. package/lib/schemas/models/warehouse_void_invoice_items.js +0 -176
  49. package/lib/schemas/types/inventory_entries.d.ts +0 -41
  50. package/lib/schemas/types/inventory_entries.js +0 -2
  51. package/lib/schemas/types/materialized_reports.d.ts +0 -82
  52. package/lib/schemas/types/materialized_reports.js +0 -2
  53. package/lib/schemas/types/warehouse_invoices.d.ts +0 -69
  54. package/lib/schemas/types/warehouse_invoices.js +0 -2
  55. package/lib/schemas/types/warehouse_void_invoice_items.d.ts +0 -37
  56. package/lib/schemas/types/warehouse_void_invoice_items.js +0 -2
  57. package/lib/tests/materialized-report-helpers.test.d.ts +0 -1
@@ -354,7 +354,11 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
354
354
  else {
355
355
  modifierOptions = modifierOptions.map((option) => ({
356
356
  ...option,
357
- name: (0, common_1.titleCase)(getItemModifierOptionTitle(modifierName, option.name)),
357
+ // With hide_modifier_name on, the modifier name is not printed, so
358
+ // the option name must not be merged with it - keep it as-is.
359
+ name: hide_modifier_name
360
+ ? (0, common_1.titleCase)(option.name)
361
+ : (0, common_1.titleCase)(getItemModifierOptionTitle(modifierName, option.name)),
358
362
  }));
359
363
  }
360
364
  for (let j = 0; j < modifierOptions.length; j++) {
@@ -379,7 +383,11 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
379
383
  const modifierName = getItemModifierTitle(modifier.name);
380
384
  for (let j = 0; j < modifier.options.length; j++) {
381
385
  const option = modifier.options[j];
382
- const optionName = (0, common_1.sentenceCase)(getItemModifierOptionTitle(modifierName, option.name));
386
+ // With hide_modifier_name on, the modifier name is not printed, so
387
+ // the option name must not be merged with it - keep it as-is.
388
+ const optionName = hide_modifier_name
389
+ ? (0, common_1.sentenceCase)(option.name)
390
+ : (0, common_1.sentenceCase)(getItemModifierOptionTitle(modifierName, option.name));
383
391
  const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
384
392
  const optionDescription = hide_modifier_name
385
393
  ? `${space}${optionQuantity}`
@@ -8,10 +8,13 @@ const specials_helpers_1 = require("../helpers/utils/specials-helpers");
8
8
  //
9
9
  // The modern flow lets a cashier pick the same item several times in a group
10
10
  // (merged into one option with a summed quantity). The classic drawer must
11
- // support the same selection semantics:
12
- // - a group's exact total is enforced by the AGGREGATES (repeats allowed),
13
- // - the drawer renders quantity rows (choice quantities),
14
- // - a single-item group is selected in ONE click at the full quantity,
11
+ // support the same selection semantics, with the group's field shape DERIVED
12
+ // per group by `convertSpecialToItem`:
13
+ // - quantity 1 → radio rows (one pick; ticking another replaces it),
14
+ // - quantity > 1 → stepper rows with the exact total enforced by the
15
+ // AGGREGATES (any mix, repeats allowed),
16
+ // - a single-item group is selected in ONE click at the full quantity (and
17
+ // auto-selected when the drawer opens, mirroring the modern auto-fill),
15
18
  // - stored lines with repeated options (merged quantity, free/paid split)
16
19
  // EDIT losslessly — occurrences aggregate into the one engine option.
17
20
  // ============================================================================
@@ -252,3 +252,82 @@ describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
252
252
  expect(bevCategory.items).toHaveLength(0);
253
253
  });
254
254
  });
255
+ // =========================><=========================
256
+ describe('getReceiptItemModifiers - hide_modifier_name', () => {
257
+ it('merges an option name into the modifier name when they are the same', () => {
258
+ const options = [];
259
+ (0, receipt_engine_1.getReceiptItemModifiers)([
260
+ makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
261
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
262
+ ]),
263
+ ], options, false, '', false);
264
+ expect(options).toHaveLength(1);
265
+ expect(options[0].left).toBe(' TIKKA PIZZA ');
266
+ expect(options[0].option_name).toBe('');
267
+ });
268
+ it('prints the full option name when hide_modifier_name is on (no merge)', () => {
269
+ const options = [];
270
+ (0, receipt_engine_1.getReceiptItemModifiers)([
271
+ makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
272
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
273
+ ]),
274
+ ], options, false, '', true);
275
+ expect(options).toHaveLength(1);
276
+ expect(options[0].left).toBe(' ');
277
+ expect(options[0].option_name).toBe('Tikka pizza');
278
+ });
279
+ it('keeps the option name and quantity when hide_modifier_name is on', () => {
280
+ const options = [];
281
+ (0, receipt_engine_1.getReceiptItemModifiers)([
282
+ makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
283
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza', { quantity: 2 }),
284
+ ]),
285
+ ], options, false, '', true);
286
+ expect(options).toHaveLength(1);
287
+ expect(options[0].left).toBe(' 2x ');
288
+ expect(options[0].option_name).toBe('Tikka pizza');
289
+ });
290
+ it('still hides the modifier name when the option name is different', () => {
291
+ const options = [];
292
+ (0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-size', 'modref-size', 'SIZE', [makeOption('opt-large', 'size-large', 'Large')])], options, false, '', true);
293
+ expect(options).toHaveLength(1);
294
+ expect(options[0].left).toBe(' ');
295
+ expect(options[0].option_name).toBe('Large');
296
+ });
297
+ it('prints the full option name in separate-lines mode when hide_modifier_name is on', () => {
298
+ const options = [];
299
+ (0, receipt_engine_1.getReceiptItemModifiers)([
300
+ makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
301
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
302
+ ]),
303
+ ], options, true, '', true);
304
+ expect(options).toHaveLength(1);
305
+ expect(options[0].left).toBe(' ');
306
+ expect(options[0].option_name).toBe('Tikka Pizza');
307
+ });
308
+ it('hides the modifier name even when the option name has no printable text (emoji only)', () => {
309
+ const options = [];
310
+ (0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [makeOption('opt-tikka', 'pizza-tikka', '🍕')])], options, false, '', true);
311
+ expect(options).toHaveLength(1);
312
+ expect(options[0].left).toBe(' ');
313
+ expect(options[0].option_name).toBe('');
314
+ });
315
+ it('hides the modifier name when the option has no printable text in separate-lines mode too', () => {
316
+ const options = [];
317
+ (0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [makeOption('opt-tikka', 'pizza-tikka', '🍕')])], options, true, '', true);
318
+ expect(options).toHaveLength(1);
319
+ expect(options[0].left).toBe(' ');
320
+ expect(options[0].option_name).toBe('');
321
+ });
322
+ it('does not strip the modifier name out of the option name when hiding is on', () => {
323
+ const options = [];
324
+ (0, receipt_engine_1.getReceiptItemModifiers)([
325
+ makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
326
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza Large'),
327
+ ]),
328
+ ], options, true, '', true);
329
+ expect(options).toHaveLength(1);
330
+ expect(options[0].left).toBe(' ');
331
+ expect(options[0].option_name).toBe('Tikka Pizza Large');
332
+ });
333
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.769",
3
+ "version": "0.2.771",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,44 +0,0 @@
1
- /**
2
- * Every materialized report/analytics compilation that runs at day-end.
3
- *
4
- * The order of `ALL_TENANT_PROCESSES` defines the strict, forward-only
5
- * execution order of the day-end pipeline. A materialization handler may
6
- * only ever enqueue the process at `index + 1` — never itself, never an
7
- * earlier one — which makes infinite loops structurally impossible.
8
- */
9
- export declare enum TENANT_PROCESS_ENUM {
10
- SALES_OVERVIEW_REPORT = "SALES_OVERVIEW_REPORT"
11
- }
12
- /**
13
- * Static, ordered, finite list of day-end processes.
14
- * Handlers advance strictly forward through this array.
15
- */
16
- export declare const ALL_TENANT_PROCESSES: TENANT_PROCESS_ENUM[];
17
- /**
18
- * The local-time granularity a materialized document is compiled for.
19
- * Each materialized report stores 6 documents per tenant-day — one per
20
- * query field — so the frontend can query by date / week / month /
21
- * quarter / semester / year using targeted `$in` queries against
22
- * dedicated partial indexes.
23
- */
24
- export declare enum REPORT_QUERY_FIELD_ENUM {
25
- LOCAL_DATE = "localDate",
26
- LOCAL_WEEK = "localWeek",
27
- LOCAL_MONTH = "localMonth",
28
- LOCAL_QUARTER = "localQuarter",
29
- LOCAL_SEMESTER = "localSemester",
30
- LOCAL_YEAR = "localYear"
31
- }
32
- export declare const ALL_REPORT_QUERY_FIELDS: REPORT_QUERY_FIELD_ENUM[];
33
- /** How the materialized document was produced. */
34
- export declare enum MATERIALIZE_SOURCE_ENUM {
35
- DAY_END = "DAY_END",
36
- MANUAL = "MANUAL",
37
- BACKFILL = "BACKFILL"
38
- }
39
- export declare const ALL_MATERIALIZE_SOURCES: MATERIALIZE_SOURCE_ENUM[];
40
- /** Collection names for materialized reporting. */
41
- export declare const TENANT_PROCESSES_COLLECTION_NAME = "tenant_processes";
42
- export declare const TENANT_SALES_OVERVIEW_REPORT_COLLECTION_NAME = "tenant_sales_overview_report";
43
- /** Default ETA (seconds) after which a finished tenant_processes doc resets. */
44
- export declare const TENANT_PROCESSES_RESET_ETA_SECONDS = 300;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- // ======================>> MATERIALIZED REPORTS / ANALYTICS <<====================== //
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TENANT_PROCESSES_RESET_ETA_SECONDS = exports.TENANT_SALES_OVERVIEW_REPORT_COLLECTION_NAME = exports.TENANT_PROCESSES_COLLECTION_NAME = exports.ALL_MATERIALIZE_SOURCES = exports.MATERIALIZE_SOURCE_ENUM = exports.ALL_REPORT_QUERY_FIELDS = exports.REPORT_QUERY_FIELD_ENUM = exports.ALL_TENANT_PROCESSES = exports.TENANT_PROCESS_ENUM = void 0;
5
- /**
6
- * Every materialized report/analytics compilation that runs at day-end.
7
- *
8
- * The order of `ALL_TENANT_PROCESSES` defines the strict, forward-only
9
- * execution order of the day-end pipeline. A materialization handler may
10
- * only ever enqueue the process at `index + 1` — never itself, never an
11
- * earlier one — which makes infinite loops structurally impossible.
12
- */
13
- var TENANT_PROCESS_ENUM;
14
- (function (TENANT_PROCESS_ENUM) {
15
- TENANT_PROCESS_ENUM["SALES_OVERVIEW_REPORT"] = "SALES_OVERVIEW_REPORT";
16
- // Future materialized reports / analytics are appended here, e.g.:
17
- // SALES_SUMMARY_REPORT = 'SALES_SUMMARY_REPORT',
18
- // X_REPORT = 'X_REPORT',
19
- })(TENANT_PROCESS_ENUM || (exports.TENANT_PROCESS_ENUM = TENANT_PROCESS_ENUM = {}));
20
- /**
21
- * Static, ordered, finite list of day-end processes.
22
- * Handlers advance strictly forward through this array.
23
- */
24
- exports.ALL_TENANT_PROCESSES = [TENANT_PROCESS_ENUM.SALES_OVERVIEW_REPORT];
25
- // ======================>> <<====================== //
26
- /**
27
- * The local-time granularity a materialized document is compiled for.
28
- * Each materialized report stores 6 documents per tenant-day — one per
29
- * query field — so the frontend can query by date / week / month /
30
- * quarter / semester / year using targeted `$in` queries against
31
- * dedicated partial indexes.
32
- */
33
- var REPORT_QUERY_FIELD_ENUM;
34
- (function (REPORT_QUERY_FIELD_ENUM) {
35
- REPORT_QUERY_FIELD_ENUM["LOCAL_DATE"] = "localDate";
36
- REPORT_QUERY_FIELD_ENUM["LOCAL_WEEK"] = "localWeek";
37
- REPORT_QUERY_FIELD_ENUM["LOCAL_MONTH"] = "localMonth";
38
- REPORT_QUERY_FIELD_ENUM["LOCAL_QUARTER"] = "localQuarter";
39
- REPORT_QUERY_FIELD_ENUM["LOCAL_SEMESTER"] = "localSemester";
40
- REPORT_QUERY_FIELD_ENUM["LOCAL_YEAR"] = "localYear";
41
- })(REPORT_QUERY_FIELD_ENUM || (exports.REPORT_QUERY_FIELD_ENUM = REPORT_QUERY_FIELD_ENUM = {}));
42
- exports.ALL_REPORT_QUERY_FIELDS = Object.values(REPORT_QUERY_FIELD_ENUM);
43
- // ======================>> <<====================== //
44
- /** How the materialized document was produced. */
45
- var MATERIALIZE_SOURCE_ENUM;
46
- (function (MATERIALIZE_SOURCE_ENUM) {
47
- MATERIALIZE_SOURCE_ENUM["DAY_END"] = "DAY_END";
48
- MATERIALIZE_SOURCE_ENUM["MANUAL"] = "MANUAL";
49
- MATERIALIZE_SOURCE_ENUM["BACKFILL"] = "BACKFILL";
50
- })(MATERIALIZE_SOURCE_ENUM || (exports.MATERIALIZE_SOURCE_ENUM = MATERIALIZE_SOURCE_ENUM = {}));
51
- exports.ALL_MATERIALIZE_SOURCES = Object.values(MATERIALIZE_SOURCE_ENUM);
52
- // ======================>> <<====================== //
53
- /** Collection names for materialized reporting. */
54
- exports.TENANT_PROCESSES_COLLECTION_NAME = 'tenant_processes';
55
- exports.TENANT_SALES_OVERVIEW_REPORT_COLLECTION_NAME = 'tenant_sales_overview_report';
56
- // ======================>> <<====================== //
57
- /** Default ETA (seconds) after which a finished tenant_processes doc resets. */
58
- exports.TENANT_PROCESSES_RESET_ETA_SECONDS = 300; // 5 minutes
@@ -1,14 +0,0 @@
1
- import type { IWarehouseClientInvoice } from '../schemas';
2
- export interface IWarehouseInvoiceStatus {
3
- status: IWarehouseClientInvoice['order_status'];
4
- color: string;
5
- contrast_color: string;
6
- priority: number;
7
- }
8
- export interface IWarehouseInvoiceStatusColorCode {
9
- color: string;
10
- contrast_color: string;
11
- }
12
- export type IWarehouseInvoiceStatusColorCodeMap = Record<IWarehouseClientInvoice['order_status'], IWarehouseInvoiceStatusColorCode>;
13
- export declare const DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP: IWarehouseInvoiceStatusColorCodeMap;
14
- export declare const DEFAULT_WAREHOUSE_INVOICE_STATUS: IWarehouseInvoiceStatus[];
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_WAREHOUSE_INVOICE_STATUS = exports.DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP = void 0;
4
- const WAREHOUSE_ENUMS_1 = require("./WAREHOUSE_ENUMS");
5
- exports.DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP = {
6
- [WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.PENDING]: {
7
- color: '#727472',
8
- contrast_color: '#FFFFFF',
9
- },
10
- [WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.COMPLETED]: {
11
- color: '#4CC417',
12
- contrast_color: '#FFFFFF',
13
- },
14
- [WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.CANCELLED]: {
15
- color: '#FF0000',
16
- contrast_color: '#FFFFFF',
17
- },
18
- };
19
- exports.DEFAULT_WAREHOUSE_INVOICE_STATUS = [
20
- {
21
- status: WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.PENDING,
22
- ...exports.DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP[WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.PENDING],
23
- priority: 0,
24
- },
25
- {
26
- status: WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.COMPLETED,
27
- ...exports.DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP[WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.COMPLETED],
28
- priority: 1,
29
- },
30
- {
31
- status: WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.CANCELLED,
32
- ...exports.DEFAULT_WAREHOUSE_INVOICE_STATUS_COLOR_CODE_MAP[WAREHOUSE_ENUMS_1.WAREHOUSE_INVOICE_STATUS_ENUM.CANCELLED],
33
- priority: 2,
34
- },
35
- ];
@@ -1,11 +0,0 @@
1
- import Mongoose from 'mongoose';
2
- import { IItemSpecialHour, IOffer } from '../../schemas';
3
- export declare function generateOfferSpecialHours(specialHours?: IItemSpecialHour[] | null): IItemSpecialHour[] | null;
4
- export declare function generateOfferOnCreate<T extends IOffer | Partial<IOffer>>(offer: T): T;
5
- export declare function generateOfferOnUpdate(partialUpdatedOffer: Partial<IOffer>): {
6
- updateOperation: {
7
- $unset?: (Mongoose.AnyKeys<IOffer> & Mongoose.AnyObject) | undefined;
8
- $set?: (Mongoose.AnyKeys<IOffer> & Mongoose.AnyObject) | undefined;
9
- };
10
- partialResponseOffer: Partial<IOffer>;
11
- };
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateOfferSpecialHours = generateOfferSpecialHours;
7
- exports.generateOfferOnCreate = generateOfferOnCreate;
8
- exports.generateOfferOnUpdate = generateOfferOnUpdate;
9
- const mongoose_1 = __importDefault(require("mongoose"));
10
- function toObjectId(value) {
11
- return new mongoose_1.default.Types.ObjectId(value);
12
- }
13
- function toObjectIdArray(values) {
14
- return values.map((value) => toObjectId(value));
15
- }
16
- function generateOfferSpecialHours(specialHours) {
17
- if (specialHours == null)
18
- return null;
19
- return specialHours.map((specialHour) => ({
20
- ...specialHour,
21
- start_date: specialHour.start_date != null ? new Date(specialHour.start_date) : null,
22
- end_date: specialHour.end_date != null ? new Date(specialHour.end_date) : null,
23
- }));
24
- }
25
- function getOfferPathway(offer) {
26
- const normalizedPathway = {};
27
- if (offer.pathway_to_unlock_type_items != null) {
28
- normalizedPathway.pathway_to_unlock_type_items = {
29
- ...offer.pathway_to_unlock_type_items,
30
- item_ids: toObjectIdArray(offer.pathway_to_unlock_type_items.item_ids),
31
- category_ids: toObjectIdArray(offer.pathway_to_unlock_type_items.category_ids),
32
- };
33
- }
34
- if (offer.pathway_to_unlock_type_vouchers != null) {
35
- normalizedPathway.pathway_to_unlock_type_vouchers = {
36
- ...offer.pathway_to_unlock_type_vouchers,
37
- voucher_ids: toObjectIdArray(offer.pathway_to_unlock_type_vouchers.voucher_ids),
38
- };
39
- }
40
- return normalizedPathway;
41
- }
42
- function getNormalizedRewardItems(rewardItems) {
43
- return {
44
- ...rewardItems,
45
- item_ids: toObjectIdArray(rewardItems.item_ids),
46
- ...(rewardItems.allocation != null
47
- ? {
48
- allocation: rewardItems.allocation.map((allocation) => ({
49
- ...allocation,
50
- item_ids: toObjectIdArray(allocation.item_ids),
51
- })),
52
- }
53
- : {}),
54
- };
55
- }
56
- function getNormalizedRewardDiscountItems(rewardDiscountItems) {
57
- return {
58
- ...rewardDiscountItems,
59
- item_ids: toObjectIdArray(rewardDiscountItems.item_ids),
60
- ...(rewardDiscountItems.allocation != null
61
- ? {
62
- allocation: rewardDiscountItems.allocation.map((allocation) => ({
63
- ...allocation,
64
- item_ids: toObjectIdArray(allocation.item_ids),
65
- })),
66
- }
67
- : {}),
68
- };
69
- }
70
- function getOfferReward(offer) {
71
- const normalizedReward = {};
72
- if (offer.reward_items != null) {
73
- normalizedReward.reward_items = getNormalizedRewardItems(offer.reward_items);
74
- }
75
- if (offer.reward_discount_items != null) {
76
- normalizedReward.reward_discount_items = getNormalizedRewardDiscountItems(offer.reward_discount_items);
77
- }
78
- return normalizedReward;
79
- }
80
- const OFFER_VARIANT_FIELDS = [
81
- 'pathway_to_unlock_type_items',
82
- 'pathway_to_unlock_type_orders',
83
- 'pathway_to_unlock_type_points',
84
- 'pathway_to_unlock_type_vouchers',
85
- 'reward_items',
86
- 'reward_discount',
87
- 'reward_discount_items',
88
- 'reward_points',
89
- 'reward_cashback',
90
- 'reward_gift_cards',
91
- 'reward_voucher',
92
- ];
93
- function generateOfferOnCreate(offer) {
94
- const newOffer = {
95
- ...offer,
96
- ...getOfferPathway(offer),
97
- ...getOfferReward(offer),
98
- ...(offer.offer_special_hours != null
99
- ? { offer_special_hours: generateOfferSpecialHours(offer.offer_special_hours) }
100
- : {}),
101
- _id: toObjectId(offer._id),
102
- };
103
- const cleanedOffer = newOffer;
104
- if (cleanedOffer.offer_special_hours == null) {
105
- delete cleanedOffer.offer_special_hours;
106
- }
107
- OFFER_VARIANT_FIELDS.forEach((field) => {
108
- if (cleanedOffer[field] == null) {
109
- delete cleanedOffer[field];
110
- }
111
- });
112
- return cleanedOffer;
113
- }
114
- // ===============================>>><<<=====================================
115
- function generateOfferOnUpdate(partialUpdatedOffer) {
116
- const partialResponseOffer = {
117
- ...partialUpdatedOffer,
118
- };
119
- const unset = {};
120
- const set = {
121
- ...partialUpdatedOffer,
122
- ...getOfferPathway(partialUpdatedOffer),
123
- ...getOfferReward(partialUpdatedOffer),
124
- ...(partialUpdatedOffer.offer_special_hours != null
125
- ? { offer_special_hours: generateOfferSpecialHours(partialUpdatedOffer.offer_special_hours) }
126
- : {}),
127
- };
128
- if (set.offer_special_hours === null) {
129
- delete set.offer_special_hours;
130
- unset['offer_special_hours'] = '';
131
- }
132
- OFFER_VARIANT_FIELDS.forEach((field) => {
133
- if (set[field] === null) {
134
- delete set[field];
135
- unset[field] = '';
136
- }
137
- });
138
- const updateOperation = {
139
- ...(Object.keys(set).length > 0 ? { $set: set } : {}),
140
- ...(Object.keys(unset).length > 0 ? { $unset: unset } : {}),
141
- };
142
- return { updateOperation, partialResponseOffer };
143
- }
@@ -1 +0,0 @@
1
- export * from './generate-offer';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./generate-offer"), exports);
@@ -1,11 +0,0 @@
1
- import { IWarehouseClientInvoice, IWarehouseClientInvoiceIteration } from '../../schemas';
2
- export declare function generateWarehouseClientInvoiceCategories(categories?: IWarehouseClientInvoice['categories']): IWarehouseClientInvoice['categories'];
3
- export declare function generateWarehouseClientInvoiceIteration(order: IWarehouseClientInvoice | IWarehouseClientInvoiceIteration, partial?: boolean, skipItemMetadata?: boolean): IWarehouseClientInvoiceIteration;
4
- export declare function generateWarehouseClientInvoiceOnCreate<T extends IWarehouseClientInvoice | Partial<IWarehouseClientInvoice>>(order: T, withIterations?: boolean): T;
5
- export declare function generateWarehouseClientInvoiceOnUpdate(partialUpdatedOrder: Partial<IWarehouseClientInvoice>): {
6
- updateOperation: {
7
- $unset?: Partial<Record<string | number | symbol, any>> | undefined;
8
- $set?: Partial<Record<string | number | symbol, any>> | undefined;
9
- };
10
- partialResponseOrder: IWarehouseClientInvoice;
11
- };