[resumes][fix] update vote query (#436)

* [resumes][fix] update vote query

* [resumes][fix] lint issues

Co-authored-by: Terence Ho <>
pull/437/head
Terence 2 years ago committed by GitHub
parent 248c1e3584
commit b3d110f90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,4 @@
import { z } from 'zod';
import type { ResumesCommentVote } from '@prisma/client';
import { Vote } from '@prisma/client';
import { createRouter } from '../context';
@ -20,13 +19,13 @@ export const resumesCommentsVotesRouter = createRouter().query('list', {
},
});
let userVote: ResumesCommentVote | null = null;
let numVotes = 0;
votes.forEach((vote) => {
numVotes += vote.value === Vote.UPVOTE ? 1 : -1;
userVote = vote.userId === userId ? vote : null;
});
const userVotes = votes.filter((vote) => vote.userId === userId);
const userVote = userVotes.length > 0 ? userVotes[0] : null;
const numVotes = votes
.map((vote) => (vote.value === Vote.UPVOTE ? 1 : -1))
.reduce((result, current) => {
return result + current;
}, 0);
const resumeCommentVote: ResumeCommentVote = {
numVotes,

Loading…
Cancel
Save