Files
Epicure/apps/web/app/api/v1/users/me/feature-prefs/route.ts
T
Arnaud 274c50c2f6 fix: desktop nav ignored feature toggles; add chatbots toggle (v0.62.0)
Feature toggles (Settings -> Features) were filtered into
visibleNavItems but the desktop horizontal nav still mapped over the
raw NAV_ITEMS list, so hiding a feature only worked on mobile. Both
nav renders now read the same filtered list.

Also adds a Chatbots toggle covering the recipe cooking-chat panel
and the recipe-list cooking assistant, wired end-to-end (schema,
migration, feature-prefs lib, API route, settings form, i18n,
openapi).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-20 23:23:01 +02:00

47 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { db, userFeaturePrefs } from "@epicure/db";
import { requireSession } from "@/lib/api-auth";
import { getFeaturePrefs } from "@/lib/feature-prefs";
import { z } from "zod";
const PutSchema = z.object({
nutrition: z.boolean().optional(),
pantry: z.boolean().optional(),
mealPlan: z.boolean().optional(),
shoppingLists: z.boolean().optional(),
collections: z.boolean().optional(),
messages: z.boolean().optional(),
chatbots: z.boolean().optional(),
});
export async function GET() {
const { session, response } = await requireSession();
if (response) return response;
const prefs = await getFeaturePrefs(session!.user.id);
return NextResponse.json({ data: prefs });
}
export async function PUT(req: NextRequest) {
const { session, response } = await requireSession();
if (response) return response;
const parsed = PutSchema.safeParse(await req.json());
if (!parsed.success) {
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
}
const body = parsed.data;
const userId = session!.user.id;
await db
.insert(userFeaturePrefs)
.values({ id: crypto.randomUUID(), userId, ...body, updatedAt: new Date() })
.onConflictDoUpdate({
target: userFeaturePrefs.userId,
set: { ...body, updatedAt: new Date() },
});
return NextResponse.json({ ok: true });
}