Member/Ecology revamp.
This commit is contained in:
parent
fc7ec52574
commit
59d6e97787
31 changed files with 1763 additions and 1010 deletions
|
|
@ -2,23 +2,35 @@ import * as z from 'zod'
|
|||
import WikiArticle from '../../../models/wikiArticle.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
|
||||
const wikiTagsSchema = z.object({
|
||||
tags: z.array(z.string())
|
||||
const wikiUpdateSchema = z.object({
|
||||
tags: z.array(z.string()).optional(),
|
||||
hidden: z.boolean().optional()
|
||||
})
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAdmin(event)
|
||||
|
||||
const body = await validateBody(event, wikiTagsSchema)
|
||||
const body = await validateBody(event, wikiUpdateSchema)
|
||||
const id = getRouterParam(event, 'id')
|
||||
|
||||
if (body.tags === undefined && body.hidden === undefined) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Nothing to update' })
|
||||
}
|
||||
|
||||
await connectDB()
|
||||
|
||||
await validateTagSlugs(body.tags)
|
||||
const update = {}
|
||||
if (body.tags !== undefined) {
|
||||
await validateTagSlugs(body.tags)
|
||||
update.tags = body.tags
|
||||
}
|
||||
if (body.hidden !== undefined) {
|
||||
update.hidden = body.hidden
|
||||
}
|
||||
|
||||
const article = await WikiArticle.findByIdAndUpdate(
|
||||
id,
|
||||
{ tags: body.tags },
|
||||
update,
|
||||
{ new: true }
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue