projects overview and event list improvements

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-09 21:53:40 +01:00
parent 79d2368cfc
commit faafb71d88
16 changed files with 585 additions and 59 deletions

View File

@@ -1,30 +1,35 @@
import type { Project } from '../prisma-client';
import { db } from '../prisma-client';
export type IServiceProject = Awaited<ReturnType<typeof getProjectById>>;
export type IServiceProject = ReturnType<typeof transform>;
export function getProjectById(id: string) {
return db.project.findUnique({
function transform({ organization_slug, ...project }: Project) {
return {
organizationSlug: organization_slug,
...project,
};
}
export async function getProjectById(id: string) {
const res = await db.project.findUnique({
where: {
id,
},
});
if (!res) {
return null;
}
return transform(res);
}
export function getProjectsByOrganizationSlug(slug: string) {
return db.project.findMany({
export async function getProjectsByOrganizationSlug(slug: string) {
const res = await db.project.findMany({
where: {
organization_slug: slug,
},
});
}
export async function getProjectWithMostEvents(slug: string) {
return db.project.findFirst({
where: {
organization_slug: slug,
},
orderBy: {
eventsCount: 'desc',
},
});
return res.map(transform);
}