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.
20 lines
599 B
JavaScript
20 lines
599 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 id = getRouterParam(event, 'id')
|
|
|
|
const post = await BoardPost.findById(id)
|
|
if (!post) {
|
|
throw createError({ statusCode: 404, statusMessage: 'Post not found' })
|
|
}
|
|
|
|
if (post.author.toString() !== member._id.toString()) {
|
|
throw createError({ statusCode: 403, statusMessage: 'Not authorized to delete this post' })
|
|
}
|
|
|
|
await post.deleteOne()
|
|
|
|
return { success: true }
|
|
})
|