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:
@@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user