Fas 1b punkt 6: First Scan Coach + aktiveringsmätning
This commit is contained in:
@@ -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 §13–14): 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 };
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user