From 86053815f059f5e76e6bd7d7d46337fe7c5cd0b4 Mon Sep 17 00:00:00 2001 From: Aden Lindsay <140392385+AdenMGB@users.noreply.github.com> Date: Sun, 2 Feb 2025 10:19:31 +1030 Subject: [PATCH] feat(api): Added API for creating articles --- server/api/v1/news/index.post.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/api/v1/news/index.post.ts diff --git a/server/api/v1/news/index.post.ts b/server/api/v1/news/index.post.ts new file mode 100644 index 0000000..61c4d92 --- /dev/null +++ b/server/api/v1/news/index.post.ts @@ -0,0 +1,24 @@ +import { defineEventHandler, createError, readBody } from "h3"; +import newsManager from "~/server/internal/news"; + +export default defineEventHandler(async (event) => { + const body = await readBody(event); + + if (!body.authorId) { + throw createError({ + statusCode: 400, + message: 'Author ID is required' + }); + } + + const article = await newsManager.create({ + title: body.title, + content: body.content, + excerpt: body.excerpt, + tags: body.tags, + image: body.image, + authorId: body.authorId, + }); + + return article; +});