@teincfood/core 0.7.3 → 0.7.4
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/dist/reference/service.js +36 -3
- package/package.json +1 -1
|
@@ -156,10 +156,43 @@ class ReferenceSyncService {
|
|
|
156
156
|
async fetchFallback(key, businessId) {
|
|
157
157
|
switch (key) {
|
|
158
158
|
case "menu:items": {
|
|
159
|
-
|
|
159
|
+
// Paginate through all pages so offline cache is complete — not just page 1 (20).
|
|
160
|
+
// Safety cap 50 pages (~1000 items) to avoid runaway on misconfigured backend.
|
|
161
|
+
const allItems = [];
|
|
162
|
+
let page = 1;
|
|
163
|
+
let lastPagination = null;
|
|
164
|
+
while (true) {
|
|
165
|
+
const response = (await menuService.fetchBusinessMenuItems(businessId, page));
|
|
166
|
+
allItems.push(...(response.data ?? []));
|
|
167
|
+
lastPagination = response.pagination;
|
|
168
|
+
if (!lastPagination ||
|
|
169
|
+
lastPagination.page >= lastPagination.total_pages ||
|
|
170
|
+
(response.data ?? []).length === 0)
|
|
171
|
+
break;
|
|
172
|
+
page += 1;
|
|
173
|
+
if (page > 50)
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
const merged = {
|
|
177
|
+
data: allItems,
|
|
178
|
+
pagination: lastPagination
|
|
179
|
+
? {
|
|
180
|
+
...lastPagination,
|
|
181
|
+
page: 1,
|
|
182
|
+
page_size: allItems.length,
|
|
183
|
+
total_pages: 1,
|
|
184
|
+
total_entries: allItems.length,
|
|
185
|
+
}
|
|
186
|
+
: {
|
|
187
|
+
page: 1,
|
|
188
|
+
page_size: allItems.length,
|
|
189
|
+
total_pages: 1,
|
|
190
|
+
total_entries: allItems.length,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
160
193
|
return {
|
|
161
|
-
payload:
|
|
162
|
-
version: this.hashPayload(
|
|
194
|
+
payload: merged,
|
|
195
|
+
version: this.hashPayload(merged),
|
|
163
196
|
};
|
|
164
197
|
}
|
|
165
198
|
case "menu:categories": {
|
package/package.json
CHANGED