feat: kitchen screen, scan dedup, gemini-3.5-flash-lite, seed grapes/beetroot/pea shoots

This commit is contained in:
Sven (AAMOS AI)
2026-08-16 20:13:49 +07:00
parent d098bf705e
commit c0a15bb1b5
20 changed files with 295 additions and 48 deletions
+37
View File
@@ -150,6 +150,43 @@ export async function scanRoutes(app: FastifyInstance) {
if (!locationId)
throw errors.badRequest("storageLocationId saknas och ingen standardplats finns.");
// Dedup (#1): finns varan redan aktiv i hushållet? Uppdatera + hoppa över,
// så överlappande foton / omfotografering inte skapar dubletter.
const dedupCond = item.canonicalIngredientId
? and(
eq(schema.inventoryItems.householdId, householdId),
eq(schema.inventoryItems.canonicalIngredientId, item.canonicalIngredientId),
gt(schema.inventoryItems.quantity, 0),
)
: and(
eq(schema.inventoryItems.householdId, householdId),
isNull(schema.inventoryItems.canonicalIngredientId),
eq(schema.inventoryItems.displayName, item.displayName),
gt(schema.inventoryItems.quantity, 0),
);
const [dupe] = await app.db
.select({ id: schema.inventoryItems.id })
.from(schema.inventoryItems)
.where(dedupCond)
.limit(1);
if (dupe) {
await app.db
.update(schema.inventoryItems)
.set({
quantity: item.quantity,
unit: item.unit,
brand: item.brand ?? null,
bestBeforeDate: item.bestBeforeDate ?? null,
useByDate: item.useByDate ?? null,
lastVerifiedAt: new Date(),
verifiedByUser: true,
updatedAt: new Date(),
})
.where(eq(schema.inventoryItems.id, dupe.id));
created.push(dupe.id);
continue;
}
const [inv] = await app.db
.insert(schema.inventoryItems)
.values({