fix: news frontend

This commit is contained in:
DecDuck
2025-03-10 12:05:10 +11:00
parent b6f52f660a
commit 1eede0f035
7 changed files with 53 additions and 62 deletions

View File

@@ -1,16 +1,15 @@
import { defineEventHandler, createError } from "h3";
import aclManager from "~/server/internal/acls";
import newsManager from "~/server/internal/news";
export default defineEventHandler(async (event) => {
const userId = await event.context.session.getUserId(event);
if (!userId) {
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["news:delete"]);
if (!allowed)
throw createError({
statusCode: 401,
message: "Unauthorized",
statusCode: 403,
});
}
const id = event.context.params?.id;
const id = h3.context.params?.id;
if (!id) {
throw createError({
statusCode: 400,

View File

@@ -45,23 +45,27 @@ class NewsManager {
return await prisma.article.findMany({
where: {
AND: [
{
tags: {
some: { OR: options.tags?.map((e) => ({ name: e })) ?? [] },
},
},
{
title: {
search: options.search
},
description: {
search: options.search
},
content: {
search: options.search
}
}
],
options.tags
? {
tags: {
some: { OR: options.tags?.map((e) => ({ name: e })) ?? [] },
},
}
: undefined,
options.search
? {
title: {
search: options.search,
},
description: {
search: options.search,
},
content: {
search: options.search,
},
}
: undefined,
].filter((e) => e !== undefined),
},
take: options?.take || 10,
skip: options?.skip || 0,
@@ -75,6 +79,7 @@ class NewsManager {
displayName: true,
},
},
tags: true,
},
});
}
@@ -89,6 +94,7 @@ class NewsManager {
displayName: true,
},
},
tags: true,
},
});
}