From 3e4cc78d3e64326f38bbe1c23e1d4cd70f27cbdf Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Mon, 11 May 2026 23:39:27 +0200 Subject: [PATCH] fix: write cook assignments with legacy bridge schema --- server/routes/meal-planning.js | 19 +++++++++++++------ server/routes/meals.js | 8 ++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/server/routes/meal-planning.js b/server/routes/meal-planning.js index 3e799c8..a5912c0 100644 --- a/server/routes/meal-planning.js +++ b/server/routes/meal-planning.js @@ -225,7 +225,7 @@ router.put('/cook-assignments/:mealId', (req, res) => { try { const mealId = ensureMeal(req.params.mealId); const userId = ensureUser(req.body.user_id ?? req.body.userId); - const meal = db.get().prepare('SELECT date, meal_type FROM meals WHERE id = ?').get(mealId); + const meal = db.get().prepare('SELECT date, meal_type, title FROM meals WHERE id = ?').get(mealId); const vDate = date(req.body.planned_for_date ?? req.body.plannedForDate ?? meal.date, 'Planned date', true); const mealType = VALID_MEAL_TYPES.includes(req.body.meal_type || req.body.mealType || meal.meal_type) ? (req.body.meal_type || req.body.mealType || meal.meal_type) : meal.meal_type; const errors = collectErrors([vDate]); @@ -236,11 +236,18 @@ router.put('/cook-assignments/:mealId', (req, res) => { WHERE meal_id = ? `).run(userId, vDate.value, mealType, req.body.source_plan_id ?? req.body.sourcePlanId ?? null, currentUserId(req), mealId); if (update.changes === 0) { - insertWithOptionalTextId( - 'planned_meal_cooks', - ['meal_id', 'user_id', 'planned_for_date', 'meal_type', 'source_plan_id', 'created_by', 'updated_at'], - [mealId, userId, vDate.value, mealType, req.body.source_plan_id ?? req.body.sourcePlanId ?? null, currentUserId(req), new Date().toISOString().replace(/\.\d{3}Z$/, 'Z')] - ); + const columns = ['meal_id', 'user_id', 'planned_for_date', 'meal_type', 'source_plan_id', 'created_by', 'updated_at']; + const values = [mealId, userId, vDate.value, mealType, req.body.source_plan_id ?? req.body.sourcePlanId ?? null, currentUserId(req), new Date().toISOString().replace(/\.\d{3}Z$/, 'Z')]; + const available = tableColumns('planned_meal_cooks'); + if (available.has('meal_date')) { + columns.push('meal_date'); + values.push(vDate.value); + } + if (available.has('meal_title')) { + columns.push('meal_title'); + values.push(meal.title || null); + } + insertWithOptionalTextId('planned_meal_cooks', columns, values); } const data = db.get().prepare('SELECT * FROM planned_meal_cooks WHERE meal_id = ?').get(mealId); res.json({ data }); diff --git a/server/routes/meals.js b/server/routes/meals.js index 15595d6..c28da83 100644 --- a/server/routes/meals.js +++ b/server/routes/meals.js @@ -91,6 +91,14 @@ function saveCookAssignment(meal, cookUserId, sourcePlanId, createdBy) { const columns = tableColumns('planned_meal_cooks'); const insertColumns = ['meal_id', 'user_id', 'planned_for_date', 'meal_type', 'source_plan_id', 'created_by', 'updated_at']; const values = [meal.id, cookUserId, meal.date, meal.meal_type, sourcePlanId || null, createdBy, new Date().toISOString().replace(/\.\d{3}Z$/, 'Z')]; + if (columns.has('meal_date')) { + insertColumns.push('meal_date'); + values.push(meal.date); + } + if (columns.has('meal_title')) { + insertColumns.push('meal_title'); + values.push(meal.title || null); + } if (columns.has('id')) { insertColumns.unshift('id'); values.unshift(crypto.randomUUID());