feat(pos): load catalog from /api/v1/pos/catalog instead of PB directly

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Dave 2026-08-31 01:42:42 +02:00
parent 7d0d50408c
commit 47f4c73f18

View file

@ -84,24 +84,20 @@ async function loadProducts(){
render();
}
}catch{}
// Then network refresh
// Then network refresh — single call, the API route returns the
// full active catalog (no pagination needed at this catalog size).
try{
await window.pbAuth();
const all = [];
let page = 1;
while(true){
const r = await window.pbFetch(`/api/collections/${cfg.collections.products}/records?perPage=200&page=${page}&sort=description`);
const j = await r.json();
all.push(...j.items);
if(j.page >= j.totalPages) break;
page++;
if(page > 30) break; // hard cap
}
const r = await window.posFetch('/catalog');
if(!r.ok) throw new Error('catalog returned ' + r.status);
const j = await r.json();
const all = (j.items || []).map(p => ({
...p,
description: p.description || p.name,
}));
state.products = all;
state.productsById = new Map(all.map(p=>[p.id,p]));
buildCategories();
render();
// Persist
for(const p of all) await dbPut(STORE_PRODUCTS, p);
}catch(e){
console.warn('Network load failed', e);
@ -113,11 +109,8 @@ async function loadProducts(){
}
async function loadLetterhead(){
try{
const r = await window.pbFetch(`/api/collections/${cfg.collections.letterhead}/records?perPage=1&filter=is_active=true`);
const j = await r.json();
if(j.items && j.items[0]) state.letterhead = j.items[0];
}catch{}
// Letterhead comes from the main app in a later task if needed;
// the receipt already falls back to "WFSALES POS" when absent.
}
function buildCategories(){