feat: add Tags API endpoints and validation schemas
- GET /api/tags — public, filterable by ?pool=craft|cooperative, active only, sorted by label - POST /api/tags/suggest — auth-required, creates TagSuggestion doc - Add tagSuggestionSchema and communityConnectionsUpdateSchema to schemas.js - Extend memberProfileUpdateSchema with craftTags, craftTagsPrivacy, communityConnectionsPrivacy
This commit is contained in:
parent
18b8106405
commit
79d038c724
3 changed files with 56 additions and 1 deletions
16
server/api/tags/index.get.js
Normal file
16
server/api/tags/index.get.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Tag from '../../models/tag.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await connectDB()
|
||||
|
||||
const query = getQuery(event)
|
||||
const filter = { active: true }
|
||||
|
||||
if (query.pool) {
|
||||
filter.pool = query.pool
|
||||
}
|
||||
|
||||
const tags = await Tag.find(filter).sort({ label: 1 }).lean()
|
||||
|
||||
return { tags }
|
||||
})
|
||||
17
server/api/tags/suggest.post.js
Normal file
17
server/api/tags/suggest.post.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import TagSuggestion from '../../models/tagSuggestion.js'
|
||||
import { tagSuggestionSchema } from '../../utils/schemas.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await connectDB()
|
||||
|
||||
const member = await requireAuth(event)
|
||||
const body = await validateBody(event, tagSuggestionSchema)
|
||||
|
||||
await TagSuggestion.create({
|
||||
label: body.label,
|
||||
pool: body.pool,
|
||||
suggestedBy: member._id
|
||||
})
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue