refactor: convert preferences to Server Action

- Add src/app/actions/preferences.ts with updatePreferences
- Update PreferencesContext to use Server Action
- Remove PUT from api/preferences route (keep GET)
This commit is contained in:
2026-02-28 10:50:32 +01:00
parent 7308c0aa63
commit d56b0fd7ae
4 changed files with 51 additions and 85 deletions

View File

@@ -7,6 +7,7 @@ import type { UserPreferences } from "@/types/preferences";
import { getErrorMessage } from "@/utils/errors";
import logger from "@/lib/logger";
// GET reste utilisé par PreferencesContext pour récupérer les préférences
export async function GET() {
try {
const preferences: UserPreferences = await PreferencesService.getPreferences();
@@ -37,36 +38,3 @@ export async function GET() {
);
}
}
export async function PUT(request: NextRequest) {
try {
const preferences: UserPreferences = await request.json();
const updatedPreferences: UserPreferences =
await PreferencesService.updatePreferences(preferences);
return NextResponse.json(updatedPreferences);
} catch (error) {
logger.error({ err: error }, "Erreur lors de la mise à jour des préférences:");
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
name: "Preferences update error",
code: error.code,
message: getErrorMessage(error.code),
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
name: "Preferences update error",
code: ERROR_CODES.PREFERENCES.UPDATE_ERROR,
message: getErrorMessage(ERROR_CODES.PREFERENCES.UPDATE_ERROR),
},
},
{ status: 500 }
);
}
}