Merge branch 'worktree-agent-a5a0c7d9'
This commit is contained in:
commit
abca0fb7d6
3 changed files with 185 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import Event from "../../models/event.js";
|
||||
import Tag from "../../models/tag.js";
|
||||
import { connectDB } from "../../utils/mongoose.js";
|
||||
import { requireAdmin } from "../../utils/auth.js";
|
||||
import { validateBody } from "../../utils/validateBody.js";
|
||||
|
|
@ -12,6 +13,19 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await connectDB();
|
||||
|
||||
// Validate tag slugs against Tag collection
|
||||
if (body.tags && body.tags.length > 0) {
|
||||
const foundTags = await Tag.find({ slug: { $in: body.tags } });
|
||||
const foundSlugs = new Set(foundTags.map((t) => t.slug));
|
||||
const invalid = body.tags.filter((s) => !foundSlugs.has(s));
|
||||
if (invalid.length > 0) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: `Unknown tag slugs: ${invalid.join(", ")}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const eventData = {
|
||||
...body,
|
||||
createdBy: admin.email,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import Event from '../../../models/event.js'
|
||||
import Tag from '../../../models/tag.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
import { requireAdmin } from '../../../utils/auth.js'
|
||||
|
||||
|
|
@ -11,6 +12,19 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await connectDB()
|
||||
|
||||
// Validate tag slugs against Tag collection
|
||||
if (body.tags && body.tags.length > 0) {
|
||||
const foundTags = await Tag.find({ slug: { $in: body.tags } })
|
||||
const foundSlugs = new Set(foundTags.map(t => t.slug))
|
||||
const invalid = body.tags.filter(s => !foundSlugs.has(s))
|
||||
if (invalid.length > 0) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: `Unknown tag slugs: ${invalid.join(', ')}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const updateData = {
|
||||
...body,
|
||||
startDate: new Date(body.startDate),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue