add save report modal

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-27 21:38:29 +02:00
parent ed7ed2ab24
commit a05f7933af
14 changed files with 296 additions and 56 deletions

View File

@@ -3,22 +3,48 @@ import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
import { db } from "@/server/db";
import { getProjectBySlug } from "@/server/services/project.service";
import { slug } from "@/utils/slug";
export const dashboardRouter = createTRPCRouter({
list: protectedProcedure
.input(
z.object({
organizationSlug: z.string(),
projectSlug: z.string(),
}),
z
.object({
projectSlug: z.string(),
})
.or(
z.object({
projectId: z.string(),
}),
),
)
.query(async ({ input: { projectSlug } }) => {
const project = await getProjectBySlug(projectSlug)
.query(async ({ input }) => {
let projectId = null;
if ("projectId" in input) {
projectId = input.projectId;
} else {
projectId = (await getProjectBySlug(input.projectSlug)).id;
}
return db.dashboard.findMany({
where: {
project_id: project.id,
project_id: projectId,
},
});
}),
create: protectedProcedure
.input(
z.object({
name: z.string(),
projectId: z.string(),
}),
)
.mutation(async ({ input: { projectId, name } }) => {
return db.dashboard.create({
data: {
slug: slug(name),
project_id: projectId,
name,
},
});
}),

View File

@@ -6,17 +6,19 @@ import { getOrganizationBySlug } from "@/server/services/organization.service";
export const projectRouter = createTRPCRouter({
list: protectedProcedure
.input(z.object({
organizationSlug: z.string()
}))
.query(async ({ input }) => {
const organization = await getOrganizationBySlug(input.organizationSlug)
return db.project.findMany({
where: {
organization_id: organization.id,
},
});
}),
.input(
z.object({
organizationSlug: z.string(),
}),
)
.query(async ({ input }) => {
const organization = await getOrganizationBySlug(input.organizationSlug);
return db.project.findMany({
where: {
organization_id: organization.id,
},
});
}),
get: protectedProcedure
.input(
z.object({
@@ -27,7 +29,6 @@ export const projectRouter = createTRPCRouter({
return db.project.findUniqueOrThrow({
where: {
id: input.id,
organization_id: "d433c614-69f9-443a-8961-92a662869929",
},
});
}),
@@ -42,7 +43,6 @@ export const projectRouter = createTRPCRouter({
return db.project.update({
where: {
id: input.id,
organization_id: "d433c614-69f9-443a-8961-92a662869929",
},
data: {
name: input.name,
@@ -53,17 +53,19 @@ export const projectRouter = createTRPCRouter({
.input(
z.object({
name: z.string(),
organizationSlug: z.string(),
}),
)
.mutation(({ input }) => {
.mutation(async ({ input }) => {
const organization = await getOrganizationBySlug(input.organizationSlug);
return db.project.create({
data: {
organization_id: "d433c614-69f9-443a-8961-92a662869929",
organization_id: organization.id,
name: input.name,
},
});
}),
remove: protectedProcedure
remove: protectedProcedure
.input(
z.object({
id: z.string(),
@@ -73,9 +75,8 @@ export const projectRouter = createTRPCRouter({
await db.project.delete({
where: {
id: input.id,
organization_id: "d433c614-69f9-443a-8961-92a662869929",
},
});
return true
return true;
}),
});