Added Docker
This commit is contained in:
29
server/api/posts/index.post.ts
Normal file
29
server/api/posts/index.post.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Post, User } from '~/server/database/models'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const body = await readBody(event)
|
||||
|
||||
const post = await Post.create({
|
||||
title: body.title,
|
||||
content: body.content,
|
||||
published: body.published || false,
|
||||
authorId: body.authorId
|
||||
})
|
||||
|
||||
// Get the post with author information
|
||||
const postWithAuthor = await Post.findByPk(post.id, {
|
||||
include: [{
|
||||
model: User,
|
||||
as: 'author'
|
||||
}]
|
||||
})
|
||||
|
||||
return postWithAuthor
|
||||
} catch (error) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to create post'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user