[resumes][refactor] Change to ResumesProfile schema (#318)

* [resumes][chore] Update TODOs

* [resumes][refactor] Change to new schema

* [resumes][refactor] Change query to findUniqueOrThrow

Co-authored-by: Terence Ho <>
pull/324/head
Terence 2 years ago committed by GitHub
parent 702811bafa
commit 1146c5db40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,10 +7,7 @@ type ICommentsSectionProps = {
resumeId: string;
};
// TODO: Retrieve resumeId for CommentsSection
export default function CommentsSection({
resumeId = '',
}: ICommentsSectionProps) {
export default function CommentsSection({ resumeId }: ICommentsSectionProps) {
const [showCommentsForm, setShowCommentsForm] = useState(false);
return showCommentsForm ? (

@ -73,7 +73,8 @@ export default function ResumeReviewPage() {
<ResumePdf />
</div>
<div className="mx-8 w-1/2">
<CommentsSection resumeId="" />
{/* TODO: Update resumeId */}
<CommentsSection resumeId="cl8y6gtez0009yedbne9qp5zi" />
</div>
</div>
</main>

@ -7,9 +7,18 @@ 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
@ -20,16 +29,20 @@ export const resumeReviewsRouter = createRouter().query('list', {
votes: true,
},
},
user: {
select: {
image: true,
name: true,
resumesProfile: {
include: {
user: {
select: {
image: true,
name: true,
},
},
},
},
votes: {
take: 1,
where: {
userId,
resumesProfileId,
},
},
},

@ -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,10 +22,19 @@ 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<IResumeCommentInput> = [
{ description: education, section: ResumesSection.EDUCATION },
@ -41,8 +50,8 @@ export const resumesReviewsUserRouter = createProtectedRouter().mutation(
return {
description,
resumeId,
resumesProfileId,
section,
userId,
};
});

Loading…
Cancel
Save