[resumes][feat] Add resume-comments type

pull/320/head
Terence Ho 3 years ago
parent 29ec081180
commit 17c68852c2

@ -2,6 +2,8 @@ import { z } from 'zod';
import { createRouter } from './context';
import type { ResumeComment } from '~/types/resume-comments';
export const resumeReviewsRouter = createRouter().query('list', {
input: z.object({
resumeId: z.string(),
@ -13,7 +15,7 @@ export const resumeReviewsRouter = createRouter().query('list', {
// 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
return await ctx.prisma.resumesComment.findMany({
const comments = await ctx.prisma.resumesComment.findMany({
include: {
_count: {
select: {
@ -40,5 +42,29 @@ export const resumeReviewsRouter = createRouter().query('list', {
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;
});
},
});

@ -1,11 +1,10 @@
import type { ResumesSection } from '@prisma/client';
declare module 'resume-comments' {
/**
/**
* Returned by `resumeReviewsRouter` (query for 'resumes.reviews.list') and received as prop by `Comment` in `CommentsList`
* frontend-friendly representation of the query
*/
type ResumeComment = {
export type ResumeComment = {
createdAt: Date;
description: string;
hasVoted: boolean;
@ -16,9 +15,8 @@ declare module 'resume-comments' {
section: ResumesSection;
updatedAt: Date;
user: {
image: string;
name: string;
image: string?;
name: string?;
userId: string;
};
};
}
};

Loading…
Cancel
Save