mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
feat(api): Added API for creating articles
This commit is contained in:
24
server/api/v1/news/index.post.ts
Normal file
24
server/api/v1/news/index.post.ts
Normal 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;
|
||||
});
|
||||
Reference in New Issue
Block a user