@managesome/eposmatic-toolkit 0.2.770 → 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 (58) hide show
  1. package/lib/helpers/utils/receipt-engine.js +12 -16
  2. package/lib/tests/receipt-engine.test.js +22 -19
  3. package/package.json +1 -1
  4. package/lib/constants/MATERIALIZED_REPORTS.d.ts +0 -44
  5. package/lib/constants/MATERIALIZED_REPORTS.js +0 -58
  6. package/lib/constants/WAREHOUSE_INVOICE.d.ts +0 -14
  7. package/lib/constants/WAREHOUSE_INVOICE.js +0 -35
  8. package/lib/helpers/offer/generate-offer.d.ts +0 -11
  9. package/lib/helpers/offer/generate-offer.js +0 -143
  10. package/lib/helpers/offer/index.d.ts +0 -1
  11. package/lib/helpers/offer/index.js +0 -17
  12. package/lib/helpers/order/generate-warehouse-invoice.d.ts +0 -11
  13. package/lib/helpers/order/generate-warehouse-invoice.js +0 -196
  14. package/lib/helpers/store/all-warehouse-invoice-actions.d.ts +0 -13
  15. package/lib/helpers/store/all-warehouse-invoice-actions.js +0 -58
  16. package/lib/helpers/store/common-warehouse-invoice-actions.d.ts +0 -31
  17. package/lib/helpers/store/common-warehouse-invoice-actions.js +0 -545
  18. package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +0 -24
  19. package/lib/helpers/store/warehouse-invoice-cart-actions.js +0 -486
  20. package/lib/helpers/types/sockets.d.ts +0 -6
  21. package/lib/helpers/types/sockets.js +0 -2
  22. package/lib/helpers/types/warehouse-invoice-cart-actions.d.ts +0 -26
  23. package/lib/helpers/types/warehouse-invoice-cart-actions.js +0 -2
  24. package/lib/helpers/utils/materialized-report-helpers.d.ts +0 -35
  25. package/lib/helpers/utils/materialized-report-helpers.js +0 -73
  26. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.d.ts +0 -3
  27. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.js +0 -38
  28. package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.d.ts +0 -13
  29. package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.js +0 -22
  30. package/lib/helpers/utils/warehouse-invoice-order-engine.d.ts +0 -11
  31. package/lib/helpers/utils/warehouse-invoice-order-engine.js +0 -39
  32. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.d.ts +0 -58
  33. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.js +0 -1432
  34. package/lib/schemas/models/inventory_department_transactions.d.ts +0 -86
  35. package/lib/schemas/models/inventory_department_transactions.js +0 -116
  36. package/lib/schemas/models/inventory_department_utilities.d.ts +0 -108
  37. package/lib/schemas/models/inventory_department_utilities.js +0 -88
  38. package/lib/schemas/models/inventory_departments.d.ts +0 -53
  39. package/lib/schemas/models/inventory_departments.js +0 -58
  40. package/lib/schemas/models/inventory_entries.d.ts +0 -152
  41. package/lib/schemas/models/inventory_entries.js +0 -142
  42. package/lib/schemas/models/materialized_reports.d.ts +0 -277
  43. package/lib/schemas/models/materialized_reports.js +0 -60
  44. package/lib/schemas/models/warehouse_invoices.d.ts +0 -2675
  45. package/lib/schemas/models/warehouse_invoices.js +0 -327
  46. package/lib/schemas/models/warehouse_void_invoice_items.d.ts +0 -176
  47. package/lib/schemas/models/warehouse_void_invoice_items.js +0 -176
  48. package/lib/schemas/types/inventory_entries.d.ts +0 -41
  49. package/lib/schemas/types/inventory_entries.js +0 -2
  50. package/lib/schemas/types/materialized_reports.d.ts +0 -82
  51. package/lib/schemas/types/materialized_reports.js +0 -2
  52. package/lib/schemas/types/warehouse_invoices.d.ts +0 -69
  53. package/lib/schemas/types/warehouse_invoices.js +0 -2
  54. package/lib/schemas/types/warehouse_void_invoice_items.d.ts +0 -37
  55. package/lib/schemas/types/warehouse_void_invoice_items.js +0 -2
  56. package/lib/tests/materialized-report-helpers.test.d.ts +0 -1
  57. package/lib/tests/no-choice-modifier-selection.test.d.ts +0 -1
  58. package/lib/tests/no-choice-modifier-selection.test.js +0 -142
