Fas 1b punkt 6: First Scan Coach + aktiveringsmätning

This commit is contained in:
Sven (AAMOS AI)
2026-08-06 04:14:49 +07:00
parent 2f3cdf8016
commit bd8df59138
29 changed files with 9378 additions and 29 deletions
+15 -1
View File
@@ -1,6 +1,6 @@
import type { FastifyInstance } from "fastify";
import { and, desc, eq, gt, ilike, inArray, isNull, lte, or, sql } from "drizzle-orm";
import { schema } from "@app/database";
import { markMilestone, schema } from "@app/database";
import {
cookRecipeInputSchema,
createUserRecipeInputSchema,
@@ -226,6 +226,11 @@ export async function recipeRoutes(app: FastifyInstance) {
// Innehållsspråk (i18n-spec §1314): publicerad översättning om användarens
// språk inte är svenska; annars svensk källa. Struktur ändras aldrig.
const householdId = await getActiveHouseholdId(app.db, req.userId);
if (householdId) {
void markMilestone(app.db, householdId, "firstRecipeRecommendationViewedAt");
}
const languageTag = await userLanguageTag(app.db, req.userId);
const translation = await resolveRecipeTranslation(app.db, id, languageTag);
const ingredientNames = await resolveIngredientNames(
@@ -366,6 +371,10 @@ export async function recipeRoutes(app: FastifyInstance) {
.update(schema.recipes)
.set({ favoriteCount: sql`${schema.recipes.favoriteCount} + 1` })
.where(eq(schema.recipes.id, id));
const householdId = await getActiveHouseholdId(app.db, req.userId);
if (householdId) {
void markMilestone(app.db, householdId, "firstRecipeSavedOrStartedAt");
}
return { ok: true };
});
@@ -598,6 +607,11 @@ export async function recipeRoutes(app: FastifyInstance) {
correlationId: req.correlationId,
});
await markMilestone(app.db, householdId, "firstCookingSessionCompletedAt");
if (input.deductInventory && deductions.length > 0) {
await markMilestone(app.db, householdId, "inventoryUpdatedAfterCookingAt");
}
return { ok: true, mealIds, mealBoxId, inventoryDeductions: deductions };
});