chore: playground example
This commit is contained in:
8
playground/server/api/users/[_id].delete.ts
Normal file
8
playground/server/api/users/[_id].delete.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
return await UserSchema.findOneAndDelete({ _id: event.context.params?._id })
|
||||
}
|
||||
catch (error) {
|
||||
return error
|
||||
}
|
||||
})
|
||||
8
playground/server/api/users/[_id].get.ts
Normal file
8
playground/server/api/users/[_id].get.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
return await UserSchema.findOne({ _id: event.context.params?._id })
|
||||
}
|
||||
catch (error) {
|
||||
return error
|
||||
}
|
||||
})
|
||||
9
playground/server/api/users/[_id].put.ts
Normal file
9
playground/server/api/users/[_id].put.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
try {
|
||||
return await UserSchema.findOneAndUpdate({ _id: event.context.params?._id }, body, { new: true })
|
||||
}
|
||||
catch (error) {
|
||||
return error
|
||||
}
|
||||
})
|
||||
9
playground/server/api/users/create.post.ts
Normal file
9
playground/server/api/users/create.post.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
try {
|
||||
return await new UserSchema(body).save()
|
||||
}
|
||||
catch (error) {
|
||||
return error
|
||||
}
|
||||
})
|
||||
8
playground/server/api/users/index.get.ts
Normal file
8
playground/server/api/users/index.get.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export default defineEventHandler(async () => {
|
||||
try {
|
||||
return await UserSchema.find({})
|
||||
}
|
||||
catch (error) {
|
||||
return error
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user