Implements Phase 2a of board classifieds redesign: - GET/POST /api/board/posts (list with tag/author filters, create) - PATCH/DELETE /api/board/posts/:id (author-only) - GET /api/board/channels (member) - POST /api/admin/board-channels (admin) - PATCH/DELETE /api/admin/board-channels/:id (admin) Adds board_post_created activity type.
24 lines
576 B
JavaScript
24 lines
576 B
JavaScript
import BoardPost from '../../models/boardPost.js'
|
|
import { requireAuth } from '../../utils/auth.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const member = await requireAuth(event)
|
|
|
|
const query = getQuery(event)
|
|
const dbQuery = {}
|
|
|
|
if (query.tag) {
|
|
dbQuery.tags = query.tag
|
|
}
|
|
|
|
if (query.author) {
|
|
dbQuery.author = query.author === 'me' ? member._id : query.author
|
|
}
|
|
|
|
const posts = await BoardPost.find(dbQuery)
|
|
.sort({ createdAt: -1 })
|
|
.populate('author', 'name avatar circle board.slackHandle')
|
|
.lean()
|
|
|
|
return { posts }
|
|
})
|