Files
wikiplus/app/api/article/[slug]/history/route.ts
T
2026-01-24 16:52:19 -06:00

35 lines
807 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
) {
const { slug } = await params;
// Fetch article to get its ID
const article = await prisma.article.findUnique({
where: { slug },
select: { id: true },
});
if (!article) {
return NextResponse.json({ error: 'Article not found' }, { status: 404 });
}
// Fetch history entries
const history = await prisma.articleHistory.findMany({
where: { articleId: article.id },
orderBy: { createdAt: 'desc' },
select: {
id: true,
oldContent: true,
newContent: true,
reason: true,
createdAt: true,
},
});
return NextResponse.json(history);
}