Bugfix: what-to-eat utan hushall ger forslag; onboarding mal kan valjas multi

This commit is contained in:
Sven (AAMOS AI)
2026-08-06 21:32:32 +07:00
parent 8e6b780480
commit dd66ebedbf
18 changed files with 238 additions and 68 deletions
+13 -3
View File
@@ -62,17 +62,27 @@ export async function onboardingRoutes(app: FastifyInstance) {
app.post("/v1/onboarding/quick-start", auth, async (req) => {
const input = parse(quickStartInputSchema, req.body);
// Normalize goals: multi-select UI sends `goals`; legacy clients send `primaryGoal`.
const goals = input.goals?.length
? input.goals
: input.primaryGoal
? [input.primaryGoal]
: [];
const primaryGoal = goals[0];
// Upsert minimal preferences
await app.db
.insert(schema.userPreferences)
.values({
userId: req.userId,
...(input.primaryGoal ? { primaryGoal: input.primaryGoal } : {}),
goals,
...(primaryGoal ? { primaryGoal } : {}),
})
.onConflictDoUpdate({
target: schema.userPreferences.userId,
set: {
...(input.primaryGoal ? { primaryGoal: input.primaryGoal } : {}),
goals,
...(primaryGoal ? { primaryGoal } : {}),
updatedAt: new Date(),
},
});
@@ -91,7 +101,7 @@ export async function onboardingRoutes(app: FastifyInstance) {
await audit(app.db, {
actorUserId: req.userId,
action: "onboarding.quick_start",
metadata: { primaryGoal: input.primaryGoal, precisionMode: input.precisionMode },
metadata: { goals, primaryGoal, precisionMode: input.precisionMode },
ip: req.ip,
correlationId: req.correlationId,
});