[resumes][feat] show all resumes when no filters selected (#535)

pull/536/head
Peirong 2 years ago committed by GitHub
parent a225b9ba93
commit c1bdc53730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,10 @@ import { z } from 'zod';
import { Vote } from '@prisma/client';
import type { FilterCounts } from '~/utils/resumes/resumeFilters';
import { resumeGetFilterCounts } from '~/utils/resumes/resumeGetFilterCounts';
import {
getWhereClauseFilters,
resumeGetFilterCounts,
} from '~/utils/resumes/resumePrismaUtils';
import { createRouter } from '../context';
@ -79,10 +82,12 @@ export const resumesRouter = createRouter()
skip: isTop10 ? 0 : skip,
take,
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
});
@ -111,10 +116,12 @@ export const resumesRouter = createRouter()
} else {
totalRecords = await ctx.prisma.resumesResume.count({
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
});
@ -126,9 +133,8 @@ export const resumesRouter = createRouter()
},
by: ['role'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, [], locationFilters),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
});
@ -145,8 +151,7 @@ export const resumesRouter = createRouter()
by: ['experience'],
where: {
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
...getWhereClauseFilters([], roleFilters, locationFilters),
title: { contains: searchValue, mode: 'insensitive' },
},
});
@ -160,9 +165,8 @@ export const resumesRouter = createRouter()
},
by: ['locationId'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, roleFilters, []),
isResolved: isUnreviewed ? false : {},
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
});

@ -1,7 +1,10 @@
import { z } from 'zod';
import type { FilterCounts } from '~/utils/resumes/resumeFilters';
import { resumeGetFilterCounts } from '~/utils/resumes/resumeGetFilterCounts';
import {
getWhereClauseFilters,
resumeGetFilterCounts,
} from '~/utils/resumes/resumePrismaUtils';
import { createProtectedRouter } from '../context';
@ -141,10 +144,12 @@ export const resumesResumeUserRouter = createProtectedRouter()
take,
where: {
resume: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
userId,
@ -177,10 +182,12 @@ export const resumesResumeUserRouter = createProtectedRouter()
totalRecords = await ctx.prisma.resumesStar.count({
where: {
resume: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
},
userId,
@ -193,9 +200,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['role'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, [], locationFilters),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
stars: {
some: {
userId,
@ -214,9 +220,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['experience'],
where: {
...getWhereClauseFilters([], roleFilters, locationFilters),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
stars: {
some: {
userId,
@ -235,9 +240,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['locationId'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, roleFilters, []),
isResolved: isUnreviewed ? false : {},
role: { in: roleFilters },
stars: {
some: {
userId,
@ -328,10 +332,12 @@ export const resumesResumeUserRouter = createProtectedRouter()
skip: isTop10 ? 0 : skip,
take,
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
userId,
},
@ -361,10 +367,12 @@ export const resumesResumeUserRouter = createProtectedRouter()
} else {
totalRecords = await ctx.prisma.resumesResume.count({
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(
experienceFilters,
roleFilters,
locationFilters,
),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
userId,
},
@ -376,9 +384,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['role'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, [], locationFilters),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
title: { contains: searchValue, mode: 'insensitive' },
userId,
},
@ -393,9 +400,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['experience'],
where: {
...getWhereClauseFilters([], roleFilters, locationFilters),
isResolved: isUnreviewed ? false : {},
locationId: { in: locationFilters },
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
userId,
},
@ -410,9 +416,8 @@ export const resumesResumeUserRouter = createProtectedRouter()
},
by: ['locationId'],
where: {
experience: { in: experienceFilters },
...getWhereClauseFilters(experienceFilters, roleFilters, []),
isResolved: isUnreviewed ? false : {},
role: { in: roleFilters },
title: { contains: searchValue, mode: 'insensitive' },
userId,
},

@ -71,24 +71,6 @@ export const SORT_OPTIONS: Array<FilterOption<SortOrder>> = [
{ label: 'Most Comments', value: 'mostComments' },
];
const INITIAL_ROLES_VALUES: Array<JobTitleType> = [
'software-engineer',
'back-end-engineer',
'front-end-engineer',
'full-stack-engineer',
'ios-engineer',
'android-engineer',
'data-engineer',
];
export const INITIAL_ROLES: Array<TypeaheadOption> = INITIAL_ROLES_VALUES.map(
(value) =>
getTypeaheadOption('role', value) ?? {
id: value,
label: value,
value,
},
);
export const EXPERIENCES: Array<TypeaheadOption> = [
{
id: 'internship',
@ -112,45 +94,12 @@ export const EXPERIENCES: Array<TypeaheadOption> = [
},
];
export const INITIAL_LOCATIONS: Array<TypeaheadOption> = [
{
id: '196',
label: 'Singapore',
value: '196',
},
{
id: '101',
label: 'India',
value: '101',
},
{
id: '231',
label: 'United States',
value: '231',
},
{
id: '230',
label: 'United Kingdom',
value: '230',
},
{
id: '102',
label: 'Indonesia',
value: '102',
},
{
id: '44',
label: 'China',
value: '44',
},
];
export const INITIAL_FILTER_STATE: FilterState = {
experience: EXPERIENCES,
experience: [],
isTop10: false,
isUnreviewed: true,
location: INITIAL_LOCATIONS,
role: INITIAL_ROLES,
location: [],
role: [],
};
export const SHORTCUTS: Array<Shortcut> = [

@ -37,3 +37,21 @@ export function resumeGetFilterCounts(data: Array<Resume>) {
role: roleCounts,
};
}
export const getWhereClauseFilters = (
experienceFilters: Array<string>,
roleFilters: Array<string>,
locationFilters: Array<string>,
) => {
return {
...(experienceFilters.length > 0 && {
experience: { in: experienceFilters },
}),
...(roleFilters.length > 0 && {
role: { in: roleFilters },
}),
...(locationFilters.length > 0 && {
locationId: { in: locationFilters },
}),
};
};
Loading…
Cancel
Save