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.
28 lines
910 B
JavaScript
28 lines
910 B
JavaScript
import BoardPost from '../../models/boardPost.js'
|
|
import { requireAuth } from '../../utils/auth.js'
|
|
import { validateBody } from '../../utils/validateBody.js'
|
|
import { boardPostCreateSchema } from '../../utils/schemas.js'
|
|
import { logActivity, ACTIVITY_TYPES } from '../../utils/activityLog.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const member = await requireAuth(event)
|
|
|
|
const body = await validateBody(event, boardPostCreateSchema)
|
|
|
|
const post = new BoardPost({
|
|
author: member._id,
|
|
title: body.title,
|
|
seeking: body.seeking,
|
|
offering: body.offering,
|
|
note: body.note,
|
|
tags: body.tags || []
|
|
})
|
|
|
|
await post.save()
|
|
await post.populate('author', 'name avatar circle board.slackHandle')
|
|
|
|
logActivity(member._id, ACTIVITY_TYPES.BOARD_POST_CREATED, { postId: post._id, title: post.title })
|
|
|
|
setResponseStatus(event, 201)
|
|
return { post: post.toObject() }
|
|
})
|