@managesome/eposmatic-toolkit 0.4.14 → 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +162 -0
- package/esm/helpers/reporting-contract/report-contract.js +1 -0
- package/esm/schemas/models/index.js +1 -1
- package/esm/schemas/models/materialized_report_drilldown_rows.js +155 -0
- package/esm/schemas/types/index.js +1 -1
- package/esm/schemas/types/materialized_report_drilldown_rows.js +10 -0
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.d.ts +40 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +169 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +3 -0
- package/lib/helpers/reporting-contract/report-contract.js +1 -0
- package/lib/schemas/models/brands.d.ts +6 -6
- package/lib/schemas/models/categories.d.ts +6 -6
- package/lib/schemas/models/close_dates.d.ts +3 -3
- package/lib/schemas/models/courses.d.ts +3 -3
- package/lib/schemas/models/customer_redemptions.d.ts +3 -3
- package/lib/schemas/models/customers.d.ts +6 -6
- package/lib/schemas/models/deliveries.d.ts +9 -9
- package/lib/schemas/models/delivery_areas.d.ts +3 -3
- package/lib/schemas/models/dinein_floors.d.ts +3 -3
- package/lib/schemas/models/dinein_tables.d.ts +6 -6
- package/lib/schemas/models/dinein_tables_fingerprints.d.ts +9 -9
- package/lib/schemas/models/discounts.d.ts +27 -27
- package/lib/schemas/models/expense_categories.d.ts +3 -3
- package/lib/schemas/models/expense_details.d.ts +12 -12
- package/lib/schemas/models/gift_cards.d.ts +3 -3
- package/lib/schemas/models/halfhalf_setup.d.ts +153 -153
- package/lib/schemas/models/index.d.ts +1 -1
- package/lib/schemas/models/index.js +1 -1
- package/lib/schemas/models/internal_invoices.d.ts +3 -3
- package/lib/schemas/models/internal_staffs.d.ts +3 -3
- package/lib/schemas/models/inventories.d.ts +6 -6
- package/lib/schemas/models/inventory_categories.d.ts +3 -3
- package/lib/schemas/models/inventory_transactions.d.ts +9 -9
- package/lib/schemas/models/item_transactions.d.ts +9 -9
- package/lib/schemas/models/items.d.ts +216 -216
- package/lib/schemas/models/marketing_fingerprints.d.ts +9 -9
- package/lib/schemas/models/materialized_credit_bills.d.ts +21 -21
- package/lib/schemas/models/materialized_report_drilldown_rows.d.ts +130 -0
- package/lib/schemas/models/materialized_report_drilldown_rows.js +158 -0
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +24 -24
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +12 -12
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +3 -3
- package/lib/schemas/models/menus.d.ts +21 -21
- package/lib/schemas/models/modifier_extras.d.ts +3 -3
- package/lib/schemas/models/offers.d.ts +24 -24
- package/lib/schemas/models/offers_fingerprints.d.ts +9 -9
- package/lib/schemas/models/operational_roles.d.ts +3 -3
- package/lib/schemas/models/orders.d.ts +18 -18
- package/lib/schemas/models/printer_settings.d.ts +3 -3
- package/lib/schemas/models/public_holidays.d.ts +3 -3
- package/lib/schemas/models/reservations.d.ts +6 -6
- package/lib/schemas/models/reviews.d.ts +12 -12
- package/lib/schemas/models/riders.d.ts +3 -3
- package/lib/schemas/models/specials.d.ts +48 -48
- package/lib/schemas/models/staff_shifts.d.ts +9 -9
- package/lib/schemas/models/tenant-activity-logs.d.ts +3 -3
- package/lib/schemas/models/tenant_active_jobs.d.ts +3 -3
- package/lib/schemas/models/tenant_calendar.d.ts +3 -3
- package/lib/schemas/models/tenant_cash_drawer_sessions.d.ts +36 -36
- package/lib/schemas/models/tenant_cash_drawers.d.ts +3 -3
- package/lib/schemas/models/tenant_cash_in_hand_transactions.d.ts +9 -9
- package/lib/schemas/models/tenant_cash_in_out.d.ts +9 -9
- package/lib/schemas/models/tenant_clients.d.ts +3 -3
- package/lib/schemas/models/tenant_day_sessions.d.ts +36 -36
- package/lib/schemas/models/tenant_hr_attendance_records.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_biometric_enrollments.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_departments.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_employees.d.ts +24 -24
- package/lib/schemas/models/tenant_hr_leave_requests.d.ts +6 -6
- package/lib/schemas/models/tenant_hr_payrolls.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_performance_reviews.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_policies.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_positions.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_shift_schedules.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_shifts.d.ts +3 -3
- package/lib/schemas/models/tenant_instore_shift_sessions.d.ts +36 -36
- package/lib/schemas/models/tenant_instore_shifts.d.ts +3 -3
- package/lib/schemas/models/tenant_inventory_department_transactions.d.ts +9 -9
- package/lib/schemas/models/tenant_inventory_department_utilities.d.ts +6 -6
- package/lib/schemas/models/tenant_inventory_departments.d.ts +6 -6
- package/lib/schemas/models/tenant_inventory_entries.d.ts +3 -3
- package/lib/schemas/models/tenant_metadata.d.ts +3 -3
- package/lib/schemas/models/tenant_order_item_instructions.d.ts +3 -3
- package/lib/schemas/models/tenant_purchase_order_vendor_returns.d.ts +6 -6
- package/lib/schemas/models/tenant_purchase_orders.d.ts +6 -6
- package/lib/schemas/models/tenant_shifts.d.ts +3 -3
- package/lib/schemas/models/tenant_staffs.d.ts +24 -24
- package/lib/schemas/models/tenant_vendors.d.ts +3 -3
- package/lib/schemas/models/tenants.d.ts +3 -3
- package/lib/schemas/models/terminal_devices.d.ts +3 -3
- package/lib/schemas/models/tokens.d.ts +9 -9
- package/lib/schemas/models/void_order_items.d.ts +27 -27
- package/lib/schemas/models/vouchers.d.ts +3 -3
- package/lib/schemas/models/wallet_transactions.d.ts +9 -9
- package/lib/schemas/models/wallets.d.ts +3 -3
- package/lib/schemas/models/warehouse_categories.d.ts +3 -3
- package/lib/schemas/models/warehouse_communications.d.ts +3 -3
- package/lib/schemas/models/warehouse_inventory_transactions.d.ts +6 -6
- package/lib/schemas/models/warehouse_item_transactions.d.ts +6 -6
- package/lib/schemas/models/warehouse_items.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_rfqs.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_deliveries.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_order_rfqs.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_orders.d.ts +3 -3
- package/lib/schemas/models/warehouse_staffs.d.ts +3 -3
- package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +21 -21
- package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +21 -21
- package/lib/schemas/models/warehouses.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +1 -1
- package/lib/schemas/types/index.js +1 -1
- package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +64 -0
- package/lib/schemas/types/materialized_report_drilldown_rows.js +13 -0
- package/lib/tests/materialized-reports/materialized-report-drilldown-rows.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-report-drilldown-rows.test.js +143 -0
- package/lib/tests/reporting-contract.test.js +7 -0
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ export * from './materialized-cash-compile-helpers';
|
|
|
21
21
|
export * from './materialized-prep-time-classification-helpers';
|
|
22
22
|
export * from './materialized-prep-time-close-day-helpers';
|
|
23
23
|
export * from './materialized-prep-time-compile-helpers';
|
|
24
|
+
export * from './materialized-report-drilldown-rows';
|
|
24
25
|
export * from './materialized-reports-read-helpers';
|
|
25
26
|
export * from './materialized-reports-scope-group-helpers';
|
|
26
27
|
export * from './materialized-reports-selection-helpers';
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_TYPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION } from '../../schemas/models/materialized_report_drilldown_rows';
|
|
3
|
+
const asString = (value) => (typeof value === 'string' ? value : value == null ? '' : String(value));
|
|
4
|
+
const toDate = (value) => {
|
|
5
|
+
if (value instanceof Date)
|
|
6
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
7
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
8
|
+
const date = new Date(value);
|
|
9
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
10
|
+
}
|
|
11
|
+
// Demo files are Extended JSON before upload; production docs are Dates.
|
|
12
|
+
if (value != null && typeof value === 'object' && '$date' in value) {
|
|
13
|
+
return toDate(value.$date);
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
const ROW_SPECS = {
|
|
18
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES]: {
|
|
19
|
+
rowsKey: 'discount_entries',
|
|
20
|
+
time: (row) => row.created_at,
|
|
21
|
+
orderId: (row) => row.order_id,
|
|
22
|
+
cursorId: (row) => row.entry_key,
|
|
23
|
+
},
|
|
24
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES]: {
|
|
25
|
+
rowsKey: 'prep_time_entries',
|
|
26
|
+
time: (row) => row.created_at,
|
|
27
|
+
orderId: (row) => row.order_id,
|
|
28
|
+
cursorId: (row) => row.item_id,
|
|
29
|
+
},
|
|
30
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES]: {
|
|
31
|
+
rowsKey: 'cash_entries',
|
|
32
|
+
time: (row) => row.created_at,
|
|
33
|
+
// Cash rows are drawer-ledger rows, not orders.
|
|
34
|
+
orderId: () => '',
|
|
35
|
+
cursorId: (row) => row.cash_in_out_id ?? row.entry_key,
|
|
36
|
+
},
|
|
37
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES]: {
|
|
38
|
+
rowsKey: 'delivery_entries',
|
|
39
|
+
time: (row) => row.delivered_at ?? row.created_at,
|
|
40
|
+
orderId: (row) => row.order_id,
|
|
41
|
+
cursorId: (row) => row.delivery_id,
|
|
42
|
+
},
|
|
43
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES]: {
|
|
44
|
+
rowsKey: 'sales_entries',
|
|
45
|
+
time: (row) => row.time,
|
|
46
|
+
orderId: (row) => row.order_id,
|
|
47
|
+
cursorId: (row) => row.order_id,
|
|
48
|
+
},
|
|
49
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES]: {
|
|
50
|
+
rowsKey: 'sales_entries',
|
|
51
|
+
time: (row) => row.time,
|
|
52
|
+
orderId: (row) => row.order_id,
|
|
53
|
+
cursorId: (row) => row.order_id,
|
|
54
|
+
},
|
|
55
|
+
[MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES]: {
|
|
56
|
+
rowsKey: 'payment_entries',
|
|
57
|
+
time: (row) => row.time,
|
|
58
|
+
orderId: (row) => row.order_id,
|
|
59
|
+
cursorId: (row) => row.payment_id,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/** The nested map key an entry collection uses for its row sections. */
|
|
63
|
+
export const getDrilldownRowsKey = (reportType) => ROW_SPECS[reportType].rowsKey;
|
|
64
|
+
/**
|
|
65
|
+
* Projects one entry document. Rows missing the report's stable identity or a
|
|
66
|
+
* usable time anchor are skipped and counted; the writer can decide whether to
|
|
67
|
+
* fail loudly.
|
|
68
|
+
*/
|
|
69
|
+
export function buildMaterializedDrilldownRows(reportType, document) {
|
|
70
|
+
if (document == null)
|
|
71
|
+
return { rows: [], skipped: 0 };
|
|
72
|
+
const spec = ROW_SPECS[reportType];
|
|
73
|
+
if (spec == null)
|
|
74
|
+
return { rows: [], skipped: 0 };
|
|
75
|
+
const tenantId = asString(document.tenant_id);
|
|
76
|
+
const brandId = asString(document.brand_id);
|
|
77
|
+
const scopeContextRaw = asString(document.scope_context);
|
|
78
|
+
const scopeField = asString(document.scope_field);
|
|
79
|
+
if (tenantId === '' || scopeContextRaw === '' || scopeField === '') {
|
|
80
|
+
return { rows: [], skipped: 0 };
|
|
81
|
+
}
|
|
82
|
+
const scopeContext = scopeContextRaw;
|
|
83
|
+
const sections = document[spec.rowsKey];
|
|
84
|
+
const computedAt = toDate(document.computed_at) ?? new Date();
|
|
85
|
+
const dayIndex = (document.day_index ?? null);
|
|
86
|
+
const rows = [];
|
|
87
|
+
let skipped = 0;
|
|
88
|
+
for (const [key, section] of Object.entries(sections ?? {})) {
|
|
89
|
+
if (section == null || !Array.isArray(section.rows))
|
|
90
|
+
continue;
|
|
91
|
+
for (const raw of section.rows) {
|
|
92
|
+
if (raw == null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
93
|
+
skipped += 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const row = raw;
|
|
97
|
+
const time = toDate(spec.time(row));
|
|
98
|
+
const orderId = asString(spec.orderId(row));
|
|
99
|
+
const cursorId = asString(spec.cursorId(row));
|
|
100
|
+
// Discounts are served only when the row carries its kind; the nested
|
|
101
|
+
// collector applies the same requirement before it can be viewed.
|
|
102
|
+
const kindMissing = reportType === MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES && asString(row.kind) === '';
|
|
103
|
+
const orderMissing = reportType !== MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES && orderId === '';
|
|
104
|
+
if (time == null || cursorId === '' || kindMissing || orderMissing) {
|
|
105
|
+
skipped += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
rows.push({
|
|
109
|
+
tenant_id: tenantId,
|
|
110
|
+
brand_id: brandId,
|
|
111
|
+
report_type: reportType,
|
|
112
|
+
scope_context: scopeContext,
|
|
113
|
+
scope_field: scopeField,
|
|
114
|
+
day_index: dayIndex,
|
|
115
|
+
key: asString(key),
|
|
116
|
+
order_id: orderId,
|
|
117
|
+
cursor_id: cursorId,
|
|
118
|
+
time,
|
|
119
|
+
data: row,
|
|
120
|
+
schema_version: MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
121
|
+
computed_at: computedAt,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { rows, skipped };
|
|
126
|
+
}
|
|
127
|
+
/** Flattens many entry documents of one report (used by backfill/demo). */
|
|
128
|
+
export function buildMaterializedDrilldownRowsFromDocuments(reportType, documents) {
|
|
129
|
+
const rows = [];
|
|
130
|
+
let skipped = 0;
|
|
131
|
+
for (const document of documents ?? []) {
|
|
132
|
+
const result = buildMaterializedDrilldownRows(reportType, document);
|
|
133
|
+
rows.push(...result.rows);
|
|
134
|
+
skipped += result.skipped;
|
|
135
|
+
}
|
|
136
|
+
return { rows, skipped };
|
|
137
|
+
}
|
|
138
|
+
/** Scope metadata (row count + delivery off-app count) for the flat reader. */
|
|
139
|
+
export function buildMaterializedDrilldownScope(reportType, document, rows) {
|
|
140
|
+
if (document == null)
|
|
141
|
+
return null;
|
|
142
|
+
const tenantId = asString(document.tenant_id);
|
|
143
|
+
const scopeContextRaw = asString(document.scope_context);
|
|
144
|
+
const scopeField = asString(document.scope_field);
|
|
145
|
+
if (tenantId === '' || scopeContextRaw === '' || scopeField === '')
|
|
146
|
+
return null;
|
|
147
|
+
const scopeContext = scopeContextRaw;
|
|
148
|
+
const offApp = reportType === MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES
|
|
149
|
+
? Math.max(0, Number(document.off_app_order_count) || 0)
|
|
150
|
+
: 0;
|
|
151
|
+
return {
|
|
152
|
+
tenant_id: tenantId,
|
|
153
|
+
brand_id: asString(document.brand_id),
|
|
154
|
+
report_type: reportType,
|
|
155
|
+
scope_context: scopeContext,
|
|
156
|
+
scope_field: scopeField,
|
|
157
|
+
row_count: rows.length,
|
|
158
|
+
off_app_order_count: offApp,
|
|
159
|
+
schema_version: MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
160
|
+
computed_at: toDate(document.computed_at) ?? new Date(),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -175,6 +175,7 @@ export function buildReportDetailsResponse(input) {
|
|
|
175
175
|
meta: input.meta,
|
|
176
176
|
rows: input.rows,
|
|
177
177
|
next_cursor: input.nextCursor ?? null,
|
|
178
|
+
...(input.offAppOrderCount != null ? { off_app_order_count: input.offAppOrderCount } : {}),
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
export function buildReportAnalyticsResponse(input) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './app_configs';
|
|
2
|
-
export * from './applied_order_discounts';
|
|
3
2
|
export * from './brands';
|
|
4
3
|
export * from './categories';
|
|
5
4
|
export * from './close_dates';
|
|
@@ -38,6 +37,7 @@ export * from './materialized_tenant_cash_reports';
|
|
|
38
37
|
export * from './materialized_tenant_prep_time_entries';
|
|
39
38
|
export * from './materialized_tenant_prep_time_reports';
|
|
40
39
|
export * from './materialized_tenant_reports_iterations';
|
|
40
|
+
export * from './materialized_report_drilldown_rows';
|
|
41
41
|
export * from './materialized_tenant_sales_comparison_entries';
|
|
42
42
|
export * from './materialized_tenant_sales_comparison_reports';
|
|
43
43
|
export * from './materialized_tenant_hourly_comparison_entries';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { ALL_DAY_INDEX } from '../../constants/ENUMS';
|
|
3
|
+
import { ALL_MATERIALIZED_REPORT_SCOPES, MATERIALIZED_REPORT_TYPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
4
|
+
import { ALL_DRILLDOWN_REPORT_TYPES, } from '../types/materialized_report_drilldown_rows';
|
|
5
|
+
/**
|
|
6
|
+
* FLAT drill-down rows and their scope metadata (see the type module).
|
|
7
|
+
*
|
|
8
|
+
* These are READ projections of the nested `*_entries` documents. The writer
|
|
9
|
+
* replaces all rows for one `(tenant, report_type, scope_context, scope_field)`
|
|
10
|
+
* scope after that scope's entry document is written; re-closing a day is
|
|
11
|
+
* therefore idempotent, and a stale scope can be deleted by identity.
|
|
12
|
+
*/
|
|
13
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION = 1;
|
|
14
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME = 'materialized_report_drilldown_rows';
|
|
15
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME = 'materialized_report_drilldown_scopes';
|
|
16
|
+
const ReportTypeEnum = ALL_DRILLDOWN_REPORT_TYPES;
|
|
17
|
+
export const MaterializedReportDrilldownRowSchema = new Schema({
|
|
18
|
+
tenant_id: { type: String, required: true, immutable: true },
|
|
19
|
+
brand_id: { type: String, required: true },
|
|
20
|
+
report_type: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
immutable: true,
|
|
24
|
+
enum: ReportTypeEnum,
|
|
25
|
+
},
|
|
26
|
+
scope_context: {
|
|
27
|
+
type: String,
|
|
28
|
+
required: true,
|
|
29
|
+
immutable: true,
|
|
30
|
+
enum: ALL_MATERIALIZED_REPORT_SCOPES,
|
|
31
|
+
},
|
|
32
|
+
scope_field: { type: String, required: true, immutable: true },
|
|
33
|
+
day_index: { type: String, default: null, enum: [...ALL_DAY_INDEX, null] },
|
|
34
|
+
key: { type: String, required: true },
|
|
35
|
+
// Cash rows are drawer-ledger rows and have no order id; the field is
|
|
36
|
+
// still present (empty) because it is part of the identity/cursor tuple.
|
|
37
|
+
order_id: { type: String, default: '' },
|
|
38
|
+
cursor_id: { type: String, required: true },
|
|
39
|
+
time: { type: Schema.Types.Date, required: true },
|
|
40
|
+
// The original row is polymorphic across reports; the report_type
|
|
41
|
+
// discriminator says which shape it is.
|
|
42
|
+
data: { type: Schema.Types.Mixed, required: true },
|
|
43
|
+
schema_version: {
|
|
44
|
+
type: Number,
|
|
45
|
+
required: true,
|
|
46
|
+
immutable: true,
|
|
47
|
+
default: MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
48
|
+
},
|
|
49
|
+
computed_at: { type: Schema.Types.Date, required: true },
|
|
50
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
51
|
+
export const MaterializedReportDrilldownScopeSchema = new Schema({
|
|
52
|
+
tenant_id: { type: String, required: true, immutable: true },
|
|
53
|
+
brand_id: { type: String, required: true },
|
|
54
|
+
report_type: {
|
|
55
|
+
type: String,
|
|
56
|
+
required: true,
|
|
57
|
+
immutable: true,
|
|
58
|
+
enum: ReportTypeEnum,
|
|
59
|
+
},
|
|
60
|
+
scope_context: {
|
|
61
|
+
type: String,
|
|
62
|
+
required: true,
|
|
63
|
+
immutable: true,
|
|
64
|
+
enum: ALL_MATERIALIZED_REPORT_SCOPES,
|
|
65
|
+
},
|
|
66
|
+
scope_field: { type: String, required: true, immutable: true },
|
|
67
|
+
row_count: { type: Number, required: true, min: 0, default: 0 },
|
|
68
|
+
off_app_order_count: { type: Number, required: true, min: 0, default: 0 },
|
|
69
|
+
schema_version: {
|
|
70
|
+
type: Number,
|
|
71
|
+
required: true,
|
|
72
|
+
immutable: true,
|
|
73
|
+
default: MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
74
|
+
},
|
|
75
|
+
computed_at: { type: Schema.Types.Date, required: true },
|
|
76
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
77
|
+
/**
|
|
78
|
+
* Index keys consumed by the flat reader.
|
|
79
|
+
*
|
|
80
|
+
* `identity` is the write-side upsert/delete key. The two read indexes cover
|
|
81
|
+
* the two cursor orders the reports already expose:
|
|
82
|
+
* - ascending tie-break: discounts/prep/sales/hourly/payments;
|
|
83
|
+
* - descending tie-break: cash/delivery.
|
|
84
|
+
*/
|
|
85
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_INDEXES = {
|
|
86
|
+
_id: { _id: 1 },
|
|
87
|
+
identity: {
|
|
88
|
+
tenant_id: 1,
|
|
89
|
+
report_type: 1,
|
|
90
|
+
scope_context: 1,
|
|
91
|
+
scope_field: 1,
|
|
92
|
+
order_id: 1,
|
|
93
|
+
cursor_id: 1,
|
|
94
|
+
},
|
|
95
|
+
read_asc: {
|
|
96
|
+
tenant_id: 1,
|
|
97
|
+
report_type: 1,
|
|
98
|
+
scope_context: 1,
|
|
99
|
+
scope_field: 1,
|
|
100
|
+
time: -1,
|
|
101
|
+
order_id: 1,
|
|
102
|
+
cursor_id: 1,
|
|
103
|
+
},
|
|
104
|
+
read_desc: {
|
|
105
|
+
tenant_id: 1,
|
|
106
|
+
report_type: 1,
|
|
107
|
+
scope_context: 1,
|
|
108
|
+
scope_field: 1,
|
|
109
|
+
time: -1,
|
|
110
|
+
cursor_id: -1,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS = [
|
|
114
|
+
{
|
|
115
|
+
key: MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_INDEXES.identity,
|
|
116
|
+
name: 'tenant_id__report_type__scope__order_id__cursor_id',
|
|
117
|
+
unique: true,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_INDEXES.read_asc,
|
|
121
|
+
name: 'tenant_id__report_type__scope__time_desc__order_id__cursor_id',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_INDEXES.read_desc,
|
|
125
|
+
name: 'tenant_id__report_type__scope__time_desc__cursor_id_desc',
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_INDEXES = {
|
|
129
|
+
_id: { _id: 1 },
|
|
130
|
+
identity: {
|
|
131
|
+
tenant_id: 1,
|
|
132
|
+
report_type: 1,
|
|
133
|
+
scope_context: 1,
|
|
134
|
+
scope_field: 1,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
export const MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS = [
|
|
138
|
+
{
|
|
139
|
+
key: MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_INDEXES.identity,
|
|
140
|
+
name: 'tenant_id__report_type__scope',
|
|
141
|
+
unique: true,
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
/** The report-type values the flat reader accepts. */
|
|
145
|
+
export const ALL_DRILLDOWN_REPORT_TYPE_VALUES = ALL_DRILLDOWN_REPORT_TYPES;
|
|
146
|
+
/** Kept explicit so the JSON/demo upload can validate a file's report type. */
|
|
147
|
+
export const DRILLDOWN_REPORT_TYPE_BY_ENTRY_COLLECTION = {
|
|
148
|
+
materialized_tenant_discount_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES,
|
|
149
|
+
materialized_tenant_prep_time_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES,
|
|
150
|
+
materialized_tenant_cash_in_out_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES,
|
|
151
|
+
materialized_tenant_delivery_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES,
|
|
152
|
+
materialized_tenant_sales_comparison_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES,
|
|
153
|
+
materialized_tenant_hourly_comparison_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
|
|
154
|
+
materialized_tenant_payments_comparison_entries: MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES,
|
|
155
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './app_configs';
|
|
2
|
-
export * from './applied_order_discounts';
|
|
3
2
|
export * from './brands';
|
|
4
3
|
export * from './categories';
|
|
5
4
|
export * from './close_dates';
|
|
@@ -129,3 +128,4 @@ export * from './materialized_tenant_hourly_comparison_reports';
|
|
|
129
128
|
export * from './materialized_tenant_hourly_comparison_entries';
|
|
130
129
|
export * from './materialized_tenant_payments_comparison_reports';
|
|
131
130
|
export * from './materialized_tenant_payments_comparison_entries';
|
|
131
|
+
export * from './materialized_report_drilldown_rows';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_TYPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
export const ALL_DRILLDOWN_REPORT_TYPES = [
|
|
3
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES,
|
|
4
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES,
|
|
5
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES,
|
|
6
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES,
|
|
7
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES,
|
|
8
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
|
|
9
|
+
MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES,
|
|
10
|
+
];
|
|
@@ -21,6 +21,7 @@ export * from './materialized-cash-compile-helpers';
|
|
|
21
21
|
export * from './materialized-prep-time-classification-helpers';
|
|
22
22
|
export * from './materialized-prep-time-close-day-helpers';
|
|
23
23
|
export * from './materialized-prep-time-compile-helpers';
|
|
24
|
+
export * from './materialized-report-drilldown-rows';
|
|
24
25
|
export * from './materialized-reports-read-helpers';
|
|
25
26
|
export * from './materialized-reports-scope-group-helpers';
|
|
26
27
|
export * from './materialized-reports-selection-helpers';
|
|
@@ -37,6 +37,7 @@ __exportStar(require("./materialized-cash-compile-helpers"), exports);
|
|
|
37
37
|
__exportStar(require("./materialized-prep-time-classification-helpers"), exports);
|
|
38
38
|
__exportStar(require("./materialized-prep-time-close-day-helpers"), exports);
|
|
39
39
|
__exportStar(require("./materialized-prep-time-compile-helpers"), exports);
|
|
40
|
+
__exportStar(require("./materialized-report-drilldown-rows"), exports);
|
|
40
41
|
__exportStar(require("./materialized-reports-read-helpers"), exports);
|
|
41
42
|
__exportStar(require("./materialized-reports-scope-group-helpers"), exports);
|
|
42
43
|
__exportStar(require("./materialized-reports-selection-helpers"), exports);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IMaterializedReportDrilldownRow, IMaterializedReportDrilldownScope, TDrilldownReportType } from '../../schemas/types/materialized_report_drilldown_rows';
|
|
2
|
+
/**
|
|
3
|
+
* Pure projection from one nested entry document to FLAT drill-down rows.
|
|
4
|
+
*
|
|
5
|
+
* This module is write-side only: the close-day writer (workers-service, next
|
|
6
|
+
* session) calls it after persisting an entry document, then replaces the rows
|
|
7
|
+
* for that `(tenant, report_type, scope_context, scope_field)` scope. The read
|
|
8
|
+
* path never flattens nested documents.
|
|
9
|
+
*
|
|
10
|
+
* The row identity is intentionally the SAME tie-break each report's cursor
|
|
11
|
+
* already uses, so the API cursor shape does not change when the read path
|
|
12
|
+
* switches from nested to flat.
|
|
13
|
+
*/
|
|
14
|
+
interface IEntryDocumentLike {
|
|
15
|
+
tenant_id?: unknown;
|
|
16
|
+
brand_id?: unknown;
|
|
17
|
+
scope_context?: unknown;
|
|
18
|
+
scope_field?: unknown;
|
|
19
|
+
day_index?: unknown;
|
|
20
|
+
computed_at?: unknown;
|
|
21
|
+
off_app_order_count?: unknown;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** The nested map key an entry collection uses for its row sections. */
|
|
25
|
+
export declare const getDrilldownRowsKey: (reportType: TDrilldownReportType) => string;
|
|
26
|
+
export interface IBuildDrilldownRowsResult {
|
|
27
|
+
rows: IMaterializedReportDrilldownRow[];
|
|
28
|
+
skipped: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Projects one entry document. Rows missing the report's stable identity or a
|
|
32
|
+
* usable time anchor are skipped and counted; the writer can decide whether to
|
|
33
|
+
* fail loudly.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildMaterializedDrilldownRows(reportType: TDrilldownReportType, document: IEntryDocumentLike | null | undefined): IBuildDrilldownRowsResult;
|
|
36
|
+
/** Flattens many entry documents of one report (used by backfill/demo). */
|
|
37
|
+
export declare function buildMaterializedDrilldownRowsFromDocuments(reportType: TDrilldownReportType, documents: IEntryDocumentLike[] | null | undefined): IBuildDrilldownRowsResult;
|
|
38
|
+
/** Scope metadata (row count + delivery off-app count) for the flat reader. */
|
|
39
|
+
export declare function buildMaterializedDrilldownScope(reportType: TDrilldownReportType, document: IEntryDocumentLike | null | undefined, rows: IMaterializedReportDrilldownRow[]): IMaterializedReportDrilldownScope | null;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDrilldownRowsKey = void 0;
|
|
4
|
+
exports.buildMaterializedDrilldownRows = buildMaterializedDrilldownRows;
|
|
5
|
+
exports.buildMaterializedDrilldownRowsFromDocuments = buildMaterializedDrilldownRowsFromDocuments;
|
|
6
|
+
exports.buildMaterializedDrilldownScope = buildMaterializedDrilldownScope;
|
|
7
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
8
|
+
const materialized_report_drilldown_rows_1 = require("../../schemas/models/materialized_report_drilldown_rows");
|
|
9
|
+
const asString = (value) => (typeof value === 'string' ? value : value == null ? '' : String(value));
|
|
10
|
+
const toDate = (value) => {
|
|
11
|
+
if (value instanceof Date)
|
|
12
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
13
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
14
|
+
const date = new Date(value);
|
|
15
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
16
|
+
}
|
|
17
|
+
// Demo files are Extended JSON before upload; production docs are Dates.
|
|
18
|
+
if (value != null && typeof value === 'object' && '$date' in value) {
|
|
19
|
+
return toDate(value.$date);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
const ROW_SPECS = {
|
|
24
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES]: {
|
|
25
|
+
rowsKey: 'discount_entries',
|
|
26
|
+
time: (row) => row.created_at,
|
|
27
|
+
orderId: (row) => row.order_id,
|
|
28
|
+
cursorId: (row) => row.entry_key,
|
|
29
|
+
},
|
|
30
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES]: {
|
|
31
|
+
rowsKey: 'prep_time_entries',
|
|
32
|
+
time: (row) => row.created_at,
|
|
33
|
+
orderId: (row) => row.order_id,
|
|
34
|
+
cursorId: (row) => row.item_id,
|
|
35
|
+
},
|
|
36
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES]: {
|
|
37
|
+
rowsKey: 'cash_entries',
|
|
38
|
+
time: (row) => row.created_at,
|
|
39
|
+
// Cash rows are drawer-ledger rows, not orders.
|
|
40
|
+
orderId: () => '',
|
|
41
|
+
cursorId: (row) => row.cash_in_out_id ?? row.entry_key,
|
|
42
|
+
},
|
|
43
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES]: {
|
|
44
|
+
rowsKey: 'delivery_entries',
|
|
45
|
+
time: (row) => row.delivered_at ?? row.created_at,
|
|
46
|
+
orderId: (row) => row.order_id,
|
|
47
|
+
cursorId: (row) => row.delivery_id,
|
|
48
|
+
},
|
|
49
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES]: {
|
|
50
|
+
rowsKey: 'sales_entries',
|
|
51
|
+
time: (row) => row.time,
|
|
52
|
+
orderId: (row) => row.order_id,
|
|
53
|
+
cursorId: (row) => row.order_id,
|
|
54
|
+
},
|
|
55
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES]: {
|
|
56
|
+
rowsKey: 'sales_entries',
|
|
57
|
+
time: (row) => row.time,
|
|
58
|
+
orderId: (row) => row.order_id,
|
|
59
|
+
cursorId: (row) => row.order_id,
|
|
60
|
+
},
|
|
61
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES]: {
|
|
62
|
+
rowsKey: 'payment_entries',
|
|
63
|
+
time: (row) => row.time,
|
|
64
|
+
orderId: (row) => row.order_id,
|
|
65
|
+
cursorId: (row) => row.payment_id,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
/** The nested map key an entry collection uses for its row sections. */
|
|
69
|
+
const getDrilldownRowsKey = (reportType) => ROW_SPECS[reportType].rowsKey;
|
|
70
|
+
exports.getDrilldownRowsKey = getDrilldownRowsKey;
|
|
71
|
+
/**
|
|
72
|
+
* Projects one entry document. Rows missing the report's stable identity or a
|
|
73
|
+
* usable time anchor are skipped and counted; the writer can decide whether to
|
|
74
|
+
* fail loudly.
|
|
75
|
+
*/
|
|
76
|
+
function buildMaterializedDrilldownRows(reportType, document) {
|
|
77
|
+
if (document == null)
|
|
78
|
+
return { rows: [], skipped: 0 };
|
|
79
|
+
const spec = ROW_SPECS[reportType];
|
|
80
|
+
if (spec == null)
|
|
81
|
+
return { rows: [], skipped: 0 };
|
|
82
|
+
const tenantId = asString(document.tenant_id);
|
|
83
|
+
const brandId = asString(document.brand_id);
|
|
84
|
+
const scopeContextRaw = asString(document.scope_context);
|
|
85
|
+
const scopeField = asString(document.scope_field);
|
|
86
|
+
if (tenantId === '' || scopeContextRaw === '' || scopeField === '') {
|
|
87
|
+
return { rows: [], skipped: 0 };
|
|
88
|
+
}
|
|
89
|
+
const scopeContext = scopeContextRaw;
|
|
90
|
+
const sections = document[spec.rowsKey];
|
|
91
|
+
const computedAt = toDate(document.computed_at) ?? new Date();
|
|
92
|
+
const dayIndex = (document.day_index ?? null);
|
|
93
|
+
const rows = [];
|
|
94
|
+
let skipped = 0;
|
|
95
|
+
for (const [key, section] of Object.entries(sections ?? {})) {
|
|
96
|
+
if (section == null || !Array.isArray(section.rows))
|
|
97
|
+
continue;
|
|
98
|
+
for (const raw of section.rows) {
|
|
99
|
+
if (raw == null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
100
|
+
skipped += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const row = raw;
|
|
104
|
+
const time = toDate(spec.time(row));
|
|
105
|
+
const orderId = asString(spec.orderId(row));
|
|
106
|
+
const cursorId = asString(spec.cursorId(row));
|
|
107
|
+
// Discounts are served only when the row carries its kind; the nested
|
|
108
|
+
// collector applies the same requirement before it can be viewed.
|
|
109
|
+
const kindMissing = reportType === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES && asString(row.kind) === '';
|
|
110
|
+
const orderMissing = reportType !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES && orderId === '';
|
|
111
|
+
if (time == null || cursorId === '' || kindMissing || orderMissing) {
|
|
112
|
+
skipped += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
rows.push({
|
|
116
|
+
tenant_id: tenantId,
|
|
117
|
+
brand_id: brandId,
|
|
118
|
+
report_type: reportType,
|
|
119
|
+
scope_context: scopeContext,
|
|
120
|
+
scope_field: scopeField,
|
|
121
|
+
day_index: dayIndex,
|
|
122
|
+
key: asString(key),
|
|
123
|
+
order_id: orderId,
|
|
124
|
+
cursor_id: cursorId,
|
|
125
|
+
time,
|
|
126
|
+
data: row,
|
|
127
|
+
schema_version: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
128
|
+
computed_at: computedAt,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { rows, skipped };
|
|
133
|
+
}
|
|
134
|
+
/** Flattens many entry documents of one report (used by backfill/demo). */
|
|
135
|
+
function buildMaterializedDrilldownRowsFromDocuments(reportType, documents) {
|
|
136
|
+
const rows = [];
|
|
137
|
+
let skipped = 0;
|
|
138
|
+
for (const document of documents ?? []) {
|
|
139
|
+
const result = buildMaterializedDrilldownRows(reportType, document);
|
|
140
|
+
rows.push(...result.rows);
|
|
141
|
+
skipped += result.skipped;
|
|
142
|
+
}
|
|
143
|
+
return { rows, skipped };
|
|
144
|
+
}
|
|
145
|
+
/** Scope metadata (row count + delivery off-app count) for the flat reader. */
|
|
146
|
+
function buildMaterializedDrilldownScope(reportType, document, rows) {
|
|
147
|
+
if (document == null)
|
|
148
|
+
return null;
|
|
149
|
+
const tenantId = asString(document.tenant_id);
|
|
150
|
+
const scopeContextRaw = asString(document.scope_context);
|
|
151
|
+
const scopeField = asString(document.scope_field);
|
|
152
|
+
if (tenantId === '' || scopeContextRaw === '' || scopeField === '')
|
|
153
|
+
return null;
|
|
154
|
+
const scopeContext = scopeContextRaw;
|
|
155
|
+
const offApp = reportType === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES
|
|
156
|
+
? Math.max(0, Number(document.off_app_order_count) || 0)
|
|
157
|
+
: 0;
|
|
158
|
+
return {
|
|
159
|
+
tenant_id: tenantId,
|
|
160
|
+
brand_id: asString(document.brand_id),
|
|
161
|
+
report_type: reportType,
|
|
162
|
+
scope_context: scopeContext,
|
|
163
|
+
scope_field: scopeField,
|
|
164
|
+
row_count: rows.length,
|
|
165
|
+
off_app_order_count: offApp,
|
|
166
|
+
schema_version: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_SCHEMA_VERSION,
|
|
167
|
+
computed_at: toDate(document.computed_at) ?? new Date(),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -104,6 +104,8 @@ export interface IReportDetailsResponse<T, TCursor = unknown> {
|
|
|
104
104
|
meta: IReportResponseMeta;
|
|
105
105
|
rows: T[];
|
|
106
106
|
next_cursor: TCursor | null;
|
|
107
|
+
/** Delivery only: orders with no delivery document (OFF_APP view). */
|
|
108
|
+
off_app_order_count?: number;
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
109
111
|
* Analytics response family. Live and historical of the SAME analytics
|
|
@@ -141,6 +143,7 @@ export interface IBuildReportDetailsResponseInput<T, TCursor = unknown> {
|
|
|
141
143
|
meta: IReportResponseMeta | null | undefined;
|
|
142
144
|
rows: T[];
|
|
143
145
|
nextCursor?: TCursor | null;
|
|
146
|
+
offAppOrderCount?: number | null;
|
|
144
147
|
}
|
|
145
148
|
export declare function buildReportDetailsResponse<T, TCursor = unknown>(input: IBuildReportDetailsResponseInput<T, TCursor> | null | undefined): IReportDetailsResponse<T, TCursor> | null;
|
|
146
149
|
export interface IBuildReportAnalyticsResponseInput<T> {
|
|
@@ -186,6 +186,7 @@ function buildReportDetailsResponse(input) {
|
|
|
186
186
|
meta: input.meta,
|
|
187
187
|
rows: input.rows,
|
|
188
188
|
next_cursor: input.nextCursor ?? null,
|
|
189
|
+
...(input.offAppOrderCount != null ? { off_app_order_count: input.offAppOrderCount } : {}),
|
|
189
190
|
};
|
|
190
191
|
}
|
|
191
192
|
function buildReportAnalyticsResponse(input) {
|
|
@@ -10,33 +10,33 @@ export declare const BrandSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
10
10
|
} & {
|
|
11
11
|
_id: string;
|
|
12
12
|
name: string;
|
|
13
|
-
createdAt: NativeDate;
|
|
14
|
-
updatedAt: NativeDate;
|
|
15
13
|
image_url: string;
|
|
16
14
|
multi_tenant_website: string;
|
|
17
15
|
website_display_type: MULTI_TENANT_WEBSITE_TYPE_ENUM;
|
|
16
|
+
createdAt: NativeDate;
|
|
17
|
+
updatedAt: NativeDate;
|
|
18
18
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
19
19
|
createdAt: NativeDate;
|
|
20
20
|
updatedAt: NativeDate;
|
|
21
21
|
} & {
|
|
22
22
|
_id: string;
|
|
23
23
|
name: string;
|
|
24
|
-
createdAt: NativeDate;
|
|
25
|
-
updatedAt: NativeDate;
|
|
26
24
|
image_url: string;
|
|
27
25
|
multi_tenant_website: string;
|
|
28
26
|
website_display_type: MULTI_TENANT_WEBSITE_TYPE_ENUM;
|
|
27
|
+
createdAt: NativeDate;
|
|
28
|
+
updatedAt: NativeDate;
|
|
29
29
|
}>> & import("mongoose").FlatRecord<{
|
|
30
30
|
createdAt: NativeDate;
|
|
31
31
|
updatedAt: NativeDate;
|
|
32
32
|
} & {
|
|
33
33
|
_id: string;
|
|
34
34
|
name: string;
|
|
35
|
-
createdAt: NativeDate;
|
|
36
|
-
updatedAt: NativeDate;
|
|
37
35
|
image_url: string;
|
|
38
36
|
multi_tenant_website: string;
|
|
39
37
|
website_display_type: MULTI_TENANT_WEBSITE_TYPE_ENUM;
|
|
38
|
+
createdAt: NativeDate;
|
|
39
|
+
updatedAt: NativeDate;
|
|
40
40
|
}> & Required<{
|
|
41
41
|
_id: string;
|
|
42
42
|
}> & {
|