Bugfix: what-to-eat utan hushall ger forslag; onboarding mal kan valjas multi
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user