Merge branch 'AdenMGB-develop' into develop

This commit is contained in:
DecDuck
2025-03-10 11:41:40 +11:00
26 changed files with 1526 additions and 4 deletions
+6
View File
@@ -30,6 +30,8 @@ export const userACLDescriptions: ObjectFromList<typeof userACLs> = {
"Remove a game from any collection (excluding library).",
"library:add": "Add a game to your library.",
"library:remove": "Remove a game from your library.",
"news:read": "Read the server's news articles.",
};
export const systemACLDescriptions: ObjectFromList<typeof systemACLs> = {
@@ -55,4 +57,8 @@ export const systemACLDescriptions: ObjectFromList<typeof systemACLs> = {
"import:game:new": "Import a game.",
"user:read": "Fetch any user's information.",
"news:read": "Read news articles.",
"news:create": "Create a new news article.",
"news:delete": "Delete a news article."
};
+12
View File
@@ -25,6 +25,11 @@ export const userACLs = [
"collections:remove",
"library:add",
"library:remove",
<<<<<<< HEAD
=======
"news:read",
>>>>>>> AdenMGB-develop
] as const;
const userACLPrefix = "user:";
@@ -51,6 +56,13 @@ export const systemACLs = [
"import:game:new",
"user:read",
<<<<<<< HEAD
=======
"news:read",
"news:create",
"news:delete",
>>>>>>> AdenMGB-develop
] as const;
const systemACLPrefix = "system:";
+118
View File
@@ -0,0 +1,118 @@
import { triggerAsyncId } from "async_hooks";
import prisma from "../db/database";
class NewsManager {
async create(data: {
title: string;
content: string;
description: string;
tags: string[];
authorId: string;
image?: string;
}) {
return await prisma.article.create({
data: {
title: data.title,
description: data.description,
content: data.content,
tags: {
connectOrCreate: data.tags.map((e) => ({
where: { name: e },
create: { name: e },
})),
},
image: data.image,
author: {
connect: {
id: data.authorId,
},
},
},
});
}
async fetch(
options: {
take?: number;
skip?: number;
orderBy?: "asc" | "desc";
tags?: string[];
search?: string;
} = {}
) {
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
}
}
],
},
take: options?.take || 10,
skip: options?.skip || 0,
orderBy: {
publishedAt: options?.orderBy || "desc",
},
include: {
author: {
select: {
id: true,
displayName: true,
},
},
},
});
}
async fetchById(id: string) {
return await prisma.article.findUnique({
where: { id },
include: {
author: {
select: {
id: true,
displayName: true,
},
},
},
});
}
async update(
id: string,
data: {
title?: string;
content?: string;
excerpt?: string;
image?: string;
}
) {
return await prisma.article.update({
where: { id },
data,
});
}
async delete(id: string) {
return await prisma.article.delete({
where: { id },
});
}
}
export default new NewsManager();