|
|
@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
|
|
|
|
|
|
|
|
|
|
import { createRouter } from './context';
|
|
|
|
import { createRouter } from './context';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import type { ResumeComment } from '~/types/resume-comments';
|
|
|
|
|
|
|
|
|
|
|
|
export const resumeReviewsRouter = createRouter().query('list', {
|
|
|
|
export const resumeReviewsRouter = createRouter().query('list', {
|
|
|
|
input: z.object({
|
|
|
|
input: z.object({
|
|
|
|
resumeId: z.string(),
|
|
|
|
resumeId: z.string(),
|
|
|
@ -13,7 +15,7 @@ export const resumeReviewsRouter = createRouter().query('list', {
|
|
|
|
// 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
|
|
|
|
return await ctx.prisma.resumesComment.findMany({
|
|
|
|
const comments = await ctx.prisma.resumesComment.findMany({
|
|
|
|
include: {
|
|
|
|
include: {
|
|
|
|
_count: {
|
|
|
|
_count: {
|
|
|
|
select: {
|
|
|
|
select: {
|
|
|
@ -40,5 +42,29 @@ export const resumeReviewsRouter = createRouter().query('list', {
|
|
|
|
resumeId,
|
|
|
|
resumeId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return comments.map((data) => {
|
|
|
|
|
|
|
|
const hasVoted = data.votes.length > 0;
|
|
|
|
|
|
|
|
const numVotes = data._count.votes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const comment: ResumeComment = {
|
|
|
|
|
|
|
|
createdAt: data.createdAt,
|
|
|
|
|
|
|
|
description: data.description,
|
|
|
|
|
|
|
|
hasVoted,
|
|
|
|
|
|
|
|
id: data.id,
|
|
|
|
|
|
|
|
numVotes,
|
|
|
|
|
|
|
|
resumeId: data.resumeId,
|
|
|
|
|
|
|
|
resumesProfileId: data.resumesProfileId,
|
|
|
|
|
|
|
|
section: data.section,
|
|
|
|
|
|
|
|
updatedAt: data.updatedAt,
|
|
|
|
|
|
|
|
user: {
|
|
|
|
|
|
|
|
image: data.resumesProfile.user.image,
|
|
|
|
|
|
|
|
name: data.resumesProfile.user.name,
|
|
|
|
|
|
|
|
userId: data.resumesProfile.userId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return comment;
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|