2025-03-02 17:15:57 +00:00

45 lines
1.3 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';
import { checkAdminAuth } from '@/lib/auth';
import { resetMemberVotingStatus } from '@/lib/server-auth';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
// Check for admin auth
const { password } = body;
const isAuthenticated = await checkAdminAuth(password);
if (!isAuthenticated) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
);
}
// Reset responses.json to an empty array
const responsesPath = path.join(process.cwd(), 'data', 'responses.json');
fs.writeFileSync(responsesPath, '[]', 'utf8');
// Reset used_tokens.json to an empty array
const usedTokensPath = path.join(process.cwd(), 'data', 'used_tokens.json');
fs.writeFileSync(usedTokensPath, '[]', 'utf8');
// Reset member voting status
resetMemberVotingStatus();
return NextResponse.json({
success: true,
message: 'Abstimmungsdaten wurden zurückgesetzt'
});
}
catch (error) {
console.error('Error resetting votes:', error);
return NextResponse.json(
{ error: 'Fehler beim Zurücksetzen der Abstimmungsdaten' },
{ status: 500 }
);
}
}