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);
}

View File

@@ -60,16 +60,16 @@ export const zMetric = z.enum(objectToZodEnums(metrics));
export const zRange = z.enum(objectToZodEnums(timeRanges));
export const zChartInput = z.object({
name: z.string(),
chartType: zChartType,
lineType: zLineType,
interval: zTimeInterval,
name: z.string().default(''),
chartType: zChartType.default('linear'),
lineType: zLineType.default('monotone'),
interval: zTimeInterval.default('day'),
events: zChartEvents,
breakdowns: zChartBreakdowns,
range: zRange,
previous: z.boolean(),
breakdowns: zChartBreakdowns.default([]),
range: zRange.default('1m'),
previous: z.boolean().default(false),
formula: z.string().optional(),
metric: zMetric,
metric: zMetric.default('sum'),
unit: z.string().optional(),
previousIndicatorInverted: z.boolean().optional(),
projectId: z.string(),