mirror of
https://github.com/BillyOutlast/drop.git
synced 2026-02-04 08:41:17 +01:00
* feat: nginx + torrential basics & services system * fix: lint + i18n * fix: update torrential to remove openssl * feat: add torrential to Docker build * feat: move to self hosted runner * fix: move off self-hosted runner * fix: update nginx.conf * feat: torrential cache invalidation * fix: update torrential for cache invalidation * feat: integrity check task * fix: lint * feat: move to version ids * fix: client fixes and client-side checks * feat: new depot apis and version id fixes * feat: update torrential * feat: droplet bump and remove unsafe update functions * fix: lint * feat: v4 featureset: emulators, multi-launch commands * fix: lint * fix: mobile ui for game editor * feat: launch options * fix: lint * fix: remove axios, use $fetch * feat: metadata and task api improvements * feat: task actions * fix: slight styling issue * feat: fix style and lints * feat: totp backend routes * feat: oidc groups * fix: update drop-base * feat: creation of passkeys & totp * feat: totp signin * feat: webauthn mfa/signin * feat: launch selecting ui * fix: manually running tasks * feat: update add company game modal to use new SelectorGame * feat: executor selector * fix(docker): update rust to rust nightly for torrential build (#305) * feat: new version ui * feat: move package lookup to build time to allow for deno dev * fix: lint * feat: localisation cleanup * feat: apply localisation cleanup * feat: potential i18n refactor logic * feat: remove args from commands * fix: lint * fix: lockfile --------- Co-authored-by: Aden Lindsay <140392385+AdenMGB@users.noreply.github.com>
143 lines
3.0 KiB
TypeScript
143 lines
3.0 KiB
TypeScript
import prisma from "../db/database";
|
|
import objectHandler from "../objects";
|
|
|
|
class NewsManager {
|
|
async create(data: {
|
|
title: string;
|
|
content: string;
|
|
description: string;
|
|
tags: string[];
|
|
authorId: string;
|
|
imageObjectId?: 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 },
|
|
})),
|
|
},
|
|
|
|
...(data.imageObjectId && { imageObjectId: data.imageObjectId }),
|
|
author: {
|
|
connect: {
|
|
id: data.authorId,
|
|
},
|
|
},
|
|
},
|
|
include: {
|
|
author: {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
},
|
|
},
|
|
tags: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
async fetch(
|
|
options: {
|
|
take?: number;
|
|
skip?: number;
|
|
orderBy?: "asc" | "desc";
|
|
tags?: string[];
|
|
search?: string;
|
|
} = {},
|
|
) {
|
|
return await prisma.article.findMany({
|
|
where: {
|
|
AND: [
|
|
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,
|
|
orderBy: {
|
|
publishedAt: options?.orderBy || "desc",
|
|
},
|
|
include: {
|
|
author: {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
},
|
|
},
|
|
tags: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
async fetchById(id: string) {
|
|
return await prisma.article.findUnique({
|
|
where: { id },
|
|
include: {
|
|
author: {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
},
|
|
},
|
|
tags: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
async update(
|
|
id: string,
|
|
data: {
|
|
title?: string;
|
|
content?: string;
|
|
excerpt?: string;
|
|
image?: string;
|
|
},
|
|
) {
|
|
return (
|
|
await prisma.article.updateManyAndReturn({
|
|
where: { id },
|
|
data,
|
|
})
|
|
).at(0);
|
|
}
|
|
|
|
async delete(id: string) {
|
|
const article = await prisma.article.findUnique({ where: { id } });
|
|
if (!article) return false;
|
|
// eslint-disable-next-line drop/no-prisma-delete
|
|
await prisma.article.delete({
|
|
where: { id },
|
|
});
|
|
if (article.imageObjectId) {
|
|
return await objectHandler.deleteAsSystem(article.imageObjectId);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
export default new NewsManager();
|