Skip to content

Commit

Permalink
Add trpc routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciszkoo committed Apr 16, 2024
1 parent bed3424 commit c1d889f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions apps/web/src/server/api/routers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { eq } from "drizzle-orm";
import { createSelectSchema } from "drizzle-zod";
import { z } from "zod";

import {
createProjectSchema,
editProjectSchema,
} from "~/lib/validators/project";
import { projects } from "~/server/db/schema";

import { createTRPCRouter, protectedProcedure } from "../trpc";
Expand All @@ -21,15 +25,42 @@ export const projectRouter = createTRPCRouter({
getProjectDetails: protectedProcedure
.input(z.object({ projId: z.number() }))
.query(async ({ ctx, input }) => {
return await ctx.db
const details = await ctx.db
.select()
.from(projects)
.where(eq(projects.id, input.projId));

return details[0];
}),

createProject: protectedProcedure
.input(projectSchema)
.input(createProjectSchema)
.mutation(async ({ ctx, input }) => {
return await ctx.db
.insert(projects)
.values(input)
.returning({ id: projects.id });
}),

editProject: protectedProcedure
.input(editProjectSchema)
.mutation(async ({ ctx, input }) => {
await ctx.db.insert(projects).values(input);
return ctx.db
.update(projects)
.set({
projectName: input.projectName,
projectDescription: input.projectDescription,
title: input.title,
description: input.description,
categoryId: input.categoryId,
defaultLanguage: input.defaultLanguage,
embeddable: input.embeddable,
license: input.license,
privacyStatus: input.privacyStatus,
publicStatsViewable: input.publicStatsViewable,
publishAt: input.publishAt?.toString(),
selfDeclaredMadeForKids: input.selfDeclaredMadeForKids,
})
.where(eq(projects.id, input.id));
}),
});

0 comments on commit c1d889f

Please sign in to comment.