@managesome/eposmatic-toolkit 0.3.10 → 0.4.0

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 (145) hide show
  1. package/esm/constants/ENUMS.js +17 -1988
  2. package/esm/constants/MATERIALIZED_REPORTS.js +105 -0
  3. package/esm/constants/enums/cash.js +45 -0
  4. package/esm/constants/enums/communications.js +329 -0
  5. package/esm/constants/enums/delivery.js +35 -0
  6. package/esm/constants/enums/geo.js +150 -0
  7. package/esm/constants/enums/hr.js +130 -0
  8. package/esm/constants/enums/internal.js +132 -0
  9. package/esm/constants/enums/items.js +126 -0
  10. package/esm/constants/enums/misc.js +35 -0
  11. package/esm/constants/enums/offers.js +102 -0
  12. package/esm/constants/enums/order.js +135 -0
  13. package/esm/constants/enums/payments.js +186 -0
  14. package/esm/constants/enums/platform.js +215 -0
  15. package/esm/constants/enums/printing.js +107 -0
  16. package/esm/constants/enums/users.js +245 -0
  17. package/esm/constants/enums/wallet.js +32 -0
  18. package/esm/helpers/materialized-reports/index.js +5 -0
  19. package/esm/helpers/materialized-reports/key-helpers.js +59 -0
  20. package/esm/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +60 -0
  21. package/esm/helpers/materialized-reports/scope-helpers.js +107 -0
  22. package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +251 -0
  23. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +860 -0
  24. package/esm/helpers/store/cart-actions.js +1 -1
  25. package/esm/helpers/store/common-tenant-purchase-order-actions.js +7 -7
  26. package/esm/helpers/store/common-warehouse-purchase-order-actions.js +1 -1
  27. package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +1 -1
  28. package/esm/helpers/store/common-warehouse-sale-order-actions.js +1 -1
  29. package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +1 -1
  30. package/esm/helpers/store/offline-ordering.js +1 -1
  31. package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +1 -1
  32. package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +1 -1
  33. package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +1 -1
  34. package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +1 -1
  35. package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +1 -1
  36. package/esm/helpers/utils/cancellation-helpers.js +7 -0
  37. package/esm/helpers/utils/common.js +0 -46
  38. package/esm/helpers/utils/getFormFieldsDiff.js +1 -1
  39. package/esm/helpers/utils/index.js +2 -0
  40. package/esm/helpers/utils/phone-helpers.js +40 -0
  41. package/esm/helpers/utils/receipt-engine.js +3 -1
  42. package/esm/helpers/utils/specials-helpers.js +1 -1
  43. package/esm/helpers/utils/void-items-report-helpers.js +2 -1
  44. package/esm/schemas/models/materialized_tenant_reports_iterations.js +82 -0
  45. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +399 -0
  46. package/esm/schemas/types/materialized_tenant_reports_iterations.js +1 -0
  47. package/esm/schemas/types/materialized_tenant_sales_overview_reports.js +1 -0
  48. package/lib/constants/ENUMS.d.ts +15 -1275
  49. package/lib/constants/ENUMS.js +31 -1994
  50. package/lib/constants/MATERIALIZED_REPORTS.d.ts +96 -0
  51. package/lib/constants/MATERIALIZED_REPORTS.js +108 -0
  52. package/lib/constants/enums/cash.d.ts +35 -0
  53. package/lib/constants/enums/cash.js +48 -0
  54. package/lib/constants/enums/communications.d.ts +79 -0
  55. package/lib/constants/enums/communications.js +332 -0
  56. package/lib/constants/enums/delivery.d.ts +26 -0
  57. package/lib/constants/enums/delivery.js +38 -0
  58. package/lib/constants/enums/geo.d.ts +133 -0
  59. package/lib/constants/enums/geo.js +153 -0
  60. package/lib/constants/enums/hr.d.ts +105 -0
  61. package/lib/constants/enums/hr.js +133 -0
  62. package/lib/constants/enums/internal.d.ts +104 -0
  63. package/lib/constants/enums/internal.js +135 -0
  64. package/lib/constants/enums/items.d.ts +94 -0
  65. package/lib/constants/enums/items.js +129 -0
  66. package/lib/constants/enums/misc.d.ts +25 -0
  67. package/lib/constants/enums/misc.js +38 -0
  68. package/lib/constants/enums/offers.d.ts +80 -0
  69. package/lib/constants/enums/offers.js +105 -0
  70. package/lib/constants/enums/order.d.ts +108 -0
  71. package/lib/constants/enums/order.js +138 -0
  72. package/lib/constants/enums/payments.d.ts +129 -0
  73. package/lib/constants/enums/payments.js +189 -0
  74. package/lib/constants/enums/platform.d.ts +100 -0
  75. package/lib/constants/enums/platform.js +218 -0
  76. package/lib/constants/enums/printing.d.ts +89 -0
  77. package/lib/constants/enums/printing.js +110 -0
  78. package/lib/constants/enums/users.d.ts +142 -0
  79. package/lib/constants/enums/users.js +248 -0
  80. package/lib/constants/enums/wallet.d.ts +26 -0
  81. package/lib/constants/enums/wallet.js +35 -0
  82. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  83. package/lib/helpers/materialized-reports/index.js +21 -0
  84. package/lib/helpers/materialized-reports/key-helpers.d.ts +35 -0
  85. package/lib/helpers/materialized-reports/key-helpers.js +64 -0
  86. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.d.ts +66 -0
  87. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +63 -0
  88. package/lib/helpers/materialized-reports/scope-helpers.d.ts +57 -0
  89. package/lib/helpers/materialized-reports/scope-helpers.js +114 -0
  90. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +125 -0
  91. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +256 -0
  92. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +223 -0
  93. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +875 -0
  94. package/lib/helpers/store/cart-actions.js +6 -6
  95. package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +2 -2
  96. package/lib/helpers/store/common-tenant-purchase-order-actions.js +10 -10
  97. package/lib/helpers/store/common-warehouse-purchase-order-actions.js +4 -4
  98. package/lib/helpers/store/common-warehouse-purchase-order-rfq-actions.js +4 -4
  99. package/lib/helpers/store/common-warehouse-sale-order-actions.js +4 -4
  100. package/lib/helpers/store/common-warehouse-sale-order-rfq-actions.js +4 -4
  101. package/lib/helpers/store/offline-ordering.js +2 -2
  102. package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +2 -2
  103. package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +2 -2
  104. package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +2 -2
  105. package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.js +2 -2
  106. package/lib/helpers/store/warehouse-sale-orders-cart-actions.js +2 -2
  107. package/lib/helpers/utils/cancellation-helpers.d.ts +1 -0
  108. package/lib/helpers/utils/cancellation-helpers.js +13 -0
  109. package/lib/helpers/utils/common.d.ts +0 -6
  110. package/lib/helpers/utils/common.js +1 -54
  111. package/lib/helpers/utils/getFormFieldsDiff.js +5 -2
  112. package/lib/helpers/utils/index.d.ts +2 -0
  113. package/lib/helpers/utils/index.js +2 -0
  114. package/lib/helpers/utils/phone-helpers.d.ts +5 -0
  115. package/lib/helpers/utils/phone-helpers.js +46 -0
  116. package/lib/helpers/utils/receipt-engine.js +4 -2
  117. package/lib/helpers/utils/specials-helpers.js +2 -2
  118. package/lib/helpers/utils/void-items-report-helpers.js +3 -2
  119. package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +80 -0
  120. package/lib/schemas/models/materialized_tenant_reports_iterations.js +85 -0
  121. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +569 -0
  122. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +402 -0
  123. package/lib/schemas/types/materialized_tenant_reports_iterations.d.ts +62 -0
  124. package/lib/schemas/types/materialized_tenant_reports_iterations.js +2 -0
  125. package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +242 -0
  126. package/lib/schemas/types/materialized_tenant_sales_overview_reports.js +3 -0
  127. package/lib/tests/materialized-reports/fixtures.d.ts +81 -0
  128. package/lib/tests/materialized-reports/fixtures.js +87 -0
  129. package/lib/tests/materialized-reports/fixtures.test.d.ts +1 -0
  130. package/lib/tests/materialized-reports/fixtures.test.js +123 -0
  131. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.d.ts +1 -0
  132. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.js +75 -0
  133. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.d.ts +1 -0
  134. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +73 -0
  135. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.d.ts +1 -0
  136. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +207 -0
  137. package/lib/tests/materialized-reports/sales-overview-baseline.test.d.ts +1 -0
  138. package/lib/tests/materialized-reports/sales-overview-baseline.test.js +326 -0
  139. package/lib/tests/materialized-reports/sales-overview-reference.d.ts +63 -0
  140. package/lib/tests/materialized-reports/sales-overview-reference.js +131 -0
  141. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.d.ts +1 -0
  142. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +335 -0
  143. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.d.ts +1 -0
  144. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +885 -0
  145. package/package.json +5 -2
