diff --git a/apps/portal/src/pages/resumes/[resumeId].tsx b/apps/portal/src/pages/resumes/[resumeId].tsx index a9d2b49d..5a13a1c3 100644 --- a/apps/portal/src/pages/resumes/[resumeId].tsx +++ b/apps/portal/src/pages/resumes/[resumeId].tsx @@ -29,10 +29,7 @@ export default function ResumeReviewPage() { const utils = trpc.useContext(); // Safe to assert resumeId type as string because query is only sent if so const detailsQuery = trpc.useQuery( - [ - 'resumes.details.find', - { resumeId: resumeId as string, userId: session?.user?.id }, - ], + ['resumes.details.find', { resumeId: resumeId as string }], { enabled: typeof resumeId === 'string' && session?.user?.id !== undefined, }, @@ -56,7 +53,6 @@ export default function ResumeReviewPage() { // Star button only clickable if user exists starMutation.mutate({ resumeId: resumeId as string, - userId: session!.user!.id!, }); }; diff --git a/apps/portal/src/server/router/resumes-details-router.ts b/apps/portal/src/server/router/resumes-details-router.ts index b5ea3dbb..1255ac2e 100644 --- a/apps/portal/src/server/router/resumes-details-router.ts +++ b/apps/portal/src/server/router/resumes-details-router.ts @@ -6,10 +6,10 @@ export const resumesDetailsRouter = createRouter() .query('find', { input: z.object({ resumeId: z.string(), - userId: z.string().optional(), }), async resolve({ ctx, input }) { - const { resumeId, userId } = input; + const { resumeId } = input; + const userId = ctx.session?.user?.id; // Use the resumeId to query all related information of a single resume // from Resumesresume: @@ -40,10 +40,11 @@ export const resumesDetailsRouter = createRouter() .mutation('update_star', { input: z.object({ resumeId: z.string(), - userId: z.string(), }), async resolve({ ctx, input }) { - const { resumeId, userId } = input; + const { resumeId } = input; + // Update_star will only be called if user is logged in + const userId = ctx.session!.user!.id; // Use the resumeId and resumeProfileId to check if star exists const resumesStar = await ctx.prisma.resumesStar.findUnique({ diff --git a/apps/portal/src/server/router/resumes-resume-user-router.ts b/apps/portal/src/server/router/resumes-resume-user-router.ts index e4962d0b..9f014795 100644 --- a/apps/portal/src/server/router/resumes-resume-user-router.ts +++ b/apps/portal/src/server/router/resumes-resume-user-router.ts @@ -15,23 +15,12 @@ export const resumesResumeUserRouter = createProtectedRouter().mutation( }), async resolve({ ctx, input }) { const userId = ctx.session?.user.id; - const resumeProfile = await ctx.prisma.resumesProfile.upsert({ - create: { - userId, - }, - update: {}, - where: { - userId, - }, - }); - // TODO: Store file in file storage and retrieve URL - return await ctx.prisma.resumesResume.create({ data: { ...input, - resumesProfileId: resumeProfile.id, url: '', + userId, }, }); }, diff --git a/apps/portal/src/server/router/resumes-reviews-router.ts b/apps/portal/src/server/router/resumes-reviews-router.ts index 2f983c92..8e681326 100644 --- a/apps/portal/src/server/router/resumes-reviews-router.ts +++ b/apps/portal/src/server/router/resumes-reviews-router.ts @@ -7,18 +7,9 @@ export const resumeReviewsRouter = createRouter().query('list', { resumeId: z.string(), }), async resolve({ ctx, input }) { + const userId = ctx.session?.user?.id; const { resumeId } = input; - const { resumesProfileId } = - await ctx.prisma.resumesResume.findUniqueOrThrow({ - select: { - resumesProfileId: true, - }, - where: { - id: resumeId, - }, - }); - // For this resume, we retrieve every comment's information, along with: // The user's name and image to render // Number of votes, and whether the user (if-any) has voted @@ -29,20 +20,16 @@ export const resumeReviewsRouter = createRouter().query('list', { votes: true, }, }, - resumesProfile: { - include: { - user: { - select: { - image: true, - name: true, - }, - }, + user: { + select: { + image: true, + name: true, }, }, votes: { take: 1, where: { - resumesProfileId, + userId, }, }, }, diff --git a/apps/portal/src/server/router/resumes-reviews-user-router.ts b/apps/portal/src/server/router/resumes-reviews-user-router.ts index b13e2a00..5730887f 100644 --- a/apps/portal/src/server/router/resumes-reviews-user-router.ts +++ b/apps/portal/src/server/router/resumes-reviews-user-router.ts @@ -6,8 +6,8 @@ import { createProtectedRouter } from './context'; type IResumeCommentInput = Readonly<{ description: string; resumeId: string; - resumesProfileId: string; section: ResumesSection; + userId: string; }>; export const resumesReviewsUserRouter = createProtectedRouter().mutation( @@ -22,19 +22,10 @@ export const resumesReviewsUserRouter = createProtectedRouter().mutation( skills: z.string(), }), async resolve({ ctx, input }) { + const userId = ctx.session?.user?.id; const { resumeId, education, experience, general, projects, skills } = input; - const { resumesProfileId } = - await ctx.prisma.resumesResume.findUniqueOrThrow({ - select: { - resumesProfileId: true, - }, - where: { - id: resumeId, - }, - }); - // For each section, convert them into ResumesComment model if provided const comments: Array = [ { description: education, section: ResumesSection.EDUCATION }, @@ -50,8 +41,8 @@ export const resumesReviewsUserRouter = createProtectedRouter().mutation( return { description, resumeId, - resumesProfileId, section, + userId, }; });