feat: board post + channel API routes

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.
This commit is contained in:
Jennie Robinson Faber 2026-04-14 16:25:42 +01:00
parent 8e5f4a2d7c
commit 6a440a846d
9 changed files with 218 additions and 0 deletions

View file

@ -0,0 +1,29 @@
import BoardChannel from '../../models/boardChannel.js'
import { requireAdmin } from '../../utils/auth.js'
import { validateBody } from '../../utils/validateBody.js'
import { boardChannelCreateSchema } from '../../utils/schemas.js'
export default defineEventHandler(async (event) => {
await requireAdmin(event)
const body = await validateBody(event, boardChannelCreateSchema)
try {
const channel = await BoardChannel.create({
name: body.name,
slackChannelId: body.slackChannelId,
tagSlugs: body.tagSlugs || []
})
setResponseStatus(event, 201)
return { channel: channel.toObject() }
} catch (err) {
if (err.code === 11000) {
throw createError({
statusCode: 409,
statusMessage: 'A channel with that Slack channel ID already exists'
})
}
throw err
}
})

View file

@ -0,0 +1,14 @@
import BoardChannel from '../../../models/boardChannel.js'
import { requireAdmin } from '../../../utils/auth.js'
export default defineEventHandler(async (event) => {
await requireAdmin(event)
const id = getRouterParam(event, 'id')
const channel = await BoardChannel.findByIdAndDelete(id)
if (!channel) {
throw createError({ statusCode: 404, statusMessage: 'Channel not found' })
}
return { success: true }
})

View file

@ -0,0 +1,39 @@
import BoardChannel from '../../../models/boardChannel.js'
import { requireAdmin } from '../../../utils/auth.js'
import { validateBody } from '../../../utils/validateBody.js'
import { boardChannelUpdateSchema } from '../../../utils/schemas.js'
export default defineEventHandler(async (event) => {
await requireAdmin(event)
const id = getRouterParam(event, 'id')
const body = await validateBody(event, boardChannelUpdateSchema)
const updateData = {}
if (body.name !== undefined) updateData.name = body.name
if (body.slackChannelId !== undefined) updateData.slackChannelId = body.slackChannelId
if (body.tagSlugs !== undefined) updateData.tagSlugs = body.tagSlugs
try {
const channel = await BoardChannel.findByIdAndUpdate(
id,
{ $set: updateData },
{ new: true, runValidators: true }
)
if (!channel) {
throw createError({ statusCode: 404, statusMessage: 'Channel not found' })
}
return { channel: channel.toObject() }
} catch (err) {
if (err.statusCode) throw err
if (err.code === 11000) {
throw createError({
statusCode: 409,
statusMessage: 'A channel with that Slack channel ID already exists'
})
}
throw err
}
})