mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-24 08:53:04 +10:00
feat(api): Added API for creating articles
This commit is contained in:
@@ -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;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user