v0.6.0 — Kitchen: Pantry & Freezer inventory
This commit is contained in:
41
src/app/(dashboard)/kitchen/pantry/page.tsx
Normal file
41
src/app/(dashboard)/kitchen/pantry/page.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { db } from "@/lib/db";
|
||||
import { PantryClient } from "@/components/pantry/pantry-client";
|
||||
|
||||
export const metadata = { title: "Pantry & Freezer" };
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function PantryPage() {
|
||||
const [items, locations, plants] = await Promise.all([
|
||||
db.item.findMany({
|
||||
where: { kind: "CONSUMABLE", active: true },
|
||||
orderBy: [{ location: { name: "asc" } }, { name: "asc" }],
|
||||
select: {
|
||||
id: true, name: true, description: true, quantity: true, unit: true,
|
||||
storedAt: true, bestBefore: true, source: true, plantId: true, notes: true,
|
||||
location: { select: { id: true, name: true } },
|
||||
plant: { select: { id: true, commonName: true, variety: true } },
|
||||
},
|
||||
}),
|
||||
db.location.findMany({ where: { active: true }, orderBy: { name: "asc" }, select: { id: true, name: true } }),
|
||||
db.plant.findMany({ where: { active: true }, orderBy: { commonName: "asc" }, select: { id: true, commonName: true, variety: true } }),
|
||||
]);
|
||||
|
||||
const serialized = items.map(i => ({
|
||||
id: i.id,
|
||||
name: i.name,
|
||||
description: i.description,
|
||||
quantity: Number(i.quantity),
|
||||
unit: i.unit,
|
||||
packageSize: i.description,
|
||||
storedAt: i.storedAt,
|
||||
bestBefore: i.bestBefore,
|
||||
source: i.source,
|
||||
notes: i.notes,
|
||||
locationId: i.location?.id ?? null,
|
||||
locationName: i.location?.name ?? null,
|
||||
plantId: i.plant?.id ?? null,
|
||||
plantName: i.plant ? `${i.plant.commonName}${i.plant.variety ? ` (${i.plant.variety})` : ""}` : null,
|
||||
}));
|
||||
|
||||
return <PantryClient initialItems={serialized} locations={locations} plants={plants} />;
|
||||
}
|
||||
Reference in New Issue
Block a user