mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 21:00:09 +00:00
20c8fb0898
Introduce user-reported-issues and Goodreads shelf sync features and wire them into notifications. Adds Prisma migrations and schema changes (ReportedIssue, GoodreadsShelf, GoodreadsBookMapping), API endpoints for reporting (POST /audiobooks/[asin]/report-issue) and admin management (list, resolve/dismiss, replace), and an admin UI section to view/dismiss/replace reported issues. Adds a new notification event (issue_reported) with updates to notification schemas, docs and provider handling, plus a notification-events constants file. Refactors request creation to use createRequestForUser service, adds a Goodreads sync processor/service/hooks/UI modals, a scrape-resilience util, and related tests and minor integration updates.
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
/**
|
|
* Component: Admin Resolve Reported Issue API
|
|
* Documentation: documentation/backend/services/reported-issues.md
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { requireAuth, requireAdmin, AuthenticatedRequest } from '@/lib/middleware/auth';
|
|
import { dismissIssue, ReportedIssueError } from '@/lib/services/reported-issue.service';
|
|
import { z } from 'zod';
|
|
import { RMABLogger } from '@/lib/utils/logger';
|
|
|
|
const logger = RMABLogger.create('API.Admin.ReportedIssues.Resolve');
|
|
|
|
const ResolveSchema = z.object({
|
|
action: z.enum(['dismiss']),
|
|
});
|
|
|
|
/**
|
|
* POST /api/admin/reported-issues/[id]/resolve
|
|
* Dismiss a reported issue
|
|
*/
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
return requireAuth(request, async (req: AuthenticatedRequest) => {
|
|
return requireAdmin(req, async () => {
|
|
try {
|
|
if (!req.user) {
|
|
return NextResponse.json(
|
|
{ error: 'Unauthorized', message: 'User not authenticated' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const { id } = await params;
|
|
const body = await req.json();
|
|
const { action } = ResolveSchema.parse(body);
|
|
|
|
if (action === 'dismiss') {
|
|
const issue = await dismissIssue(id, req.user.id);
|
|
return NextResponse.json({ success: true, issue });
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{ error: 'InvalidAction', message: 'Unknown action' },
|
|
{ status: 400 }
|
|
);
|
|
} catch (error) {
|
|
if (error instanceof z.ZodError) {
|
|
return NextResponse.json(
|
|
{ error: 'ValidationError', details: error.errors },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
if (error instanceof ReportedIssueError) {
|
|
return NextResponse.json(
|
|
{ error: 'ResolveError', message: error.message },
|
|
{ status: error.statusCode }
|
|
);
|
|
}
|
|
|
|
logger.error('Failed to resolve issue', {
|
|
error: error instanceof Error ? error.message : String(error),
|
|
});
|
|
return NextResponse.json(
|
|
{ error: 'ServerError', message: 'Failed to resolve issue' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
});
|
|
});
|
|
}
|