[resumes][feat] add queries for resume badges

pull/399/head
Keane Chan 3 years ago
parent 8e3f8ab604
commit f6973a2c96
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -13,6 +13,7 @@ import { Button, TextArea } from '@tih/ui';
import { trpc } from '~/utils/trpc';
import ResumeUserBadges from './ResumeUserBadges';
import ResumeExpandableText from '../shared/ResumeExpandableText';
import type { ResumeComment } from '~/types/resume-comments';
@ -152,13 +153,15 @@ export default function ResumeCommentListItem({
{/* Name and creation time */}
<div className="flex flex-row justify-between">
<div className="flex flex-row items-center space-x-1">
<div className="font-medium">
<p className="font-medium">
{comment.user.name ?? 'Reviewer ABC'}
</div>
</p>
<div className="text-primary-800 text-xs font-medium">
<p className="text-primary-800 text-xs font-medium">
{isCommentOwner ? '(Me)' : ''}
</div>
</p>
<ResumeUserBadges userId={comment.user.userId} />
</div>
<div className="px-2 text-xs text-gray-600">

@ -0,0 +1,61 @@
import { Badge } from '@tih/ui';
import { trpc } from '~/utils/trpc';
type Props = {
userId: string;
};
type BadgeInfo = {
description: string;
id: string;
isValid: (userId: string) => boolean;
label: string;
};
const badges: Array<BadgeInfo> = [
{
description: 'User has reviewed over 50 resumes',
id: 'VeteranReviewer',
isValid: (userId: string) => {
const userReviewedResumesCountQuery = trpc.useQuery([
'resumes.resume.findUserReviewedResumeCount',
{ userId },
]);
return (
userReviewedResumesCountQuery.data != null &&
userReviewedResumesCountQuery.data >= 5
);
},
label: 'Veteran',
},
{
description: 'User has reviewed over 50 resumes',
id: 'NoviceReviewer',
isValid: (userId: string) => {
const userReviewedResumesCountQuery = trpc.useQuery([
'resumes.resume.findUserReviewedResumeCount',
{ userId },
]);
return (
userReviewedResumesCountQuery.data != null &&
userReviewedResumesCountQuery.data >= 2
);
},
label: 'Veteran',
},
];
export default function ResumeUserBadges({ userId }: Props) {
return (
<>
{badges
.filter((badge) => badge.isValid(userId))
.map((badge) => (
<Badge key={badge.id} label={badge.label} variant="primary" />
))}
</>
);
}

@ -138,4 +138,32 @@ export const resumesRouter = createRouter()
},
});
},
})
.query('findUserReviewedResumeCount', {
input: z.object({
userId: z.string(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.resumesResume.count({
where: {
comments: {
some: {
userId: input.userId,
},
},
},
});
},
})
.query('findUserStarredResumeCount', {
input: z.object({
userId: z.string(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.resumesResume.findMany({
where: {
userId: input.userId,
},
});
},
});

Loading…
Cancel
Save