@managesome/eposmatic-toolkit 0.4.62 → 0.4.63
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_SCHEMA_VERSIONS.js +17 -0
- package/esm/constants/WORKER_ENDPOINTS.js +2 -2
- package/esm/helpers/materialized-reports/index.js +3 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-document-size.js +2 -2
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/report-compile.js +38 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-bson.js +27 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +3 -22
- package/esm/schemas/models/materialized_credit_bills.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +2 -1
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.d.ts +17 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.js +20 -0
- package/lib/constants/WORKER_ENDPOINTS.d.ts +0 -2
- package/lib/constants/WORKER_ENDPOINTS.js +2 -2
- package/lib/helpers/materialized-reports/index.d.ts +2 -0
- package/lib/helpers/materialized-reports/index.js +26 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-document-size.js +2 -5
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/report-compile.d.ts +38 -0
- package/lib/helpers/materialized-reports/report-compile.js +87 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.d.ts +12 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.js +33 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +1 -12
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -24
- package/lib/schemas/models/materialized_credit_bills.d.ts +29 -46
- package/lib/schemas/models/materialized_credit_bills.js +3 -2
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +6 -6
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dialer_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dialer_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +11 -35
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +3 -2
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +2 -1
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +5 -4
- package/lib/tests/reporting-contract/no-live-transport.test.js +106 -0
- package/package.json +2 -1
- package/lib/helpers/order/payment-collection.d.ts +0 -25
- package/lib/helpers/order/payment-collection.js +0 -51
- package/lib/schemas/models/applied_order_discounts.d.ts +0 -80
- package/lib/schemas/models/applied_order_discounts.js +0 -106
- package/lib/schemas/types/applied_order_discounts.d.ts +0 -22
- package/lib/schemas/types/applied_order_discounts.js +0 -2
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +0 -1
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +0 -1
- package/lib/tests/payment-collection-timestamps.test.d.ts +0 -1
- package/lib/tests/payment-collection-timestamps.test.js +0 -71
- /package/lib/tests/{materialized-reports/analytics-growth-helpers.test.d.ts → reporting-contract/no-live-transport.test.d.ts} +0 -0
|
@@ -24,12 +24,12 @@ export declare const MaterializedTenantPaymentsComparisonReportSchema: Schema<an
|
|
|
24
24
|
tenant_id: string;
|
|
25
25
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
26
26
|
iteration: number;
|
|
27
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
28
|
-
scope_field: string;
|
|
29
|
-
sale_type_key_filters: string[];
|
|
30
27
|
schema_version: number;
|
|
31
28
|
source_watermark: NativeDate;
|
|
32
29
|
computed_at: NativeDate;
|
|
30
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
31
|
+
scope_field: string;
|
|
32
|
+
sale_type_key_filters: string[];
|
|
33
33
|
payment_counters: any;
|
|
34
34
|
payment_counter_rows: any;
|
|
35
35
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -43,12 +43,12 @@ export declare const MaterializedTenantPaymentsComparisonReportSchema: Schema<an
|
|
|
43
43
|
tenant_id: string;
|
|
44
44
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
45
45
|
iteration: number;
|
|
46
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
47
|
-
scope_field: string;
|
|
48
|
-
sale_type_key_filters: string[];
|
|
49
46
|
schema_version: number;
|
|
50
47
|
source_watermark: NativeDate;
|
|
51
48
|
computed_at: NativeDate;
|
|
49
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
50
|
+
scope_field: string;
|
|
51
|
+
sale_type_key_filters: string[];
|
|
52
52
|
payment_counters: any;
|
|
53
53
|
payment_counter_rows: any;
|
|
54
54
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -62,12 +62,12 @@ export declare const MaterializedTenantPaymentsComparisonReportSchema: Schema<an
|
|
|
62
62
|
tenant_id: string;
|
|
63
63
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
64
64
|
iteration: number;
|
|
65
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
66
|
-
scope_field: string;
|
|
67
|
-
sale_type_key_filters: string[];
|
|
68
65
|
schema_version: number;
|
|
69
66
|
source_watermark: NativeDate;
|
|
70
67
|
computed_at: NativeDate;
|
|
68
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
69
|
+
scope_field: string;
|
|
70
|
+
sale_type_key_filters: string[];
|
|
71
71
|
payment_counters: any;
|
|
72
72
|
payment_counter_rows: any;
|
|
73
73
|
}> & Required<{
|
|
@@ -108,12 +108,12 @@ export declare const MaterializedTenantPrepTimeEntriesSchema: Schema<any, import
|
|
|
108
108
|
tenant_id: string;
|
|
109
109
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
110
110
|
iteration: number;
|
|
111
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
112
|
-
scope_field: string;
|
|
113
|
-
sale_type_key_filters: string[];
|
|
114
111
|
schema_version: number;
|
|
115
112
|
source_watermark: NativeDate;
|
|
116
113
|
computed_at: NativeDate;
|
|
114
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
115
|
+
scope_field: string;
|
|
116
|
+
sale_type_key_filters: string[];
|
|
117
117
|
prep_time_entries: any;
|
|
118
118
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
119
119
|
createdAt: NativeDate;
|
|
@@ -125,12 +125,12 @@ export declare const MaterializedTenantPrepTimeEntriesSchema: Schema<any, import
|
|
|
125
125
|
tenant_id: string;
|
|
126
126
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
127
127
|
iteration: number;
|
|
128
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
129
|
-
scope_field: string;
|
|
130
|
-
sale_type_key_filters: string[];
|
|
131
128
|
schema_version: number;
|
|
132
129
|
source_watermark: NativeDate;
|
|
133
130
|
computed_at: NativeDate;
|
|
131
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
132
|
+
scope_field: string;
|
|
133
|
+
sale_type_key_filters: string[];
|
|
134
134
|
prep_time_entries: any;
|
|
135
135
|
}>> & import("mongoose").FlatRecord<{
|
|
136
136
|
createdAt: NativeDate;
|
|
@@ -142,12 +142,12 @@ export declare const MaterializedTenantPrepTimeEntriesSchema: Schema<any, import
|
|
|
142
142
|
tenant_id: string;
|
|
143
143
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
144
144
|
iteration: number;
|
|
145
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
146
|
-
scope_field: string;
|
|
147
|
-
sale_type_key_filters: string[];
|
|
148
145
|
schema_version: number;
|
|
149
146
|
source_watermark: NativeDate;
|
|
150
147
|
computed_at: NativeDate;
|
|
148
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
149
|
+
scope_field: string;
|
|
150
|
+
sale_type_key_filters: string[];
|
|
151
151
|
prep_time_entries: any;
|
|
152
152
|
}> & {
|
|
153
153
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -36,12 +36,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
36
36
|
tenant_id: string;
|
|
37
37
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
38
38
|
iteration: number;
|
|
39
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
40
|
-
scope_field: string;
|
|
41
|
-
sale_type_key_filters: string[];
|
|
42
39
|
schema_version: number;
|
|
43
40
|
source_watermark: NativeDate;
|
|
44
41
|
computed_at: NativeDate;
|
|
42
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
43
|
+
scope_field: string;
|
|
44
|
+
sale_type_key_filters: string[];
|
|
45
45
|
prep_time_counters: any;
|
|
46
46
|
prep_time_counter_rows: any;
|
|
47
47
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -54,12 +54,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
54
54
|
tenant_id: string;
|
|
55
55
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
56
56
|
iteration: number;
|
|
57
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
58
|
-
scope_field: string;
|
|
59
|
-
sale_type_key_filters: string[];
|
|
60
57
|
schema_version: number;
|
|
61
58
|
source_watermark: NativeDate;
|
|
62
59
|
computed_at: NativeDate;
|
|
60
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
61
|
+
scope_field: string;
|
|
62
|
+
sale_type_key_filters: string[];
|
|
63
63
|
prep_time_counters: any;
|
|
64
64
|
prep_time_counter_rows: any;
|
|
65
65
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -72,12 +72,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
72
72
|
tenant_id: string;
|
|
73
73
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
74
74
|
iteration: number;
|
|
75
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
76
|
-
scope_field: string;
|
|
77
|
-
sale_type_key_filters: string[];
|
|
78
75
|
schema_version: number;
|
|
79
76
|
source_watermark: NativeDate;
|
|
80
77
|
computed_at: NativeDate;
|
|
78
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
79
|
+
scope_field: string;
|
|
80
|
+
sale_type_key_filters: string[];
|
|
81
81
|
prep_time_counters: any;
|
|
82
82
|
prep_time_counter_rows: any;
|
|
83
83
|
}> & {
|
|
@@ -63,12 +63,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
63
63
|
tenant_id: string;
|
|
64
64
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
65
65
|
iteration: number;
|
|
66
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
67
|
-
scope_field: string;
|
|
68
|
-
sale_type_key_filters: string[];
|
|
69
66
|
schema_version: number;
|
|
70
67
|
source_watermark: NativeDate;
|
|
71
68
|
computed_at: NativeDate;
|
|
69
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
70
|
+
scope_field: string;
|
|
71
|
+
sale_type_key_filters: string[];
|
|
72
72
|
sales_entries: any;
|
|
73
73
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
74
74
|
createdAt: NativeDate;
|
|
@@ -81,12 +81,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
81
81
|
tenant_id: string;
|
|
82
82
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
83
83
|
iteration: number;
|
|
84
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
85
|
-
scope_field: string;
|
|
86
|
-
sale_type_key_filters: string[];
|
|
87
84
|
schema_version: number;
|
|
88
85
|
source_watermark: NativeDate;
|
|
89
86
|
computed_at: NativeDate;
|
|
87
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
88
|
+
scope_field: string;
|
|
89
|
+
sale_type_key_filters: string[];
|
|
90
90
|
sales_entries: any;
|
|
91
91
|
}>> & import("mongoose").FlatRecord<{
|
|
92
92
|
createdAt: NativeDate;
|
|
@@ -99,12 +99,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
99
99
|
tenant_id: string;
|
|
100
100
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
101
101
|
iteration: number;
|
|
102
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
103
|
-
scope_field: string;
|
|
104
|
-
sale_type_key_filters: string[];
|
|
105
102
|
schema_version: number;
|
|
106
103
|
source_watermark: NativeDate;
|
|
107
104
|
computed_at: NativeDate;
|
|
105
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
106
|
+
scope_field: string;
|
|
107
|
+
sale_type_key_filters: string[];
|
|
108
108
|
sales_entries: any;
|
|
109
109
|
}> & Required<{
|
|
110
110
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -80,12 +80,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
80
80
|
tenant_id: string;
|
|
81
81
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
82
82
|
iteration: number;
|
|
83
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
84
|
-
scope_field: string;
|
|
85
|
-
sale_type_key_filters: string[];
|
|
86
83
|
schema_version: number;
|
|
87
84
|
source_watermark: NativeDate;
|
|
88
85
|
computed_at: NativeDate;
|
|
86
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
87
|
+
scope_field: string;
|
|
88
|
+
sale_type_key_filters: string[];
|
|
89
89
|
sales_counters: any;
|
|
90
90
|
sales_counter_rows: any;
|
|
91
91
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -99,12 +99,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
99
99
|
tenant_id: string;
|
|
100
100
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
101
101
|
iteration: number;
|
|
102
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
103
|
-
scope_field: string;
|
|
104
|
-
sale_type_key_filters: string[];
|
|
105
102
|
schema_version: number;
|
|
106
103
|
source_watermark: NativeDate;
|
|
107
104
|
computed_at: NativeDate;
|
|
105
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
106
|
+
scope_field: string;
|
|
107
|
+
sale_type_key_filters: string[];
|
|
108
108
|
sales_counters: any;
|
|
109
109
|
sales_counter_rows: any;
|
|
110
110
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -118,12 +118,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
118
118
|
tenant_id: string;
|
|
119
119
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
120
120
|
iteration: number;
|
|
121
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
122
|
-
scope_field: string;
|
|
123
|
-
sale_type_key_filters: string[];
|
|
124
121
|
schema_version: number;
|
|
125
122
|
source_watermark: NativeDate;
|
|
126
123
|
computed_at: NativeDate;
|
|
124
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
125
|
+
scope_field: string;
|
|
126
|
+
sale_type_key_filters: string[];
|
|
127
127
|
sales_counters: any;
|
|
128
128
|
sales_counter_rows: any;
|
|
129
129
|
}> & Required<{
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
+
import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
|
|
2
|
+
export { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION };
|
|
1
3
|
import { Schema } from 'mongoose';
|
|
2
|
-
/**
|
|
3
|
-
* Mongoose schema for `materialized_tenant_sales_overview_reports` — the
|
|
4
|
-
* materialized Reports > Overview data (one document per tenant × scope
|
|
5
|
-
* context × scope value), maintained by the day-end materialization job and
|
|
6
|
-
* read by the analytics API. Scope slices are stamped from the order's
|
|
7
|
-
* business day (`order.localDate`); hour buckets use the punch hour for sales
|
|
8
|
-
* and the settlement hour for credit-bill collections (see
|
|
9
|
-
* `MATERIALIZED_REPORTS.md`). The report's time-bias toggle (Punched At /
|
|
10
|
-
* `createdAt`) is out of scope. `scope_field` formats are documented on
|
|
11
|
-
* `MATERIALIZED_REPORT_SCOPE_ENUM` and in `MATERIALIZED_REPORTS.md`.
|
|
12
|
-
* NUMBERS ONLY: credit-bill COUNTERS (issued / settled / received) live in
|
|
13
|
-
* each `sale_type_metrics` key's `CREDIT_BILLS` slot — constant-size numbers.
|
|
14
|
-
* The ITEMIZED ledger (one row per bill + its receipt events) lives in the
|
|
15
|
-
* SHARED `materialized_tenant_credit_bills` collection, so these documents carry no
|
|
16
|
-
* bill rows/ids and their size no longer grows with the ledger over time.
|
|
17
|
-
* Iteration history (every structural write's full post-write snapshot)
|
|
18
|
-
* lives in the shared `materialized_tenant_reports_iterations` collection.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Version of the key grammar + metric rules of this collection. Bump when
|
|
22
|
-
* `sale_type_key_filters`, their order, or metric semantics change —
|
|
23
|
-
* historical documents must then be re-materialized (readers may branch on
|
|
24
|
-
* this value during a rollout). PRE-RELEASE: the collection has no live
|
|
25
|
-
* tenants/consumers yet, so every change so far folds into version `1`.
|
|
26
|
-
*/
|
|
27
|
-
export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
28
4
|
export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
29
5
|
timestamps: true;
|
|
30
6
|
versionKey: false;
|
|
@@ -40,12 +16,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
40
16
|
tenant_id: string;
|
|
41
17
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
42
18
|
iteration: number;
|
|
43
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
44
|
-
scope_field: string;
|
|
45
|
-
sale_type_key_filters: string[];
|
|
46
19
|
schema_version: number;
|
|
47
20
|
source_watermark: NativeDate;
|
|
48
21
|
computed_at: NativeDate;
|
|
22
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
23
|
+
scope_field: string;
|
|
24
|
+
sale_type_key_filters: string[];
|
|
49
25
|
sale_type_metrics: Map<string, {
|
|
50
26
|
TOTAL_SALES: {
|
|
51
27
|
orders: {
|
|
@@ -156,12 +132,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
156
132
|
tenant_id: string;
|
|
157
133
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
158
134
|
iteration: number;
|
|
159
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
160
|
-
scope_field: string;
|
|
161
|
-
sale_type_key_filters: string[];
|
|
162
135
|
schema_version: number;
|
|
163
136
|
source_watermark: NativeDate;
|
|
164
137
|
computed_at: NativeDate;
|
|
138
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
139
|
+
scope_field: string;
|
|
140
|
+
sale_type_key_filters: string[];
|
|
165
141
|
sale_type_metrics: Map<string, {
|
|
166
142
|
TOTAL_SALES: {
|
|
167
143
|
orders: {
|
|
@@ -272,12 +248,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
272
248
|
tenant_id: string;
|
|
273
249
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
274
250
|
iteration: number;
|
|
275
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
276
|
-
scope_field: string;
|
|
277
|
-
sale_type_key_filters: string[];
|
|
278
251
|
schema_version: number;
|
|
279
252
|
source_watermark: NativeDate;
|
|
280
253
|
computed_at: NativeDate;
|
|
254
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
255
|
+
scope_field: string;
|
|
256
|
+
sale_type_key_filters: string[];
|
|
281
257
|
sale_type_metrics: Map<string, {
|
|
282
258
|
TOTAL_SALES: {
|
|
283
259
|
orders: {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = exports.MaterializedTenantSalesOverviewReportSchema = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = void 0;
|
|
4
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
5
|
+
Object.defineProperty(exports, "MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION", { enumerable: true, get: function () { return MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION; } });
|
|
4
6
|
const mongoose_1 = require("mongoose");
|
|
5
7
|
const constants_1 = require("../../constants");
|
|
6
8
|
const ENUMS_1 = require("../../constants/ENUMS");
|
|
@@ -30,7 +32,6 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
30
32
|
* this value during a rollout). PRE-RELEASE: the collection has no live
|
|
31
33
|
* tenants/consumers yet, so every change so far folds into version `1`.
|
|
32
34
|
*/
|
|
33
|
-
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
34
35
|
const ReportDiscountByTypeSchema = new mongoose_1.Schema({
|
|
35
36
|
special_discount: {
|
|
36
37
|
type: Number, // cents — Σ order_discount_details.special_discount
|
|
@@ -261,7 +262,7 @@ exports.MaterializedTenantSalesOverviewReportSchema = new mongoose_1.Schema({
|
|
|
261
262
|
type: Number,
|
|
262
263
|
required: true,
|
|
263
264
|
immutable: true,
|
|
264
|
-
default:
|
|
265
|
+
default: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION,
|
|
265
266
|
},
|
|
266
267
|
source_watermark: {
|
|
267
268
|
type: mongoose_1.Schema.Types.Date,
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const constants_1 = require("../../constants");
|
|
4
4
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
5
|
const tenant_sales_overview_close_day_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-close-day-helpers");
|
|
6
|
+
const tenant_sales_overview_bson_1 = require("../../helpers/materialized-reports/tenant-sales-overview-bson");
|
|
6
7
|
const tenant_sales_overview_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-helpers");
|
|
7
8
|
const materialized_credit_bills_helpers_1 = require("../../helpers/materialized-reports/materialized-credit-bills-helpers");
|
|
8
9
|
/** Narrows helper results that are `null` on invalid data (tests expect valid data). */
|
|
@@ -453,7 +454,7 @@ describe('tenant sales overview close-day plan', () => {
|
|
|
453
454
|
// Real hydration shape: `Model.find()` docs carry the `sale_type_metrics` Map
|
|
454
455
|
// with mongoose subdocument values (NOT plain objects).
|
|
455
456
|
const hydratedStored = world1.docs.map((doc) => doc.scope_context === LOCAL_DATE && doc.scope_field === D1
|
|
456
|
-
? (0,
|
|
457
|
+
? (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(doc).toObject()
|
|
457
458
|
: doc);
|
|
458
459
|
const plan = closeDay(D2, [cashD2, collectedCredit], { docs: hydratedStored, credit: world1.credit }, CT2);
|
|
459
460
|
expect(plan.receivedPatches).toHaveLength(8); // the hydrated D1 date doc is still detected + patched
|
|
@@ -6,6 +6,7 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
6
6
|
const key_helpers_1 = require("../../helpers/materialized-reports/key-helpers");
|
|
7
7
|
const materialized_tenant_reports_iterations_helpers_1 = require("../../helpers/materialized-reports/materialized-tenant-reports-iterations-helpers");
|
|
8
8
|
const scope_helpers_1 = require("../../helpers/materialized-reports/scope-helpers");
|
|
9
|
+
const tenant_sales_overview_bson_1 = require("../../helpers/materialized-reports/tenant-sales-overview-bson");
|
|
9
10
|
const tenant_sales_overview_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-helpers");
|
|
10
11
|
const time_helpers_1 = require("../../helpers/utils/time-helpers");
|
|
11
12
|
const fixtures_1 = require("./fixtures");
|
|
@@ -521,14 +522,14 @@ describe('credit-bill lifecycle (synthetic PAY_LATER orders)', () => {
|
|
|
521
522
|
expect(bareCompile.credit_bill_issues[0]?.issued_at).toEqual(computedAt);
|
|
522
523
|
});
|
|
523
524
|
it('converts the JSON document to a mongoose (BSON) document', () => {
|
|
524
|
-
const hydrated = (0,
|
|
525
|
+
const hydrated = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(issueDateDoc);
|
|
525
526
|
expect(hydrated.get('scope_context')).toBe('localDate');
|
|
526
527
|
expect(hydrated.get('sale_type_metrics')).toBeInstanceOf(Map);
|
|
527
528
|
const metrics = hydrated.get('sale_type_metrics');
|
|
528
529
|
const issued = metrics.get('COMPLETED:POS_WALK-IN')?.[constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS].issued;
|
|
529
530
|
expect(issued?.count).toBe(1);
|
|
530
531
|
expect(issued?.amount).toBe(1200);
|
|
531
|
-
const hydratedCollect = (0,
|
|
532
|
+
const hydratedCollect = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(collectDateDoc);
|
|
532
533
|
const collectedMetrics = hydratedCollect.get('sale_type_metrics');
|
|
533
534
|
const received = collectedMetrics.get('COMPLETED:POS_WALK-IN')?.[constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS].received;
|
|
534
535
|
expect(received?.count).toBe(1);
|
|
@@ -901,11 +902,11 @@ describe('subtract + versioned reconcile (iteration bump)', () => {
|
|
|
901
902
|
});
|
|
902
903
|
// Real hydration shapes: `Model.find()` / json→BSON cast docs carry the Map
|
|
903
904
|
// with mongoose subdocument values; `.toObject()` output keeps them too.
|
|
904
|
-
const hydrated = (0,
|
|
905
|
+
const hydrated = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)({
|
|
905
906
|
...stored,
|
|
906
907
|
_id: '68dd3f9c9f1b2c3d4e5f6a7b',
|
|
907
908
|
}).toObject();
|
|
908
|
-
const hydratedFlattened = (0,
|
|
909
|
+
const hydratedFlattened = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)({
|
|
909
910
|
...stored,
|
|
910
911
|
_id: '68dd3f9c9f1b2c3d4e5f6a7b',
|
|
911
912
|
}).toObject({ flattenMaps: true });
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const WORKER_ENDPOINTS_1 = require("../../constants/WORKER_ENDPOINTS");
|
|
42
|
+
const reportCompile = __importStar(require("../../helpers/materialized-reports/report-compile"));
|
|
43
|
+
/**
|
|
44
|
+
* SHARED CONTRACT SURFACE — after the live-proxy revert and the direct-API move.
|
|
45
|
+
*
|
|
46
|
+
* - no internal live summary/details transport types;
|
|
47
|
+
* - no WORKER_ENDPOINTS entry for the removed live proxy or the catalog reads
|
|
48
|
+
* that items-service owns now;
|
|
49
|
+
* - the pure `report-compile` subpath still exposes the close compilers.
|
|
50
|
+
*
|
|
51
|
+
* The `report-compile` import graph must stay mongoose-free: it is the worker
|
|
52
|
+
* boundary for BOTH services' Piscina compile threads.
|
|
53
|
+
*/
|
|
54
|
+
const root = process.cwd();
|
|
55
|
+
const readSource = (relative) => node_fs_1.default.readFileSync(node_path_1.default.join(root, relative), 'utf8');
|
|
56
|
+
test('the internal live transport module is removed', () => {
|
|
57
|
+
expect(node_fs_1.default.existsSync(node_path_1.default.join(root, 'src/helpers/reporting-contract/live-reports.ts'))).toBe(false);
|
|
58
|
+
const barrel = readSource('src/helpers/reporting-contract/index.ts');
|
|
59
|
+
expect(barrel).not.toContain('live-reports');
|
|
60
|
+
});
|
|
61
|
+
test('no WORKER_ENDPOINTS entry is a live-proxy or moved catalog path', () => {
|
|
62
|
+
const values = Object.values(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS);
|
|
63
|
+
expect(values.some((value) => value.includes('/live'))).toBe(false);
|
|
64
|
+
expect('ITEMS_USING_MODIFIER' in WORKER_ENDPOINTS_1.WORKER_ENDPOINTS).toBe(false);
|
|
65
|
+
expect('AUDIT_ITEM_MODIFIERS' in WORKER_ENDPOINTS_1.WORKER_ENDPOINTS).toBe(false);
|
|
66
|
+
// The endpoints that MUST stay.
|
|
67
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.END_TENANT_DAY).toBe('/end-tenant-day');
|
|
68
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.RETRY_MATERIALIZED_REPORT).toBe('/internal/materialization/reports/retry');
|
|
69
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.RECONCILE_MATERIALIZED_REPORT_RUNS).toBe('/internal/materialization/reports/reconcile');
|
|
70
|
+
});
|
|
71
|
+
test('the pure report-compile subpath still exports the close compilers', () => {
|
|
72
|
+
expect(typeof reportCompile.compileTenantDineinReports).toBe('function');
|
|
73
|
+
expect(typeof reportCompile.compileTenantDiscountReports).toBe('function');
|
|
74
|
+
expect(typeof reportCompile.compileTenantPrepTimeReports).toBe('function');
|
|
75
|
+
expect(typeof reportCompile.compileTenantDialerReports).toBe('function');
|
|
76
|
+
expect(typeof reportCompile.compileTenantDeliveryReports).toBe('function');
|
|
77
|
+
expect(typeof reportCompile.convertOrdersToMaterializedTenantSalesOverviewReports).toBe('function');
|
|
78
|
+
});
|
|
79
|
+
test('the report-compile import graph contains no mongoose or schema model', () => {
|
|
80
|
+
const entry = 'src/helpers/materialized-reports/report-compile.ts';
|
|
81
|
+
const visited = new Set();
|
|
82
|
+
const queue = [entry];
|
|
83
|
+
while (queue.length > 0) {
|
|
84
|
+
const current = queue.shift();
|
|
85
|
+
if (visited.has(current))
|
|
86
|
+
continue;
|
|
87
|
+
visited.add(current);
|
|
88
|
+
const source = readSource(current);
|
|
89
|
+
// Type-only imports are erased by tsc and never load a module.
|
|
90
|
+
const runtimeSource = source
|
|
91
|
+
.replace(/import\s+type\s+[^;]+?from\s*['"][^'"]+['"];?/gs, '')
|
|
92
|
+
.replace(/export\s+type\s+\{[^}]*\}\s*from\s*['"][^'"]+['"];?/gs, '');
|
|
93
|
+
expect(runtimeSource).not.toContain("from 'mongoose'");
|
|
94
|
+
expect(runtimeSource).not.toContain('from "mongoose"');
|
|
95
|
+
for (const match of runtimeSource.matchAll(/(?:from|import)\s*\(?\s*['"](\.[^'"]+)['"]/g)) {
|
|
96
|
+
const candidate = node_path_1.default.posix.normalize(node_path_1.default.posix.join(node_path_1.default.posix.dirname(current), match[1]));
|
|
97
|
+
// Toolkit sources use extensionless specifiers; services use `.js`.
|
|
98
|
+
const asTs = candidate.endsWith('.js') ? candidate.replace(/\.js$/, '.ts') : `${candidate}.ts`;
|
|
99
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(root, asTs)))
|
|
100
|
+
queue.push(asTs);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// The graph is real (not an empty walk) and includes the service-facing API.
|
|
104
|
+
expect(visited.size).toBeGreaterThan(5);
|
|
105
|
+
expect([...visited].some((file) => file.includes('materialized-dinein-'))).toBe(true);
|
|
106
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@managesome/eposmatic-toolkit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.63",
|
|
4
4
|
"description": "A Toolkit Library for Eposmatic",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"test:characterization": "jest --config jestconfig.json src/tests/materialized-reports/characterization --runInBand"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"bson": "^6.10.3",
|
|
35
36
|
"bson-objectid": "^2.0.4",
|
|
36
37
|
"crypto-js": "^4.2.0",
|
|
37
38
|
"emoji-strip": "^1.0.1",
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IOrderPayment } from '../../schemas/types/orders';
|
|
2
|
-
/**
|
|
3
|
-
* Server-owned `collected_at` stamping for order payments.
|
|
4
|
-
*
|
|
5
|
-
* A payment line is the unit a credit bill lives on: the sale is issued on the
|
|
6
|
-
* punch day, and money may arrive later (full or partial). `order_settled_at`
|
|
7
|
-
* only moves on FULL settlement, so it cannot anchor a partial collection.
|
|
8
|
-
* This helper records the LAST collection moment on the payment itself,
|
|
9
|
-
* derived by comparing `amount_paid` with the stored previous version.
|
|
10
|
-
*
|
|
11
|
-
* Rules:
|
|
12
|
-
* - never trust the incoming `collected_at` (clients may send anything);
|
|
13
|
-
* - a NEW payment line with money in (`amount_paid > 0`) gets `now`;
|
|
14
|
-
* - an EXISTING line whose `amount_paid` increased gets `now`;
|
|
15
|
-
* - unchanged / decreased / zero-amount lines keep the stored timestamp
|
|
16
|
-
* (`null` when unknown — legacy rows are not backfilled here).
|
|
17
|
-
*
|
|
18
|
-
* Pure and never throws. `previousPayments` must be the SERVER copy of the
|
|
19
|
-
* order's payments before the write (pass none on create).
|
|
20
|
-
*/
|
|
21
|
-
export interface IStampPaymentCollectionTimestampsOptions {
|
|
22
|
-
/** Override for the collection instant (tests / offline replays). */
|
|
23
|
-
now?: Date | string | null;
|
|
24
|
-
}
|
|
25
|
-
export declare function stampPaymentCollectionTimestamps(payments: IOrderPayment[] | null | undefined, previousPayments?: IOrderPayment[] | null | undefined, options?: IStampPaymentCollectionTimestampsOptions): IOrderPayment[];
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stampPaymentCollectionTimestamps = stampPaymentCollectionTimestamps;
|
|
4
|
-
const constants_1 = require("../../constants");
|
|
5
|
-
const toValidDate = (value) => {
|
|
6
|
-
if (value == null)
|
|
7
|
-
return null;
|
|
8
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
9
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
10
|
-
};
|
|
11
|
-
/** Stable identity across a merge: subdoc `_id` first, then `payment_id`. */
|
|
12
|
-
const identityOf = (payment) => {
|
|
13
|
-
if (payment._id != null && String(payment._id).trim() !== '') {
|
|
14
|
-
return `id:${String(payment._id)}`;
|
|
15
|
-
}
|
|
16
|
-
if (typeof payment.payment_id === 'string' && payment.payment_id.trim() !== '') {
|
|
17
|
-
return `payment:${payment.payment_id}`;
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
};
|
|
21
|
-
function stampPaymentCollectionTimestamps(payments, previousPayments = null, options = {}) {
|
|
22
|
-
if (!Array.isArray(payments))
|
|
23
|
-
return [];
|
|
24
|
-
const now = toValidDate(options.now) ?? new Date();
|
|
25
|
-
const previousByIdentity = new Map();
|
|
26
|
-
for (const previous of Array.isArray(previousPayments) ? previousPayments : []) {
|
|
27
|
-
if (previous == null)
|
|
28
|
-
continue;
|
|
29
|
-
const identity = identityOf(previous);
|
|
30
|
-
if (identity != null)
|
|
31
|
-
previousByIdentity.set(identity, previous);
|
|
32
|
-
}
|
|
33
|
-
return payments.map((payment) => {
|
|
34
|
-
if (payment == null)
|
|
35
|
-
return payment;
|
|
36
|
-
const identity = identityOf(payment);
|
|
37
|
-
const previous = identity != null ? previousByIdentity.get(identity) : undefined;
|
|
38
|
-
const previousCollectedAt = toValidDate(previous?.collected_at);
|
|
39
|
-
const amountPaid = Number(payment.amount_paid ?? 0);
|
|
40
|
-
const previousAmountPaid = Number(previous?.amount_paid ?? 0);
|
|
41
|
-
const isFailed = payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.FAILED;
|
|
42
|
-
const isNewCollection = !isFailed &&
|
|
43
|
-
Number.isFinite(amountPaid) &&
|
|
44
|
-
amountPaid > 0 &&
|
|
45
|
-
(previous == null || amountPaid > previousAmountPaid);
|
|
46
|
-
return {
|
|
47
|
-
...payment,
|
|
48
|
-
collected_at: isNewCollection ? now : previousCollectedAt,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
}
|