Initial commit
This commit is contained in:
commit
92e96b9107
85 changed files with 24969 additions and 0 deletions
31
app/server/api/articles/[slug].delete.ts
Normal file
31
app/server/api/articles/[slug].delete.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Article } from "../../models/Article";
|
||||
import { requireRole } from "../../utils/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
|
||||
// Only admins can delete articles
|
||||
const user = await requireRole(event, ["admin"]);
|
||||
|
||||
if (!slug) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Slug is required",
|
||||
});
|
||||
}
|
||||
|
||||
// Find and delete article
|
||||
const article = await Article.findOneAndDelete({ slug });
|
||||
|
||||
if (!article) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Article not found",
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Article deleted successfully",
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue