24 lines
604 B
JavaScript
24 lines
604 B
JavaScript
import WikiArticle from '../../../models/wikiArticle.js'
|
|
import { connectDB } from '../../../utils/mongoose.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
await requireAdmin(event)
|
|
await connectDB()
|
|
|
|
const { collection, search } = getQuery(event)
|
|
|
|
const filter = {}
|
|
if (collection) {
|
|
filter.collection = collection
|
|
}
|
|
if (search) {
|
|
filter.title = { $regex: search, $options: 'i' }
|
|
}
|
|
|
|
const articles = await WikiArticle.find(filter)
|
|
.select('collection title tags url outlineId publishedAt')
|
|
.sort({ collection: 1, title: 1 })
|
|
.lean()
|
|
|
|
return articles
|
|
})
|