feat(api): Added API for creating articles

This commit is contained in:
Aden Lindsay
2025-02-02 10:19:31 +10:30
committed by GitHub
parent 88453f1ec4
commit 86053815f0

View File

@ -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;
});