@@ -0,0 +1,399 @@
1
+ import { Schema } from 'mongoose';
2
+ import { REPORT_SALE_TYPE_ENUM } from '../../constants';
3
+ import { ALL_DAY_INDEX } from '../../constants/ENUMS';
4
+ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, ALL_MATERIALIZED_REPORT_SCOPES, SALES_OVERVIEW_KEY_FILTERS, } from '../../constants/MATERIALIZED_REPORTS';
5
+ /**
6
+ * Mongoose schema for `materialized_tenant_sales_overview_reports` — the
7
+ * materialized Reports > Overview data (one document per tenant × scope
8
+ * context × scope value), maintained by the day-end materialization job and
9
+ * read by the analytics API. Scope slices are stamped from the order's
10
+ * business day (`order.localDate`); hour buckets use the punch hour for sales
11
+ * and the settlement hour for credit-bill collections (see
12
+ * `MATERIALIZED_REPORTS.md`). The report's time-bias toggle (Punched At /
13
+ * `createdAt`) is out of scope. `scope_field` formats are documented on
14
+ * `MATERIALIZED_REPORT_SCOPE_ENUM` and in `MATERIALIZED_REPORTS.md`.
15
+ * Credit bills (`PAY_LATER`) live in each `sale_type_metrics` key's
16
+ * `CREDIT_BILLS` slot as a ledger (issued + settled tracking / received);
17
+ * gross stays sales-only and report views are derived by the frontend
18
+ * formatter. Iteration history (every structural write's full post-write
19
+ * snapshot) lives in the shared `materialized_tenant_reports_iterations` collection.
20
+ */
21
+ /**
22
+ * Version of the key grammar + metric rules of this collection. Bump when
23
+ * `sale_type_key_filters`, their order, or metric semantics change —
24
+ * historical documents must then be re-materialized (readers may branch on
25
+ * this value during a rollout).
26
+ */
27
+ export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
28
+ const ReportDiscountByTypeSchema = new Schema({
29
+ special_discount: {
30
+ type: Number, // cents — Σ order_discount_details.special_discount
31
+ required: true,
32
+ },
33
+ loyalty_discount: {
34
+ type: Number, // cents — Σ order_discount_details.loyalty_discount
35
+ required: true,
36
+ },
37
+ voucher_discount: {
38
+ type: Number, // cents — Σ order_discount_details.voucher_discount
39
+ required: true,
40
+ },
41
+ }, { _id: false, minimize: false });
42
+ const ReportOrderMetricSchema = new Schema({
43
+ count: {
44
+ type: Number,
45
+ required: true,
46
+ min: 0,
47
+ },
48
+ gross_amount: {
49
+ type: Number, // cents — Σ amount_earned of the bucket's orders
50
+ required: true,
51
+ },
52
+ discount_amount: {
53
+ type: Number, // cents — Σ total_discount_applied
54
+ required: true,
55
+ },
56
+ discount_by_type: {
57
+ type: ReportDiscountByTypeSchema,
58
+ required: true,
59
+ },
60
+ gst_amount: {
61
+ type: Number, // cents — Σ gst_amount
62
+ required: true,
63
+ },
64
+ tax_amount: {
65
+ type: Number, // cents — Σ tax_amount
66
+ required: true,
67
+ },
68
+ tip_amount: {
69
+ type: Number, // cents — Σ tip_amount
70
+ required: true,
71
+ },
72
+ tax_invoice_provider_charges: {
73
+ type: Number, // cents — Σ tax_invoice_provider_charges
74
+ required: true,
75
+ },
76
+ delivery_charges: {
77
+ type: Number, // cents — Σ delivery_details.delivery_cost
78
+ required: true,
79
+ },
80
+ }, { _id: false, minimize: false });
81
+ const ReportPaymentMetricSchema = new Schema({
82
+ payment_type: {
83
+ type: String,
84
+ // enum: ALL_PAYMENT_TYPE_NAMES, — intentionally NOT enforced: live stores
85
+ // contain legacy/aggregator values (CARD_PAYMENT, FOODPANDA, PLAZA, …)
86
+ // that must pass through reporting untouched.
87
+ required: true,
88
+ },
89
+ count: {
90
+ type: Number,
91
+ required: true,
92
+ min: 0,
93
+ },
94
+ gross_amount: {
95
+ type: Number, // cents — net of refunds & card charges; may be negative
96
+ required: true,
97
+ },
98
+ amount_due: {
99
+ type: Number,
100
+ required: true,
101
+ min: 0,
102
+ },
103
+ amount_paid: {
104
+ type: Number,
105
+ required: true,
106
+ min: 0,
107
+ },
108
+ amount_refunded: {
109
+ type: Number,
110
+ required: true,
111
+ min: 0,
112
+ },
113
+ card_charges: {
114
+ type: Number,
115
+ required: true,
116
+ min: 0,
117
+ },
118
+ }, { _id: false, minimize: false });
119
+ const ReportSaleTypeMetricSchema = new Schema({
120
+ orders: {
121
+ type: ReportOrderMetricSchema,
122
+ required: true,
123
+ },
124
+ payments: {
125
+ type: [ReportPaymentMetricSchema],
126
+ default: [],
127
+ },
128
+ }, { _id: false, minimize: false });
129
+ const ReportCreditBillSchema = new Schema({
130
+ order_id: {
131
+ type: String,
132
+ required: true,
133
+ },
134
+ payment_id: {
135
+ type: String,
136
+ required: true,
137
+ },
138
+ amount: {
139
+ type: Number, // cents — the bill's amount at issue
140
+ required: true,
141
+ },
142
+ // Cumulative amount received against this bill so far (0 while unpaid;
143
+ // less than `amount` while partially paid). Replaces the old `is_settled`
144
+ // flag: the bill is settled when `received_amount >= amount` (`settled_at`
145
+ // is stamped by the collection patch). Never an event delta, so patches
146
+ // stay idempotent.
147
+ received_amount: {
148
+ type: Number,
149
+ required: true,
150
+ default: 0,
151
+ },
152
+ credit_note: {
153
+ type: String, // optional note/reference recorded with the collection
154
+ default: null,
155
+ },
156
+ issued_at: {
157
+ type: Schema.Types.Date,
158
+ required: true,
159
+ },
160
+ // Stamped when the bill is fully collected (received_amount >= amount).
161
+ settled_at: {
162
+ type: Schema.Types.Date,
163
+ default: null,
164
+ },
165
+ }, { _id: false, minimize: false });
166
+ const ReportReceivedCreditBillSchema = new Schema({
167
+ order_id: {
168
+ type: String,
169
+ required: true,
170
+ },
171
+ payment_id: {
172
+ type: String,
173
+ required: true,
174
+ },
175
+ amount: {
176
+ type: Number, // cents — the bill's amount at issue
177
+ required: true,
178
+ },
179
+ // Cumulative amount received for this bill as of the collection compile
180
+ // (≤ `amount` while partially paid; reaches `amount` when fully collected).
181
+ received_amount: {
182
+ type: Number,
183
+ required: true,
184
+ },
185
+ credit_note: {
186
+ type: String, // optional note/reference recorded with the collection
187
+ default: null,
188
+ },
189
+ issued_local_date: {
190
+ type: String, // 'YYYY-MM-DD' — the sale's day (bill issue day)
191
+ required: true,
192
+ },
193
+ // Collection timestamp (`order_settled_at`) when known — stamped onto the
194
+ // issue-day bill's `settled_at` by the collection patch.
195
+ settled_at: {
196
+ type: Schema.Types.Date,
197
+ default: null,
198
+ },
199
+ }, { _id: false, minimize: false });
200
+ const ReportCreditBillsSchema = new Schema({
201
+ issued: {
202
+ count: {
203
+ type: Number,
204
+ required: true,
205
+ min: 0,
206
+ default: 0,
207
+ },
208
+ amount: {
209
+ type: Number,
210
+ required: true,
211
+ default: 0,
212
+ },
213
+ // How much of the issued bills has been collected since — patched on
214
+ // settlement (tracking only; the money is counted on the collection day).
215
+ settled_count: {
216
+ type: Number,
217
+ required: true,
218
+ min: 0,
219
+ default: 0,
220
+ },
221
+ settled_amount: {
222
+ type: Number,
223
+ required: true,
224
+ default: 0,
225
+ },
226
+ bills: {
227
+ type: [ReportCreditBillSchema],
228
+ default: [],
229
+ },
230
+ },
231
+ received: {
232
+ count: {
233
+ type: Number,
234
+ required: true,
235
+ min: 0,
236
+ default: 0,
237
+ },
238
+ amount: {
239
+ type: Number,
240
+ required: true,
241
+ default: 0,
242
+ },
243
+ bills: {
244
+ type: [ReportReceivedCreditBillSchema],
245
+ default: [],
246
+ },
247
+ },
248
+ }, { _id: false, minimize: false });
249
+ // Credit bills carry the PAY_LATER ledger (issued + settled tracking /
250
+ // received) — report views (including the Credit Bills sale-type numbers) are
251
+ // derived by the frontend formatter, not stored separately.
252
+ const ReportKeyMetricsSchema = new Schema({
253
+ [REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: {
254
+ type: ReportSaleTypeMetricSchema,
255
+ required: true,
256
+ },
257
+ [REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: {
258
+ type: ReportSaleTypeMetricSchema,
259
+ required: true,
260
+ },
261
+ [REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: {
262
+ type: ReportCreditBillsSchema,
263
+ required: true,
264
+ default: () => ({
265
+ issued: { count: 0, amount: 0, settled_count: 0, settled_amount: 0, bills: [] },
266
+ received: { count: 0, amount: 0, bills: [] },
267
+ }),
268
+ },
269
+ }, { _id: false, minimize: false });
270
+ export const MaterializedTenantSalesOverviewReportSchema = new Schema({
271
+ _id: {
272
+ type: Schema.Types.ObjectId,
273
+ required: true,
274
+ immutable: true,
275
+ },
276
+ tenant_id: {
277
+ type: String,
278
+ required: true,
279
+ immutable: true,
280
+ ref: 'tenants',
281
+ },
282
+ brand_id: {
283
+ type: String,
284
+ required: true,
285
+ },
286
+ scope_context: {
287
+ type: String,
288
+ enum: ALL_MATERIALIZED_REPORT_SCOPES,
289
+ required: true,
290
+ },
291
+ scope_field: {
292
+ type: String, // format depends on scope_context — see MATERIALIZED_REPORT_SCOPE_ENUM
293
+ required: true,
294
+ },
295
+ // Denormalized weekday of scope_field — set ONLY on LOCAL_HOUR /
296
+ // LOCAL_DATE documents (MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX);
297
+ // null elsewhere. Weekday analysis reads date/hour slices instead of an
298
+ // all-time accumulator document (see MATERIALIZED_REPORTS.md).
299
+ day_index: {
300
+ type: String,
301
+ enum: ALL_DAY_INDEX,
302
+ default: null,
303
+ },
304
+ sale_type_key_filters: {
305
+ type: [String],
306
+ enum: ALL_MATERIALIZED_REPORT_KEY_FILTERS,
307
+ required: true,
308
+ default: () => [...SALES_OVERVIEW_KEY_FILTERS],
309
+ },
310
+ // Map key = the ordered filter combination, e.g. "PLACED:POS_WALK-IN" —
311
+ // the grammar is declared by `sale_type_key_filters` and must be built /
312
+ // parsed through the shared key helper, never ad hoc.
313
+ sale_type_metrics: {
314
+ type: Map,
315
+ of: ReportKeyMetricsSchema,
316
+ required: true,
317
+ default: {},
318
+ },
319
+ // Versioned writes: bumped by `updateMaterializedTenantSalesOverviewReport`
320
+ // on metric changes (replacement / period deltas) AND on received-payment
321
+ // patches that change the ledger; 1 = first materialization. Every bump is
322
+ // recorded in the shared `materialized_tenant_reports_iterations` history
323
+ // (full post-write snapshot + reason) — this document carries no embedded
324
+ // snapshot.
325
+ iteration: {
326
+ type: Number,
327
+ required: true,
328
+ min: 1,
329
+ default: 1,
330
+ },
331
+ schema_version: {
332
+ type: Number,
333
+ required: true,
334
+ immutable: true,
335
+ default: MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION,
336
+ },
337
+ source_watermark: {
338
+ type: Schema.Types.Date,
339
+ required: true,
340
+ },
341
+ computed_at: {
342
+ type: Schema.Types.Date,
343
+ required: true,
344
+ },
345
+ createdAt: {
346
+ type: Schema.Types.Date,
347
+ required: true,
348
+ default: () => new Date(),
349
+ immutable: true,
350
+ },
351
+ updatedAt: {
352
+ type: Schema.Types.Date,
353
+ required: true,
354
+ default: () => new Date(),
355
+ },
356
+ }, {
357
+ timestamps: true,
358
+ versionKey: false,
359
+ minimize: false,
360
+ });
361
+ export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = 'materialized_tenant_sales_overview_reports';
362
+ /**
363
+ * Describes the indexes for `materialized_tenant_sales_overview_reports`.
364
+ * Values are Mongo key patterns that can be passed straight to `.hint()`.
365
+ * - `_id`: unique primary key.
366
+ * - `tenant_id__scope_context__scope_field`: UNIQUE index — one document per
367
+ * (tenant, scope context, scope value); also serves the standardized query
368
+ * (`tenant_id` + `scope_context` + `scope_field`).
369
+ * - `brand_id__scope_context__scope_field`: brand-level reads across the
370
+ * brand's tenants (sum across their tenant documents).
371
+ * - `tenant_id__scope_context__day_index__scope_field` (+ brand variant):
372
+ * weekday queries over LOCAL_HOUR / LOCAL_DATE slices
373
+ * (`day_index` + `scope_field` range).
374
+ */
375
+ export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = {
376
+ _id: { _id: 1 }, // Unique Index
377
+ tenant_id__scope_context__scope_field: {
378
+ tenant_id: 1,
379
+ scope_context: 1,
380
+ scope_field: 1,
381
+ }, // unique — one document per (tenant, scope context, scope value)
382
+ brand_id__scope_context__scope_field: {
383
+ brand_id: 1,
384
+ scope_context: 1,
385
+ scope_field: 1,
386
+ }, // brand-level reads across the brand's tenants
387
+ tenant_id__scope_context__scope_field__day_index: {
388
+ tenant_id: 1,
389
+ scope_context: 1,
390
+ scope_field: 1,
391
+ day_index: 1,
392
+ }, // weekday queries over LOCAL_HOUR / LOCAL_DATE slices
393
+ brand_id__scope_context__scope_field__day_index: {
394
+ brand_id: 1,
395
+ scope_context: 1,
396
+ scope_field: 1,
397
+ day_index: 1,
398
+ }, // brand-level weekday queries over LOCAL_HOUR / LOCAL_DATE slices
399
+ };
@@ -0,0 +1 @@
1
+ import { REPORT_SALE_TYPE_ENUM } from '../../constants';