Merge branch 'worktree-agent-ac00ecc9'
This commit is contained in:
commit
20c961113d
2 changed files with 197 additions and 0 deletions
32
server/api/wiki/recommended.get.js
Normal file
32
server/api/wiki/recommended.get.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import WikiArticle from '../../models/wikiArticle.js'
|
||||
import { connectDB } from '../../utils/mongoose.js'
|
||||
import { requireAuth } from '../../utils/auth.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const member = await requireAuth(event)
|
||||
|
||||
// Combine craft tags and cooperative ecology tags
|
||||
const craftTags = member.craftTags || []
|
||||
const ecologyTags = (member.communityEcology?.topics || []).map(t => t.tagSlug)
|
||||
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
||||
|
||||
if (!memberTags.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
await connectDB()
|
||||
|
||||
const query = getQuery(event)
|
||||
const limit = Math.min(Math.max(parseInt(query.limit) || 10, 1), 25)
|
||||
|
||||
const articles = await WikiArticle.find({
|
||||
tags: { $in: memberTags },
|
||||
publishedAt: { $ne: null }
|
||||
})
|
||||
.sort({ publishedAt: -1 })
|
||||
.limit(limit)
|
||||
.select('title url summary tags collection publishedAt')
|
||||
.lean()
|
||||
|
||||
return articles
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue