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

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

@ -71,24 +71,6 @@ export const SORT_OPTIONS: Array<FilterOption<SortOrder>> = [
{ label: 'Most Comments', value: 'mostComments' }, { 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> = [ export const EXPERIENCES: Array<TypeaheadOption> = [
{ {
id: 'internship', 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 = { export const INITIAL_FILTER_STATE: FilterState = {
experience: EXPERIENCES, experience: [],
isTop10: false, isTop10: false,
isUnreviewed: true, isUnreviewed: true,
location: INITIAL_LOCATIONS, location: [],
role: INITIAL_ROLES, role: [],
}; };
export const SHORTCUTS: Array<Shortcut> = [ export const SHORTCUTS: Array<Shortcut> = [

@ -37,3 +37,21 @@ export function resumeGetFilterCounts(data: Array<Resume>) {
role: roleCounts, 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