diff --git a/apps/api/src/routes/recommendations.ts b/apps/api/src/routes/recommendations.ts index 5f3c595..768e54e 100644 --- a/apps/api/src/routes/recommendations.ts +++ b/apps/api/src/routes/recommendations.ts @@ -25,6 +25,7 @@ import { import { DEFAULT_TARGETS, computeDailyTargets, summarizeDay } from "@app/nutrition-engine"; import { parse } from "../lib/errors.js"; import { getActiveHouseholdId, todayIso } from "../lib/helpers.js"; +import { loadLocalePreferences } from "../lib/localeContext.js"; /** * "Vad ska vi äta?" (spec §18) – appens viktigaste endpoint. @@ -189,14 +190,18 @@ export async function recommendationRoutes(app: FastifyInstance) { targets, ); - // --- 5. Säsong & högtid (spec §28) --- + // --- 5. Säsong & högtid (spec §28) – marknadsstyrt via användarens region --- + const localePrefs = await loadLocalePreferences(app.db, req.userId); + const market = localePrefs.regionCode; const events = await app.db .select() .from(schema.seasonEvents) - .where(and(eq(schema.seasonEvents.active, true), eq(schema.seasonEvents.market, "SE"))); - const activeHolidayTags = events - .filter((e) => isEventActive({ dateRule: e.dateRule, leadDays: e.leadDays }, today)) - .map((e) => e.slug); + .where(and(eq(schema.seasonEvents.active, true), eq(schema.seasonEvents.market, market))); + const activeEvents = events.filter((e) => + isEventActive({ dateRule: e.dateRule, leadDays: e.leadDays }, today), + ); + const activeHolidayTags = activeEvents.map((e) => e.slug); // slugs → matchar recept-holidayTags (scoring) + const activeHolidayNames = activeEvents.map((e) => e.nameSv); // visningsnamn med å/ä/ö // --- 6. Senast lagat (variation) + hushållsbetyg --- const cooks = householdId @@ -468,7 +473,7 @@ export async function recommendationRoutes(app: FastifyInstance) { context: { persons: ctx.persons, season: ctx.currentSeason, - activeHolidays: activeHolidayTags, + activeHolidays: activeHolidayNames, remainingKcal: ctx.remainingKcal, remainingProteinG: ctx.remainingProteinG, craving: craving ?? null,