diff --git a/src/pages/api/inventory.ts b/src/pages/api/inventory.ts index ee0d6a4..9d814fc 100644 --- a/src/pages/api/inventory.ts +++ b/src/pages/api/inventory.ts @@ -138,14 +138,20 @@ const removeFromInventory = async (inventoryId: string) => { await client.collections('inventories').documents(inventoryId).delete(); } -const updateInventory = async (inventoryId: string, quantity: number, purchasePrice: number, note: string) => { +const updateInventory = async (inventoryId: string, quantity: number, purchasePrice: number, note: string, catalogName: string) => { // Update the database await db.update(inventory).set({ quantity: quantity, purchasePrice: purchasePrice.toFixed(2), note: note, + catalogName: catalogName, }).where(eq(inventory.inventoryId, inventoryId)); - // No need to update Typesense since we don't search by quantity or price + // Quantity/price/note aren't searched, but catalogName is faceted in Typesense. + try { + await client.collections('inventories').documents(inventoryId).update({ catalogName }); + } catch (error) { + console.error('Error updating inventory catalog in Typesense:', error); + } } export const POST: APIRoute = async ({ request, locals }) => { @@ -183,7 +189,8 @@ export const POST: APIRoute = async ({ request, locals }) => { const qty = Number(formData.get('quantity')) || 1; const price = Number(formData.get('purchasePrice')) || 0; const invNote = formData.get('note')?.toString() || ''; - await updateInventory(invId, qty, price, invNote); + const invCatalog = formData.get('catalogName')?.toString() || 'Default'; + await updateInventory(invId, qty, price, invNote, invCatalog); break; default: diff --git a/src/pages/dashboard.astro b/src/pages/dashboard.astro index e270742..211915b 100644 --- a/src/pages/dashboard.astro +++ b/src/pages/dashboard.astro @@ -253,6 +253,13 @@ const totalGain = summary.totalGain || 0; + + + + +