refactor: extract escapeRegex and validateTagSlugs server utils
Deduplicate tag validation and regex escaping into shared auto-imported utils. Add tag validation to wiki patch/batch-tag routes. Remove duplicate tags field from event schema.
This commit is contained in:
parent
f585fabf21
commit
a516f172fb
11 changed files with 33 additions and 31 deletions
|
|
@ -14,6 +14,8 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await connectDB()
|
||||
|
||||
await validateTagSlugs(body.tags)
|
||||
|
||||
const article = await WikiArticle.findByIdAndUpdate(
|
||||
id,
|
||||
{ tags: body.tags },
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await connectDB()
|
||||
|
||||
await validateTagSlugs([...(body.addTags || []), ...(body.removeTags || [])])
|
||||
|
||||
const filter = body.articleIds
|
||||
? { _id: { $in: body.articleIds } }
|
||||
: { collection: body.collection }
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
|||
filter.collection = collection
|
||||
}
|
||||
if (search) {
|
||||
filter.title = { $regex: search, $options: 'i' }
|
||||
filter.title = { $regex: escapeRegex(search), $options: 'i' }
|
||||
}
|
||||
|
||||
const articles = await WikiArticle.find(filter)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue