Skip to content
3 changes: 2 additions & 1 deletion src/server/api/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { leetcodeRouter } from "~/server/api/routers/leetcode";
import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc";
import { weekRouter } from "./routers/week";
import { problemRouter } from "./routers/problem";

import { profileRouter } from "./routers/profile";
/**
* This is the primary router for your server.
*
Expand All @@ -12,6 +12,7 @@ export const appRouter = createTRPCRouter({
leetcode: leetcodeRouter,
week: weekRouter,
problem : problemRouter,
profile : profileRouter,
});

// export type definition of API
Expand Down
20 changes: 20 additions & 0 deletions src/server/api/routers/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "../trpc";
// import { Prisma } from "@prisma/client";

export const profileRouter = createTRPCRouter({
getById: protectedProcedure.input(z.string()).query(async ({ ctx, input }) => {
return ctx.db.user.findUnique({ where: { id: input }, include: { accounts: true, sessions: false, solvedProblems: true } });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an await so that you don't return a promise

}),
update: protectedProcedure
.input(z.object({
id: z.string(),
name: z.string().optional(),
email: z.string().url().optional(),
image: z.string().optional(),
}))
.mutation(async ({ ctx, input }) => {
const { id, ...data } = input;
return ctx.db.user.update({ where: { id }, data });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add an await here

}),
});