mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 13:13:54 +08:00
[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 <>
This commit is contained in:
@ -7,10 +7,7 @@ type ICommentsSectionProps = {
|
|||||||
resumeId: string;
|
resumeId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Retrieve resumeId for CommentsSection
|
export default function CommentsSection({ resumeId }: ICommentsSectionProps) {
|
||||||
export default function CommentsSection({
|
|
||||||
resumeId = '',
|
|
||||||
}: ICommentsSectionProps) {
|
|
||||||
const [showCommentsForm, setShowCommentsForm] = useState(false);
|
const [showCommentsForm, setShowCommentsForm] = useState(false);
|
||||||
|
|
||||||
return showCommentsForm ? (
|
return showCommentsForm ? (
|
||||||
|
@ -73,7 +73,8 @@ export default function ResumeReviewPage() {
|
|||||||
<ResumePdf />
|
<ResumePdf />
|
||||||
</div>
|
</div>
|
||||||
<div className="mx-8 w-1/2">
|
<div className="mx-8 w-1/2">
|
||||||
<CommentsSection resumeId="" />
|
{/* TODO: Update resumeId */}
|
||||||
|
<CommentsSection resumeId="cl8y6gtez0009yedbne9qp5zi" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
@ -7,9 +7,18 @@ export const resumeReviewsRouter = createRouter().query('list', {
|
|||||||
resumeId: z.string(),
|
resumeId: z.string(),
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const userId = ctx.session?.user?.id;
|
|
||||||
const { resumeId } = input;
|
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:
|
// For this resume, we retrieve every comment's information, along with:
|
||||||
// The user's name and image to render
|
// The user's name and image to render
|
||||||
// Number of votes, and whether the user (if-any) has voted
|
// Number of votes, and whether the user (if-any) has voted
|
||||||
@ -20,16 +29,20 @@ export const resumeReviewsRouter = createRouter().query('list', {
|
|||||||
votes: true,
|
votes: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
user: {
|
resumesProfile: {
|
||||||
select: {
|
include: {
|
||||||
image: true,
|
user: {
|
||||||
name: true,
|
select: {
|
||||||
|
image: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
votes: {
|
votes: {
|
||||||
take: 1,
|
take: 1,
|
||||||
where: {
|
where: {
|
||||||
userId,
|
resumesProfileId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -6,8 +6,8 @@ import { createProtectedRouter } from './context';
|
|||||||
type IResumeCommentInput = Readonly<{
|
type IResumeCommentInput = Readonly<{
|
||||||
description: string;
|
description: string;
|
||||||
resumeId: string;
|
resumeId: string;
|
||||||
|
resumesProfileId: string;
|
||||||
section: ResumesSection;
|
section: ResumesSection;
|
||||||
userId: string;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const resumesReviewsUserRouter = createProtectedRouter().mutation(
|
export const resumesReviewsUserRouter = createProtectedRouter().mutation(
|
||||||
@ -22,10 +22,19 @@ export const resumesReviewsUserRouter = createProtectedRouter().mutation(
|
|||||||
skills: z.string(),
|
skills: z.string(),
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const userId = ctx.session?.user.id;
|
|
||||||
const { resumeId, education, experience, general, projects, skills } =
|
const { resumeId, education, experience, general, projects, skills } =
|
||||||
input;
|
input;
|
||||||
|
|
||||||
|
const { resumesProfileId } =
|
||||||
|
await ctx.prisma.resumesResume.findUniqueOrThrow({
|
||||||
|
select: {
|
||||||
|
resumesProfileId: true,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: resumeId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// For each section, convert them into ResumesComment model if provided
|
// For each section, convert them into ResumesComment model if provided
|
||||||
const comments: Array<IResumeCommentInput> = [
|
const comments: Array<IResumeCommentInput> = [
|
||||||
{ description: education, section: ResumesSection.EDUCATION },
|
{ description: education, section: ResumesSection.EDUCATION },
|
||||||
@ -41,8 +50,8 @@ export const resumesReviewsUserRouter = createProtectedRouter().mutation(
|
|||||||
return {
|
return {
|
||||||
description,
|
description,
|
||||||
resumeId,
|
resumeId,
|
||||||
|
resumesProfileId,
|
||||||
section,
|
section,
|
||||||
userId,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user