Member/Ecology revamp.
This commit is contained in:
parent
fc7ec52574
commit
59d6e97787
31 changed files with 1763 additions and 1010 deletions
34
server/api/admin/wiki/batch-visibility.post.js
Normal file
34
server/api/admin/wiki/batch-visibility.post.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import * as z from 'zod'
|
||||
import WikiArticle from '../../../models/wikiArticle.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
|
||||
const batchVisibilitySchema = z.object({
|
||||
articleIds: z.array(z.string()).optional(),
|
||||
collection: z.string().optional(),
|
||||
hidden: z.boolean()
|
||||
})
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAdmin(event)
|
||||
|
||||
const body = await validateBody(event, batchVisibilitySchema)
|
||||
|
||||
if (!body.articleIds && !body.collection) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Must provide either articleIds or collection'
|
||||
})
|
||||
}
|
||||
|
||||
await connectDB()
|
||||
|
||||
const filter = body.articleIds
|
||||
? { _id: { $in: body.articleIds } }
|
||||
: { collection: body.collection }
|
||||
|
||||
const result = await WikiArticle.updateMany(filter, {
|
||||
$set: { hidden: body.hidden }
|
||||
})
|
||||
|
||||
return { modified: result.modifiedCount || 0 }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue