Skip to content

Commit 24de28e

Browse files
author
Paul Nyoike
committed
fix: use stock_quantity field to match API schema
1 parent e37c595 commit 24de28e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

static/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ <h2 id="mTitle">—</h2>
896896
if(S.q){ const q=S.q.toLowerCase(); f=f.filter(p=>p.name?.toLowerCase().includes(q)||p.description?.toLowerCase().includes(q)); }
897897
if(S.minP>0) f=f.filter(p=>p.price>=S.minP);
898898
if(S.maxP<99999) f=f.filter(p=>p.price<=S.maxP);
899-
if(S.stockOnly) f=f.filter(p=>p.quantity>0);
899+
if(S.stockOnly) f=f.filter(p=>p.stock_quantity>0);
900900
const[key,dir]=S.sort.split('_');
901901
f.sort((a,b)=>{
902902
let av=key==='name'?a.name?.toLowerCase():key==='price'?a.price:a.quantity;
@@ -932,7 +932,7 @@ <h2 id="mTitle">—</h2>
932932
if(!S.fil.length){ g.innerHTML=emptyHTML(); return; }
933933
g.className='prod-grid'+(S.view==='list'?' list':'');
934934
g.innerHTML=S.fil.map((p,i)=>{
935-
const inStock=p.quantity>0, lv=S.view==='list';
935+
const inStock=p.stock_quantity>0, lv=S.view==='list';
936936
return `<div class="card" onclick="openDetail(${p.id})" style="animation-delay:${Math.min(i*.04,.4)}s">
937937
<div${lv?' class="card-body"':''}>
938938
<div class="card-head">
@@ -943,7 +943,7 @@ <h2 id="mTitle">—</h2>
943943
<div class="card-price"><span class="cur">KES</span>${fmt(p.price)}</div>
944944
</div>
945945
<div class="card-foot">
946-
<div class="card-qty">Qty: <strong>${p.quantity??0}</strong></div>
946+
<div class="card-qty">Qty: <strong>${p.stock_quantity??0}</strong></div>
947947
<div class="card-acts" onclick="event.stopPropagation()">
948948
<button class="btn btn-ghost btn-xs btn-ico" title="Edit" onclick="openEdit(${p.id})">
949949
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
@@ -1038,7 +1038,7 @@ <h3>${t}</h3><p>${m}</p>
10381038
if(!items.length){ res.innerHTML=`<div class="cmd-empty">No products found</div>`; return; }
10391039
res.innerHTML=items.map((p,i)=>`
10401040
<div class="cmd-item${i===S.cmdSel?' sel':''}" onclick="cmdSelect(${p.id})">
1041-
<div class="stock-dot ${p.quantity>0?'in':'out'}" style="margin:0;flex-shrink:0"></div>
1041+
<div class="stock-dot ${p.stock_quantity>0?'in':'out'}" style="margin:0;flex-shrink:0"></div>
10421042
<div>
10431043
<div class="cmd-item-name">${esc(p.name)}</div>
10441044
${p.description?`<div style="font-size:.72rem;color:var(--ghost)">${esc(p.description).slice(0,60)}…</div>`:''}
@@ -1087,7 +1087,7 @@ <h3>${t}</h3><p>${m}</p>
10871087
</div>
10881088
<div class="fg">
10891089
<label class="fl">Quantity *</label>
1090-
<input class="fi" id="fq" type="number" min="0" value="${p.quantity??''}" placeholder="0"/>
1090+
<input class="fi" id="fq" type="number" min="0" value="${p.stock_quantity??''}" placeholder="0"/>
10911091
<span class="ferr" id="eq"></span>
10921092
</div>
10931093
</div>
@@ -1103,7 +1103,7 @@ <h3>${t}</h3><p>${m}</p>
11031103

11041104
function openDetail(id){
11051105
const p=S.all.find(x=>x.id===id); if(!p) return;
1106-
const inS=p.quantity>0;
1106+
const inS=p.stock_quantity>0;
11071107
showModal(p.name,`<div class="modal-body">
11081108
<div class="detail-price"><sup>KES </sup>${fmt(p.price)}</div>
11091109
${p.description?`<p style="color:var(--dim);font-size:.88rem;line-height:1.75">${esc(p.description)}</p>`:''}
@@ -1113,7 +1113,7 @@ <h3>${t}</h3><p>${m}</p>
11131113
<span class="stock-dot ${inS?'in':'out'}" style="margin:0"></span>${inS?'In Stock':'Out of Stock'}
11141114
</span>
11151115
</div>
1116-
<div class="dm-row"><span class="dm-k">Quantity</span><span>${p.quantity??0} units</span></div>
1116+
<div class="dm-row"><span class="dm-k">Quantity</span><span>${p.stock_quantity??0} units</span></div>
11171117
<div class="dm-row"><span class="dm-k">Product ID</span><span style="font-family:'IBM Plex Mono',monospace;font-size:.75rem;color:var(--ghost)">#${p.id}</span></div>
11181118
</div>
11191119
</div>
@@ -1137,7 +1137,7 @@ <h3>${t}</h3><p>${m}</p>
11371137
const btn=document.getElementById('savBtn');
11381138
btn.disabled=true; btn.textContent=id?'Saving…':'Creating…';
11391139
try{
1140-
const body={name,description:desc,price,quantity:qty};
1140+
const body={name,description:desc,price,stock_quantity:qty};
11411141
if(id) await req(`/products/${id}`,{method:'PUT',body:JSON.stringify(body)});
11421142
else await req('/products',{method:'POST',body:JSON.stringify(body)});
11431143
toast('ok',id?`"${name}" updated`:`"${name}" created`);

0 commit comments

Comments
 (0)