initial commit
This commit is contained in:
39
app/api/debug/topics/route.ts
Normal file
39
app/api/debug/topics/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import connectDB from '@/lib/mongodb'
|
||||
import TopicModel from '@/models/topic'
|
||||
|
||||
// Debug endpoint to see what topics exist in the database
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
await connectDB()
|
||||
|
||||
// Get all topics with basic info
|
||||
const topics = await TopicModel.find({}, {
|
||||
id: 1,
|
||||
slug: 1,
|
||||
title: 1,
|
||||
isDraft: 1,
|
||||
views: 1,
|
||||
authorId: 1
|
||||
}).sort({ publishedAt: -1 })
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
count: topics.length,
|
||||
topics: topics.map(topic => ({
|
||||
id: topic.id,
|
||||
slug: topic.slug,
|
||||
title: topic.title,
|
||||
isDraft: topic.isDraft,
|
||||
views: topic.views || 0,
|
||||
authorId: topic.authorId
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Debug topics error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user