feat: mark recipe as cooked (multi-cook history + backdate) and enable auto-deduct pantry on cook (v0.75.0)

Adds a general-purpose "mark cooked" dialog for any recipe (not just batch-cook dishes), with a date picker for backdating and a pantry-deduct checkbox defaulted on. Also flips the previously dead-in-the-UI deductFromPantry flag to true for the existing batch-cook and meal-planner cook actions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-24 11:28:41 +02:00
parent 55c6fc5ab7
commit 04a911b431
14 changed files with 245 additions and 9 deletions
@@ -10,6 +10,9 @@ const Schema = z.object({
notes: z.string().max(2000).optional(),
deductFromPantry: z.boolean().default(true),
batchDishId: z.string().optional(),
/** ISO date (YYYY-MM-DD) or full datetime — lets a user log a past cook,
* not just "just now". Defaults to now when omitted. */
cookedAt: z.string().optional(),
});
export async function POST(req: NextRequest, { params }: Params) {
@@ -44,6 +47,8 @@ export async function POST(req: NextRequest, { params }: Params) {
isFirstBatchCook = !priorCook;
}
const cookedAt = data.cookedAt ? new Date(data.cookedAt) : new Date();
await db.insert(cookingHistory).values({
id: crypto.randomUUID(),
userId,
@@ -51,7 +56,7 @@ export async function POST(req: NextRequest, { params }: Params) {
batchDishId: data.batchDishId,
servings: data.servings,
notes: data.notes,
cookedAt: new Date(),
cookedAt: isNaN(cookedAt.getTime()) ? new Date() : cookedAt,
});
if (data.deductFromPantry && (!data.batchDishId || isFirstBatchCook)) {