refactor(shopping): DEFAULT_SERVINGS-Konstante + Kommentare
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
hsiegeln
2026-04-21 22:54:54 +02:00
parent 8ceb5e95d7
commit 95ba14ad6f

View File

@@ -1,5 +1,9 @@
import type Database from 'better-sqlite3';
// Fallback when a recipe has no servings_default set — matches the default
// used by RecipeEditor's "new recipe" template.
const DEFAULT_SERVINGS = 4;
export type ShoppingCartRecipe = {
recipe_id: number;
title: string;
@@ -33,7 +37,9 @@ export function addRecipeToCart(
const row = db
.prepare('SELECT servings_default FROM recipe WHERE id = ?')
.get(recipeId) as { servings_default: number | null } | undefined;
const resolved = servings ?? row?.servings_default ?? 4;
const resolved = servings ?? row?.servings_default ?? DEFAULT_SERVINGS;
// ON CONFLICT updates only servings — added_by_profile_id stays with the
// first profile that added the recipe (household cart, audit trail).
db.prepare(
`INSERT INTO shopping_cart_recipe (recipe_id, servings, added_by_profile_id)
VALUES (?, ?, ?)
@@ -63,6 +69,8 @@ export function listShoppingList(db: Database.Database): ShoppingListSnapshot {
ORDER BY cr.added_at ASC`
)
.all() as ShoppingCartRecipe[];
// TODO(Task 6): rows + uncheckedCount are populated by the aggregation query.
// Until then, callers must not rely on these fields.
return { recipes, rows: [], uncheckedCount: 0 };
}