|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
import { z } from 'zod';
|
|
|
|
|
import { Vote } from '@prisma/client';
|
|
|
|
|
|
|
|
|
|
import { EXPERIENCES, LOCATIONS, ROLES } from '~/utils/resumes/resumeFilters';
|
|
|
|
|
|
|
|
|
|
import { createRouter } from '../context';
|
|
|
|
|
|
|
|
|
|
import type { Resume } from '~/types/resume';
|
|
|
|
@ -251,4 +253,72 @@ export const resumesRouter = createRouter()
|
|
|
|
|
|
|
|
|
|
return topUpvotedCommentCount;
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.query('getTotalFilterCounts', {
|
|
|
|
|
async resolve({ ctx }) {
|
|
|
|
|
const roleCounts = await ctx.prisma.resumesResume.groupBy({
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
by: ['role'],
|
|
|
|
|
});
|
|
|
|
|
const mappedRoleCounts = Object.fromEntries(
|
|
|
|
|
roleCounts.map((rc) => [rc.role, rc._count._all]),
|
|
|
|
|
);
|
|
|
|
|
const zeroRoleCounts = Object.fromEntries(
|
|
|
|
|
ROLES.filter((r) => !(r.value in mappedRoleCounts)).map((r) => [
|
|
|
|
|
r.value,
|
|
|
|
|
0,
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
const processedRoleCounts = {
|
|
|
|
|
...mappedRoleCounts,
|
|
|
|
|
...zeroRoleCounts,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const experienceCounts = await ctx.prisma.resumesResume.groupBy({
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
by: ['experience'],
|
|
|
|
|
});
|
|
|
|
|
const mappedExperienceCounts = Object.fromEntries(
|
|
|
|
|
experienceCounts.map((ec) => [ec.experience, ec._count._all]),
|
|
|
|
|
);
|
|
|
|
|
const zeroExperienceCounts = Object.fromEntries(
|
|
|
|
|
EXPERIENCES.filter((e) => !(e.value in mappedExperienceCounts)).map(
|
|
|
|
|
(e) => [e.value, 0],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
const processedExperienceCounts = {
|
|
|
|
|
...mappedExperienceCounts,
|
|
|
|
|
...zeroExperienceCounts,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const locationCounts = await ctx.prisma.resumesResume.groupBy({
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
by: ['location'],
|
|
|
|
|
});
|
|
|
|
|
const mappedLocationCounts = Object.fromEntries(
|
|
|
|
|
locationCounts.map((lc) => [lc.location, lc._count._all]),
|
|
|
|
|
);
|
|
|
|
|
const zeroLocationCounts = Object.fromEntries(
|
|
|
|
|
LOCATIONS.filter((l) => !(l.value in mappedLocationCounts)).map((l) => [
|
|
|
|
|
l.value,
|
|
|
|
|
0,
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
const processedLocationCounts = {
|
|
|
|
|
...mappedLocationCounts,
|
|
|
|
|
...zeroLocationCounts,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
Experience: processedExperienceCounts,
|
|
|
|
|
Location: processedLocationCounts,
|
|
|
|
|
Role: processedRoleCounts,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|