@managesome/eposmatic-toolkit 0.4.60 → 0.4.62
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/constants/MATERIALIZED_REPORTS.js +254 -4
- package/esm/constants/TENANT_ENUMS.js +15 -0
- package/esm/constants/WORKER_ENDPOINTS.js +12 -0
- package/esm/helpers/materialized-reports/index.js +8 -0
- package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
- package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
- package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
- package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +7 -1
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
- package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
- package/esm/helpers/reporting-contract/report-contract.js +3 -0
- package/esm/schemas/models/index.js +3 -0
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
- package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
- package/esm/schemas/models/tenant_active_jobs.js +19 -1
- package/esm/schemas/types/index.js +3 -0
- package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
- package/esm/schemas/types/materialized_tenant_report_runs.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +229 -4
- package/lib/constants/MATERIALIZED_REPORTS.js +255 -5
- package/lib/constants/TENANT_ENUMS.d.ts +14 -0
- package/lib/constants/TENANT_ENUMS.js +16 -1
- package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -0
- package/lib/constants/WORKER_ENDPOINTS.js +12 -0
- package/lib/helpers/materialized-reports/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/index.js +8 -0
- package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
- package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +6 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
- package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
- package/lib/helpers/reporting-contract/report-contract.js +3 -0
- package/lib/helpers/types/workers.d.ts +65 -0
- package/lib/schemas/models/index.d.ts +3 -0
- package/lib/schemas/models/index.js +3 -0
- package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
- package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
- package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
- package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
- package/lib/schemas/models/tenant_active_jobs.js +18 -0
- package/lib/schemas/types/index.d.ts +3 -0
- package/lib/schemas/types/index.js +3 -0
- package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
- package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
- package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
- package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
- package/lib/schemas/types/materialized_tenant_report_runs.js +2 -0
- package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
- package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
- package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
- package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
- package/lib/tests/materialized-reports/materialized-report-runs.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +458 -0
- package/package.json +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatMaterializedDineinReport = formatMaterializedDineinReport;
|
|
4
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
|
+
const materialized_dinein_accumulator_helpers_1 = require("./materialized-dinein-accumulator-helpers");
|
|
6
|
+
const materialized_dinein_key_helpers_1 = require("./materialized-dinein-key-helpers");
|
|
7
|
+
const num = (value) => {
|
|
8
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
9
|
+
return Number.isFinite(number) ? number : 0;
|
|
10
|
+
};
|
|
11
|
+
const percent = (numerator, denominator) => {
|
|
12
|
+
if (!Number.isFinite(denominator) || denominator <= 0)
|
|
13
|
+
return null;
|
|
14
|
+
return Math.round((numerator / denominator) * 10000) / 100;
|
|
15
|
+
};
|
|
16
|
+
const ratio = (numerator, denominator, decimals = 2) => {
|
|
17
|
+
if (!Number.isFinite(denominator) || denominator <= 0)
|
|
18
|
+
return null;
|
|
19
|
+
const factor = Math.pow(10, decimals);
|
|
20
|
+
return Math.round((numerator / denominator) * factor) / factor;
|
|
21
|
+
};
|
|
22
|
+
const minutesRatio = (totalMinutes, count) => ratio(totalMinutes, count, 1);
|
|
23
|
+
const summaryOf = (counters) => {
|
|
24
|
+
const paymentTotal = counters.card_amount + counters.cash_amount + counters.other_amount;
|
|
25
|
+
const measuredSessions = counters.occupancy_sessions + counters.fallback_occupancy_sessions;
|
|
26
|
+
return {
|
|
27
|
+
orders: counters.orders,
|
|
28
|
+
completed_orders: counters.completed_orders,
|
|
29
|
+
cancelled_orders: counters.cancelled_orders,
|
|
30
|
+
covers: counters.covers,
|
|
31
|
+
items: counters.items,
|
|
32
|
+
average_ticket: ratio(counters.sales, counters.orders),
|
|
33
|
+
average_covers_per_check: ratio(counters.covers, counters.orders),
|
|
34
|
+
cancelled_rate: percent(counters.cancelled_orders, counters.orders),
|
|
35
|
+
sales: counters.sales,
|
|
36
|
+
discounts: counters.discounts,
|
|
37
|
+
tax: counters.tax,
|
|
38
|
+
tips: counters.tips,
|
|
39
|
+
service_charge_amount: counters.service_charge_amount,
|
|
40
|
+
service_charge_taxable_amount: counters.service_charge_taxable_amount,
|
|
41
|
+
surcharge_amount: counters.surcharge_amount,
|
|
42
|
+
refunds: counters.refunds,
|
|
43
|
+
service_charge_share: percent(counters.service_charge_amount, counters.sales),
|
|
44
|
+
tables_served: counters.tables_served,
|
|
45
|
+
tables_served_distinct: 0,
|
|
46
|
+
tables_truncated: false,
|
|
47
|
+
table_sessions: counters.table_sessions,
|
|
48
|
+
occupancy_minutes_sum: counters.occupancy_minutes_sum,
|
|
49
|
+
occupancy_sessions: counters.occupancy_sessions,
|
|
50
|
+
fallback_occupancy_sessions: counters.fallback_occupancy_sessions,
|
|
51
|
+
average_occupancy_minutes: minutesRatio(counters.occupancy_minutes_sum, measuredSessions),
|
|
52
|
+
split_parents: counters.split_parents,
|
|
53
|
+
split_children: counters.split_children,
|
|
54
|
+
split_checks: counters.split_checks,
|
|
55
|
+
split_sales: counters.split_sales,
|
|
56
|
+
split_type_counts: { ...(counters.split_type_counts ?? {}) },
|
|
57
|
+
split_sales_share: percent(counters.split_sales, counters.sales),
|
|
58
|
+
offline_orders: counters.offline_orders,
|
|
59
|
+
offline_sales: counters.offline_sales,
|
|
60
|
+
offline_sales_share: percent(counters.offline_sales, counters.sales),
|
|
61
|
+
origin_orders: counters.origin_orders,
|
|
62
|
+
origin_sales: counters.origin_sales,
|
|
63
|
+
origin_covers: counters.origin_covers,
|
|
64
|
+
service_charge_orders: counters.service_charge_orders,
|
|
65
|
+
service_charge_percentage_orders: counters.service_charge_percentage_orders,
|
|
66
|
+
service_charge_fixed_orders: counters.service_charge_fixed_orders,
|
|
67
|
+
service_charge_original_price_orders: counters.service_charge_original_price_orders,
|
|
68
|
+
service_charge_rate_counts: { ...(counters.service_charge_rate_counts ?? {}) },
|
|
69
|
+
edited_orders: counters.edited_orders,
|
|
70
|
+
total_edits: counters.total_edits,
|
|
71
|
+
item_additions: counters.item_additions,
|
|
72
|
+
item_removals: counters.item_removals,
|
|
73
|
+
net_item_change: counters.net_item_change,
|
|
74
|
+
edit_rate: percent(counters.edited_orders, counters.orders),
|
|
75
|
+
average_edits_per_check: ratio(counters.total_edits, counters.orders),
|
|
76
|
+
courses_assigned: counters.courses_assigned,
|
|
77
|
+
courses_called: counters.courses_called,
|
|
78
|
+
courses_on_hold: counters.courses_on_hold,
|
|
79
|
+
course_items: counters.course_items,
|
|
80
|
+
course_call_rate: percent(counters.courses_called, counters.courses_assigned),
|
|
81
|
+
card_amount: counters.card_amount,
|
|
82
|
+
cash_amount: counters.cash_amount,
|
|
83
|
+
other_amount: counters.other_amount,
|
|
84
|
+
card_orders: counters.card_orders,
|
|
85
|
+
cash_orders: counters.cash_orders,
|
|
86
|
+
split_tender_orders: counters.split_tender_orders,
|
|
87
|
+
card_share: percent(counters.card_amount, paymentTotal),
|
|
88
|
+
cash_share: percent(counters.cash_amount, paymentTotal),
|
|
89
|
+
other_share: percent(counters.other_amount, paymentTotal),
|
|
90
|
+
rated_orders: counters.rated_orders,
|
|
91
|
+
rating_sum: counters.rating_sum,
|
|
92
|
+
rating_1: counters.rating_1,
|
|
93
|
+
rating_2: counters.rating_2,
|
|
94
|
+
rating_3: counters.rating_3,
|
|
95
|
+
rating_4: counters.rating_4,
|
|
96
|
+
rating_5: counters.rating_5,
|
|
97
|
+
review_count: counters.review_count,
|
|
98
|
+
average_rating: ratio(counters.rating_sum, counters.rated_orders),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const rankDesc = (a, b, keyA, keyB) => b - a || (keyA < keyB ? -1 : keyA > keyB ? 1 : 0);
|
|
102
|
+
/**
|
|
103
|
+
* Formats the report documents of one scope level into the page payload.
|
|
104
|
+
*
|
|
105
|
+
* Accepts the array returned by a live/historical read or a single stored
|
|
106
|
+
* document; it never throws and never mutates its input.
|
|
107
|
+
*/
|
|
108
|
+
function formatMaterializedDineinReport(documents, options = {}) {
|
|
109
|
+
const docs = (documents ?? []).filter((doc) => doc != null);
|
|
110
|
+
const filters = options.filters ?? null;
|
|
111
|
+
const total = (0, materialized_dinein_accumulator_helpers_1.freshMaterializedDineinCounters)();
|
|
112
|
+
const reservations = (0, materialized_dinein_accumulator_helpers_1.freshMaterializedDineinReservationCounters)();
|
|
113
|
+
const tenantIds = new Set();
|
|
114
|
+
const scopes = new Set();
|
|
115
|
+
const upcomingLists = [];
|
|
116
|
+
const editedLists = [];
|
|
117
|
+
for (const doc of docs) {
|
|
118
|
+
if (doc.tenant_id != null)
|
|
119
|
+
tenantIds.add(String(doc.tenant_id));
|
|
120
|
+
scopes.add(`${String(doc.scope_context)}|${String(doc.scope_field)}`);
|
|
121
|
+
for (const [key, block] of Object.entries(doc.dinein_counters ?? {})) {
|
|
122
|
+
if (!(0, materialized_dinein_key_helpers_1.dineinKeyPassesFilters)(key, filters))
|
|
123
|
+
continue;
|
|
124
|
+
(0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinCounters)(total, block);
|
|
125
|
+
}
|
|
126
|
+
// Reservation counters are document-level: never key-filtered.
|
|
127
|
+
(0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinReservationCounters)(reservations, doc.reservation_counters ?? (0, materialized_dinein_accumulator_helpers_1.freshMaterializedDineinReservationCounters)());
|
|
128
|
+
upcomingLists.push(doc.upcoming_reservations ?? null);
|
|
129
|
+
editedLists.push(doc.top_edited_checks ?? null);
|
|
130
|
+
}
|
|
131
|
+
const tables = total.by_table ?? {};
|
|
132
|
+
const namedTables = Object.keys(tables).filter((key) => key !== MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_OTHER_TOKEN);
|
|
133
|
+
const tablesTruncated = tables[MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_OTHER_TOKEN] != null;
|
|
134
|
+
const summary = summaryOf(total);
|
|
135
|
+
summary.tables_served_distinct = namedTables.length;
|
|
136
|
+
summary.tables_truncated = tablesTruncated;
|
|
137
|
+
const byHour = MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS.map((label) => {
|
|
138
|
+
const row = total.by_hour?.[label] ?? { orders: 0, sales: 0, covers: 0 };
|
|
139
|
+
return {
|
|
140
|
+
hour: Number(label),
|
|
141
|
+
label,
|
|
142
|
+
orders: num(row.orders),
|
|
143
|
+
sales: num(row.sales),
|
|
144
|
+
covers: num(row.covers),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
const byOrigin = Object.entries(total.by_origin ?? {})
|
|
148
|
+
.map(([origin, row]) => ({
|
|
149
|
+
origin,
|
|
150
|
+
orders: num(row?.orders),
|
|
151
|
+
sales: num(row?.sales),
|
|
152
|
+
covers: num(row?.covers),
|
|
153
|
+
}))
|
|
154
|
+
.sort((a, b) => rankDesc(a.orders, b.orders, a.origin, b.origin));
|
|
155
|
+
const byTable = Object.entries(tables)
|
|
156
|
+
.map(([key, row]) => ({
|
|
157
|
+
key,
|
|
158
|
+
table_id: String(row?.table_id ?? key),
|
|
159
|
+
table_name: String(row?.table_name ?? ''),
|
|
160
|
+
floor_id: String(row?.floor_id ?? ''),
|
|
161
|
+
orders: num(row?.orders),
|
|
162
|
+
sessions: num(row?.sessions),
|
|
163
|
+
covers: num(row?.covers),
|
|
164
|
+
occupancy_minutes: num(row?.occupancy_minutes),
|
|
165
|
+
sales: num(row?.sales),
|
|
166
|
+
average_occupancy_minutes: minutesRatio(num(row?.occupancy_minutes), num(row?.sessions)),
|
|
167
|
+
}))
|
|
168
|
+
.sort((a, b) => rankDesc(a.sessions + a.orders, b.sessions + b.orders, a.key, b.key));
|
|
169
|
+
const byFloor = Object.entries(total.by_floor ?? {})
|
|
170
|
+
.map(([key, row]) => ({
|
|
171
|
+
key,
|
|
172
|
+
floor_id: String(row?.floor_id ?? key),
|
|
173
|
+
orders: num(row?.orders),
|
|
174
|
+
sessions: num(row?.sessions),
|
|
175
|
+
covers: num(row?.covers),
|
|
176
|
+
occupancy_minutes: num(row?.occupancy_minutes),
|
|
177
|
+
sales: num(row?.sales),
|
|
178
|
+
}))
|
|
179
|
+
.sort((a, b) => rankDesc(a.sessions + a.orders, b.sessions + b.orders, a.key, b.key));
|
|
180
|
+
const byCourse = Object.entries(total.by_course ?? {})
|
|
181
|
+
.map(([key, row]) => ({
|
|
182
|
+
key,
|
|
183
|
+
course_id: String(row?.course_id ?? key),
|
|
184
|
+
name: String(row?.name ?? key),
|
|
185
|
+
assigned: num(row?.assigned),
|
|
186
|
+
called: num(row?.called),
|
|
187
|
+
on_hold: num(row?.on_hold),
|
|
188
|
+
items: num(row?.items),
|
|
189
|
+
call_rate: percent(num(row?.called), num(row?.assigned)),
|
|
190
|
+
}))
|
|
191
|
+
.sort((a, b) => rankDesc(a.assigned, b.assigned, a.key, b.key));
|
|
192
|
+
const breakdownRows = (map) => Object.entries(map ?? {})
|
|
193
|
+
.map(([key, row]) => ({
|
|
194
|
+
key,
|
|
195
|
+
orders: num(row?.orders),
|
|
196
|
+
covers: num(row?.covers),
|
|
197
|
+
sales: num(row?.sales),
|
|
198
|
+
}))
|
|
199
|
+
.sort((a, b) => rankDesc(a.orders, b.orders, a.key, b.key));
|
|
200
|
+
const byStatus = breakdownRows(total.by_status);
|
|
201
|
+
const byPlatform = breakdownRows(total.by_platform);
|
|
202
|
+
const reservationByHour = MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_HOUR_KEYS.map((label) => {
|
|
203
|
+
const row = reservations.by_hour?.[label] ?? { reservations: 0, reservation_covers: 0 };
|
|
204
|
+
return {
|
|
205
|
+
hour: Number(label),
|
|
206
|
+
label,
|
|
207
|
+
reservations: num(row.reservations),
|
|
208
|
+
reservation_covers: num(row.reservation_covers),
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
const byPaymentType = Object.entries(total.by_payment_type ?? {})
|
|
212
|
+
.map(([paymentType, row]) => ({
|
|
213
|
+
payment_type: paymentType,
|
|
214
|
+
amount: num(row?.amount),
|
|
215
|
+
orders: num(row?.orders),
|
|
216
|
+
}))
|
|
217
|
+
.sort((a, b) => rankDesc(a.amount, b.amount, a.payment_type, b.payment_type));
|
|
218
|
+
return {
|
|
219
|
+
tenant_ids: [...tenantIds].sort(),
|
|
220
|
+
summary,
|
|
221
|
+
by_hour: byHour,
|
|
222
|
+
by_origin: byOrigin,
|
|
223
|
+
by_table: byTable,
|
|
224
|
+
by_floor: byFloor,
|
|
225
|
+
by_course: byCourse,
|
|
226
|
+
by_payment_type: byPaymentType,
|
|
227
|
+
by_status: byStatus,
|
|
228
|
+
by_platform: byPlatform,
|
|
229
|
+
reservation_by_hour: reservationByHour,
|
|
230
|
+
upcoming_reservations: (0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinUpcomingReservations)(upcomingLists),
|
|
231
|
+
top_edited_checks: (0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinTopEditedChecks)(editedLists),
|
|
232
|
+
reservations: {
|
|
233
|
+
...reservations,
|
|
234
|
+
average_party_size: ratio(reservations.reservation_covers, reservations.reservations),
|
|
235
|
+
average_lead_minutes: ratio(reservations.reservation_lead_minutes_sum, reservations.reservation_lead_count, 1),
|
|
236
|
+
average_duration_minutes: ratio(reservations.reservation_duration_minutes_sum, reservations.reservation_duration_count, 1),
|
|
237
|
+
},
|
|
238
|
+
scopes: [...scopes].sort().map((identity) => {
|
|
239
|
+
const [scope_context, scope_field] = identity.split('|');
|
|
240
|
+
return { scope_context, scope_field };
|
|
241
|
+
}),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -29,6 +29,7 @@ export declare enum REPORT_KEY_ENUM {
|
|
|
29
29
|
CASH_IN_OUT = "CASH_IN_OUT",
|
|
30
30
|
DELIVERY = "DELIVERY",
|
|
31
31
|
DIALER = "DIALER",
|
|
32
|
+
DINEIN = "DINEIN",
|
|
32
33
|
SALES_COMPARISON = "SALES_COMPARISON",
|
|
33
34
|
HOURLY_COMPARISON = "HOURLY_COMPARISON",
|
|
34
35
|
PAYMENTS_COMPARISON = "PAYMENTS_COMPARISON",
|
|
@@ -42,6 +42,7 @@ var REPORT_KEY_ENUM;
|
|
|
42
42
|
REPORT_KEY_ENUM["CASH_IN_OUT"] = "CASH_IN_OUT";
|
|
43
43
|
REPORT_KEY_ENUM["DELIVERY"] = "DELIVERY";
|
|
44
44
|
REPORT_KEY_ENUM["DIALER"] = "DIALER";
|
|
45
|
+
REPORT_KEY_ENUM["DINEIN"] = "DINEIN";
|
|
45
46
|
REPORT_KEY_ENUM["SALES_COMPARISON"] = "SALES_COMPARISON";
|
|
46
47
|
REPORT_KEY_ENUM["HOURLY_COMPARISON"] = "HOURLY_COMPARISON";
|
|
47
48
|
REPORT_KEY_ENUM["PAYMENTS_COMPARISON"] = "PAYMENTS_COMPARISON";
|
|
@@ -64,6 +65,7 @@ exports.REPORT_ROUTE_SEGMENTS = {
|
|
|
64
65
|
[REPORT_KEY_ENUM.CASH_IN_OUT]: 'cash-in-out',
|
|
65
66
|
[REPORT_KEY_ENUM.DELIVERY]: 'delivery',
|
|
66
67
|
[REPORT_KEY_ENUM.DIALER]: 'dialer',
|
|
68
|
+
[REPORT_KEY_ENUM.DINEIN]: 'dinein',
|
|
67
69
|
[REPORT_KEY_ENUM.SALES_COMPARISON]: 'sales-comparison',
|
|
68
70
|
[REPORT_KEY_ENUM.HOURLY_COMPARISON]: 'hourly-comparison',
|
|
69
71
|
[REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: 'payments-comparison',
|
|
@@ -95,6 +97,7 @@ exports.REPORT_CAPABILITIES = {
|
|
|
95
97
|
[REPORT_KEY_ENUM.CASH_IN_OUT]: { live: true, historical: true, details: true },
|
|
96
98
|
[REPORT_KEY_ENUM.DELIVERY]: { live: true, historical: true, details: true },
|
|
97
99
|
[REPORT_KEY_ENUM.DIALER]: { live: true, historical: true, details: true },
|
|
100
|
+
[REPORT_KEY_ENUM.DINEIN]: { live: true, historical: true, details: true },
|
|
98
101
|
[REPORT_KEY_ENUM.HOURLY_COMPARISON]: { live: true, historical: true, details: true },
|
|
99
102
|
[REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: { live: true, historical: true, details: true },
|
|
100
103
|
[REPORT_KEY_ENUM.CREDIT_BILLS]: { live: false, historical: true, details: true },
|
|
@@ -491,3 +491,68 @@ export interface IWorker_EndTenantDay {
|
|
|
491
491
|
/** The business day being closed (tenant_day_sessions doc id). */
|
|
492
492
|
day_session_id: string;
|
|
493
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* INTERNAL report-scoped retry (one report of one tenant-day).
|
|
496
|
+
*
|
|
497
|
+
* The retry re-runs ONLY `report_key`: it writes that report's documents and
|
|
498
|
+
* that report's readiness, never any other report and never the calendar.
|
|
499
|
+
*/
|
|
500
|
+
export interface IWorker_RetryMaterializedReport {
|
|
501
|
+
tenant_id: string;
|
|
502
|
+
/** Tenant-local business day, `YYYY-MM-DD` of an EXISTING CLOSED session. */
|
|
503
|
+
localDate: string;
|
|
504
|
+
report_key: string;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Answer of the internal retry endpoint (report-scoped, no PII).
|
|
508
|
+
*
|
|
509
|
+
* ASYNC contract: the endpoint validates + acquires the report lease
|
|
510
|
+
* synchronously and starts the retry in the background, so it answers
|
|
511
|
+
* `accepted: true` with `status: RUNNING` (operations maps it to HTTP 202).
|
|
512
|
+
* The terminal outcome lands in the run ledger and is read by polling.
|
|
513
|
+
*/
|
|
514
|
+
export interface IWorker_RetryMaterializedReportResult {
|
|
515
|
+
tenant_id: string;
|
|
516
|
+
localDate: string;
|
|
517
|
+
report_key: string;
|
|
518
|
+
/** Identity of the retry run (its own report-scoped lease token). */
|
|
519
|
+
run_id: string;
|
|
520
|
+
/** `RUNNING` when the retry was accepted. */
|
|
521
|
+
status: string;
|
|
522
|
+
/** True when the retry was accepted and is executing in the background. */
|
|
523
|
+
accepted: boolean;
|
|
524
|
+
/** Latest execution attempts (present once the execution has started). */
|
|
525
|
+
attempts?: number;
|
|
526
|
+
/** Whether readiness was written (only known once the retry finished). */
|
|
527
|
+
readiness_written?: boolean;
|
|
528
|
+
/** Sanitized failure reason; `null` while running / on success. */
|
|
529
|
+
last_error?: string | null;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* INTERNAL stale-run reconciliation (workers-owned).
|
|
533
|
+
*
|
|
534
|
+
* Operations calls it before listing runs / before rejecting a RUNNING retry so
|
|
535
|
+
* a crash-interrupted execution converges instead of looking running forever.
|
|
536
|
+
*/
|
|
537
|
+
export interface IWorker_ReconcileMaterializedReportRuns {
|
|
538
|
+
tenant_id: string;
|
|
539
|
+
/** `YYYY-MM-DD`; omitted = every day of the tenant (bounded by the worker). */
|
|
540
|
+
localDate?: string;
|
|
541
|
+
/** Omitted = every in-flight report of the tenant/day. */
|
|
542
|
+
report_key?: string;
|
|
543
|
+
}
|
|
544
|
+
export interface IWorker_ReconciledMaterializedReportRun {
|
|
545
|
+
localDate: string;
|
|
546
|
+
report_key: string;
|
|
547
|
+
/** What recovery decided: COMMITTED / FAILED (or a no-op reason). */
|
|
548
|
+
status: string;
|
|
549
|
+
from_status: string;
|
|
550
|
+
reason: string;
|
|
551
|
+
}
|
|
552
|
+
export interface IWorker_ReconcileMaterializedReportRunsResult {
|
|
553
|
+
tenant_id: string;
|
|
554
|
+
/** Ordered decisions (empty = nothing to reconcile). */
|
|
555
|
+
reconciled: IWorker_ReconciledMaterializedReportRun[];
|
|
556
|
+
/** Rows inspected but deliberately left untouched (active/fresh/terminal). */
|
|
557
|
+
skipped: IWorker_ReconciledMaterializedReportRun[];
|
|
558
|
+
}
|
|
@@ -40,6 +40,8 @@ export * from './materialized_tenant_discount_entries';
|
|
|
40
40
|
export * from './materialized_tenant_discount_reports';
|
|
41
41
|
export * from './materialized_tenant_dialer_entries';
|
|
42
42
|
export * from './materialized_tenant_dialer_reports';
|
|
43
|
+
export * from './materialized_tenant_dinein_entries';
|
|
44
|
+
export * from './materialized_tenant_dinein_reports';
|
|
43
45
|
export * from './materialized_tenant_discount_sources';
|
|
44
46
|
export * from './materialized_tenant_hourly_comparison_entries';
|
|
45
47
|
export * from './materialized_tenant_hourly_comparison_reports';
|
|
@@ -47,6 +49,7 @@ export * from './materialized_tenant_payments_comparison_entries';
|
|
|
47
49
|
export * from './materialized_tenant_payments_comparison_reports';
|
|
48
50
|
export * from './materialized_tenant_prep_time_entries';
|
|
49
51
|
export * from './materialized_tenant_prep_time_reports';
|
|
52
|
+
export * from './materialized_tenant_report_runs';
|
|
50
53
|
export * from './materialized_tenant_reports_iterations';
|
|
51
54
|
export * from './materialized_tenant_sales_comparison_entries';
|
|
52
55
|
export * from './materialized_tenant_sales_comparison_reports';
|
|
@@ -56,6 +56,8 @@ __exportStar(require("./materialized_tenant_discount_entries"), exports);
|
|
|
56
56
|
__exportStar(require("./materialized_tenant_discount_reports"), exports);
|
|
57
57
|
__exportStar(require("./materialized_tenant_dialer_entries"), exports);
|
|
58
58
|
__exportStar(require("./materialized_tenant_dialer_reports"), exports);
|
|
59
|
+
__exportStar(require("./materialized_tenant_dinein_entries"), exports);
|
|
60
|
+
__exportStar(require("./materialized_tenant_dinein_reports"), exports);
|
|
59
61
|
__exportStar(require("./materialized_tenant_discount_sources"), exports);
|
|
60
62
|
__exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
|
|
61
63
|
__exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
|
|
@@ -63,6 +65,7 @@ __exportStar(require("./materialized_tenant_payments_comparison_entries"), expor
|
|
|
63
65
|
__exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
|
|
64
66
|
__exportStar(require("./materialized_tenant_prep_time_entries"), exports);
|
|
65
67
|
__exportStar(require("./materialized_tenant_prep_time_reports"), exports);
|
|
68
|
+
__exportStar(require("./materialized_tenant_report_runs"), exports);
|
|
66
69
|
__exportStar(require("./materialized_tenant_reports_iterations"), exports);
|
|
67
70
|
__exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
|
|
68
71
|
__exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
|
|
@@ -22,7 +22,7 @@ export declare const MaterializedTenantDayReadinessSchema: Schema<any, import("m
|
|
|
22
22
|
tenant_id: string;
|
|
23
23
|
status: MATERIALIZED_REPORT_READINESS_STATUS_ENUM;
|
|
24
24
|
schema_version: number;
|
|
25
|
-
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER";
|
|
25
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
26
26
|
run_id: string;
|
|
27
27
|
committed_at: NativeDate;
|
|
28
28
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -35,7 +35,7 @@ export declare const MaterializedTenantDayReadinessSchema: Schema<any, import("m
|
|
|
35
35
|
tenant_id: string;
|
|
36
36
|
status: MATERIALIZED_REPORT_READINESS_STATUS_ENUM;
|
|
37
37
|
schema_version: number;
|
|
38
|
-
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER";
|
|
38
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
39
39
|
run_id: string;
|
|
40
40
|
committed_at: NativeDate;
|
|
41
41
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -48,7 +48,7 @@ export declare const MaterializedTenantDayReadinessSchema: Schema<any, import("m
|
|
|
48
48
|
tenant_id: string;
|
|
49
49
|
status: MATERIALIZED_REPORT_READINESS_STATUS_ENUM;
|
|
50
50
|
schema_version: number;
|
|
51
|
-
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER";
|
|
51
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
52
52
|
run_id: string;
|
|
53
53
|
committed_at: NativeDate;
|
|
54
54
|
}> & {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* Mongoose schema for `materialized_tenant_dinein_entries`.
|
|
4
|
+
*
|
|
5
|
+
* `dinein_entries` is `Mixed`: it is a key-addressed map of row sections
|
|
6
|
+
* (`<ORDER_STATUS>:<PLATFORM>` → rows), and the keys ARE the data.
|
|
7
|
+
*
|
|
8
|
+
* The UNIQUE identity includes `page`, exactly like the discount / delivery /
|
|
9
|
+
* dialer page collections: a page-per-source-day design cannot coexist with a
|
|
10
|
+
* unique index that omits `page`, because every period page of a month shares
|
|
11
|
+
* `day_index: null`.
|
|
12
|
+
*/
|
|
13
|
+
/** Document shape version. Bump on a row-shape change + backfill. */
|
|
14
|
+
export declare const MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = 1;
|
|
15
|
+
export declare const MaterializedTenantDineinEntriesSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
16
|
+
timestamps: true;
|
|
17
|
+
versionKey: false;
|
|
18
|
+
minimize: false;
|
|
19
|
+
}, {
|
|
20
|
+
createdAt: NativeDate;
|
|
21
|
+
updatedAt: NativeDate;
|
|
22
|
+
} & {
|
|
23
|
+
createdAt: NativeDate;
|
|
24
|
+
updatedAt: NativeDate;
|
|
25
|
+
brand_id: string;
|
|
26
|
+
tenant_id: string;
|
|
27
|
+
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
28
|
+
iteration: number;
|
|
29
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
30
|
+
scope_field: string;
|
|
31
|
+
schema_version: number;
|
|
32
|
+
source_watermark: NativeDate;
|
|
33
|
+
computed_at: NativeDate;
|
|
34
|
+
page: string;
|
|
35
|
+
dinein_entries: any;
|
|
36
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
37
|
+
createdAt: NativeDate;
|
|
38
|
+
updatedAt: NativeDate;
|
|
39
|
+
} & {
|
|
40
|
+
createdAt: NativeDate;
|
|
41
|
+
updatedAt: NativeDate;
|
|
42
|
+
brand_id: string;
|
|
43
|
+
tenant_id: string;
|
|
44
|
+
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
45
|
+
iteration: number;
|
|
46
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
47
|
+
scope_field: string;
|
|
48
|
+
schema_version: number;
|
|
49
|
+
source_watermark: NativeDate;
|
|
50
|
+
computed_at: NativeDate;
|
|
51
|
+
page: string;
|
|
52
|
+
dinein_entries: any;
|
|
53
|
+
}>> & import("mongoose").FlatRecord<{
|
|
54
|
+
createdAt: NativeDate;
|
|
55
|
+
updatedAt: NativeDate;
|
|
56
|
+
} & {
|
|
57
|
+
createdAt: NativeDate;
|
|
58
|
+
updatedAt: NativeDate;
|
|
59
|
+
brand_id: string;
|
|
60
|
+
tenant_id: string;
|
|
61
|
+
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
62
|
+
iteration: number;
|
|
63
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
64
|
+
scope_field: string;
|
|
65
|
+
schema_version: number;
|
|
66
|
+
source_watermark: NativeDate;
|
|
67
|
+
computed_at: NativeDate;
|
|
68
|
+
page: string;
|
|
69
|
+
dinein_entries: any;
|
|
70
|
+
}> & {
|
|
71
|
+
_id: import("mongoose").Types.ObjectId;
|
|
72
|
+
} & {
|
|
73
|
+
__v: number;
|
|
74
|
+
}>;
|
|
75
|
+
export declare const MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME = "materialized_tenant_dinein_entries";
|
|
76
|
+
/**
|
|
77
|
+
* The single UNIQUE compound identity index (tenant + scope + value + page).
|
|
78
|
+
* Declared ONLY — never applied by this package or the services.
|
|
79
|
+
*/
|
|
80
|
+
export declare const MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_INDEXES: {
|
|
81
|
+
_id: {
|
|
82
|
+
_id: number;
|
|
83
|
+
};
|
|
84
|
+
tenant_id__scope_context__scope_field__page: {
|
|
85
|
+
tenant_id: number;
|
|
86
|
+
scope_context: number;
|
|
87
|
+
scope_field: number;
|
|
88
|
+
page: number;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export declare const MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS: {
|
|
92
|
+
key: {
|
|
93
|
+
tenant_id: number;
|
|
94
|
+
scope_context: number;
|
|
95
|
+
scope_field: number;
|
|
96
|
+
page: number;
|
|
97
|
+
};
|
|
98
|
+
name: string;
|
|
99
|
+
unique: boolean;
|
|
100
|
+
}[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME = exports.MaterializedTenantDineinEntriesSchema = exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
6
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
/**
|
|
8
|
+
* Mongoose schema for `materialized_tenant_dinein_entries`.
|
|
9
|
+
*
|
|
10
|
+
* `dinein_entries` is `Mixed`: it is a key-addressed map of row sections
|
|
11
|
+
* (`<ORDER_STATUS>:<PLATFORM>` → rows), and the keys ARE the data.
|
|
12
|
+
*
|
|
13
|
+
* The UNIQUE identity includes `page`, exactly like the discount / delivery /
|
|
14
|
+
* dialer page collections: a page-per-source-day design cannot coexist with a
|
|
15
|
+
* unique index that omits `page`, because every period page of a month shares
|
|
16
|
+
* `day_index: null`.
|
|
17
|
+
*/
|
|
18
|
+
/** Document shape version. Bump on a row-shape change + backfill. */
|
|
19
|
+
exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = 1;
|
|
20
|
+
exports.MaterializedTenantDineinEntriesSchema = new mongoose_1.Schema({
|
|
21
|
+
tenant_id: { type: String, required: true },
|
|
22
|
+
brand_id: { type: String, required: true },
|
|
23
|
+
scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES },
|
|
24
|
+
scope_field: { type: String, required: true },
|
|
25
|
+
page: { type: String, required: true },
|
|
26
|
+
day_index: { type: String, default: null, enum: [...ENUMS_1.ALL_DAY_INDEX, null] },
|
|
27
|
+
dinein_entries: { type: mongoose_1.Schema.Types.Mixed, required: true, default: null },
|
|
28
|
+
iteration: { type: Number, required: true, min: 1, default: 1 },
|
|
29
|
+
schema_version: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: true,
|
|
32
|
+
immutable: true,
|
|
33
|
+
default: exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION,
|
|
34
|
+
},
|
|
35
|
+
source_watermark: { type: mongoose_1.Schema.Types.Date, required: true },
|
|
36
|
+
computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
|
|
37
|
+
createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
|
|
38
|
+
updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
|
|
39
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
40
|
+
exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME = 'materialized_tenant_dinein_entries';
|
|
41
|
+
/**
|
|
42
|
+
* The single UNIQUE compound identity index (tenant + scope + value + page).
|
|
43
|
+
* Declared ONLY — never applied by this package or the services.
|
|
44
|
+
*/
|
|
45
|
+
exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_INDEXES = {
|
|
46
|
+
_id: { _id: 1 },
|
|
47
|
+
tenant_id__scope_context__scope_field__page: {
|
|
48
|
+
tenant_id: 1,
|
|
49
|
+
scope_context: 1,
|
|
50
|
+
scope_field: 1,
|
|
51
|
+
page: 1,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS = [
|
|
55
|
+
{
|
|
56
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, page: 1 },
|
|
57
|
+
name: 'tenant_id__scope_context__scope_field__page',
|
|
58
|
+
unique: true,
|
|
59
|
+
},
|
|
60
|
+
];
|