@@ -354,19 +354,17 @@ 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++) {
361
365
  const option = modifierOptions[j];
362
366
  const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
363
- // The option name can collapse into the modifier name (identical
364
- // modifier/option names, e.g. a deal pizza). In that case the
365
- // modifier name carries the whole line, so it must be kept even
366
- // when hide_modifier_name is on - otherwise the line prints blank.
367
- // Checked on the stripped name: emojis are removed from printed text anyway.
368
- const isMergedWithModifierName = (0, emoji_strip_1.default)(option.name).trim().length === 0;
369
- const optionDescription = hide_modifier_name && !isMergedWithModifierName
367
+ const optionDescription = hide_modifier_name
370
368
  ? `${space}${optionQuantity}`
371
369
  : `${space}${optionQuantity}${modifierName} `;
372
370
  options.push({
@@ -385,15 +383,13 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
385
383
  const modifierName = getItemModifierTitle(modifier.name);
386
384
  for (let j = 0; j < modifier.options.length; j++) {
387
385
  const option = modifier.options[j];
388
- 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));
389
391
  const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
390
- // The option name can collapse into the modifier name (identical
391
- // modifier/option names, e.g. a deal pizza). In that case the
392
- // modifier name carries the whole line, so it must be kept even
393
- // when hide_modifier_name is on - otherwise the line prints blank.
394
- // Checked on the stripped name: emojis are removed from printed text anyway.
395
- const isMergedWithModifierName = (0, emoji_strip_1.default)(optionName).trim().length === 0;
396
- const optionDescription = hide_modifier_name && !isMergedWithModifierName
392
+ const optionDescription = hide_modifier_name
397
393
  ? `${space}${optionQuantity}`
398
394
  : `${space}${optionQuantity}${modifierName} `;
399
395
  options.push({
@@ -265,7 +265,7 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
265
265
  expect(options[0].left).toBe(' TIKKA PIZZA ');
266
266
  expect(options[0].option_name).toBe('');
267
267
  });
268
- it('keeps the modifier name when the option name collapsed into it and hide_modifier_name is on', () => {
268
+ it('prints the full option name when hide_modifier_name is on (no merge)', () => {
269
269
  const options = [];
270
270
  (0, receipt_engine_1.getReceiptItemModifiers)([
271
271
  makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
@@ -273,10 +273,10 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
273
273
  ]),
274
274
  ], options, false, '', true);
275
275
  expect(options).toHaveLength(1);
276
- expect(options[0].left).toBe(' TIKKA PIZZA ');
277
- expect(options[0].option_name).toBe('');
276
+ expect(options[0].left).toBe(' ');
277
+ expect(options[0].option_name).toBe('Tikka pizza');
278
278
  });
279
- it('keeps the collapsed modifier name and quantity when hide_modifier_name is on', () => {
279
+ it('keeps the option name and quantity when hide_modifier_name is on', () => {
280
280
  const options = [];
281
281
  (0, receipt_engine_1.getReceiptItemModifiers)([
282
282
  makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
@@ -284,8 +284,8 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
284
284
  ]),
285
285
  ], options, false, '', true);
286
286
  expect(options).toHaveLength(1);
287
- expect(options[0].left).toBe(' 2x TIKKA PIZZA ');
288
- expect(options[0].option_name).toBe('');
287
+ expect(options[0].left).toBe(' 2x ');
288
+ expect(options[0].option_name).toBe('Tikka pizza');
289
289
  });
290
290
  it('still hides the modifier name when the option name is different', () => {
291
291
  const options = [];
@@ -294,7 +294,7 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
294
294
  expect(options[0].left).toBe(' ');
295
295
  expect(options[0].option_name).toBe('Large');
296
296
  });
297
- it('keeps the collapsed modifier name in separate-lines mode too', () => {
297
+ it('prints the full option name in separate-lines mode when hide_modifier_name is on', () => {
298
298
  const options = [];
299
299
  (0, receipt_engine_1.getReceiptItemModifiers)([
300
300
  makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
@@ -302,29 +302,32 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
302
302
  ]),
303
303
  ], options, true, '', true);
304
304
  expect(options).toHaveLength(1);
305
- expect(options[0].left).toBe(' TIKKA PIZZA ');
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(' ');
306
313
  expect(options[0].option_name).toBe('');
307
314
  });
308
- it('keeps the modifier name when only emojis remain in the option name', () => {
315
+ it('hides the modifier name when the option has no printable text in separate-lines mode too', () => {
309
316
  const options = [];
310
- (0, receipt_engine_1.getReceiptItemModifiers)([
311
- makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
312
- makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza 🍕'),
313
- ]),
314
- ], options, false, '', true);
317
+ (0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [makeOption('opt-tikka', 'pizza-tikka', '🍕')])], options, true, '', true);
315
318
  expect(options).toHaveLength(1);
316
- expect(options[0].left).toBe(' TIKKA PIZZA ');
319
+ expect(options[0].left).toBe(' ');
317
320
  expect(options[0].option_name).toBe('');
318
321
  });
319
- it('keeps the modifier name when only emojis remain in separate-lines mode too', () => {
322
+ it('does not strip the modifier name out of the option name when hiding is on', () => {
320
323
  const options = [];
321
324
  (0, receipt_engine_1.getReceiptItemModifiers)([
322
325
  makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
323
- makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza 🍕'),
326
+ makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza Large'),
324
327
  ]),
325
328
  ], options, true, '', true);
326
329
  expect(options).toHaveLength(1);
327
- expect(options[0].left).toBe(' TIKKA PIZZA ');
328
- expect(options[0].option_name).toBe('');
330
+ expect(options[0].left).toBe(' ');
331
+ expect(options[0].option_name).toBe('Tikka Pizza Large');
329
332
  });
330
333
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.770",
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
- };