Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GoalSuggest): search query params #1295

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,25 @@ import { addCalculatedProjectFields } from './project';
export const goal = router({
suggestions: protectedProcedure.input(suggestionsQueryScheme).query(async ({ input }) => {
const splittedInput = input.input.split('-');
let selectParams = {};
let selectParams: Prisma.GoalFindManyArgs['where'] = {
title: {
contains: input.input,
mode: 'insensitive',
},
};

if (splittedInput.length === 2 && Number.isNaN(+splittedInput[1])) {
if (splittedInput.length === 2 && !Number.isNaN(+splittedInput[1])) {
const [projectId, scopedId] = splittedInput;
selectParams = {
AND: [
{
projectId: {
contains: splittedInput[0],
contains: projectId,
mode: 'insensitive',
},
},
{
scopeId: {
contains: splittedInput[1],
mode: 'insensitive',
},
scopeId: Number(scopedId),
},
],
};
Expand All @@ -65,16 +68,8 @@ export const goal = router({
return prisma.goal.findMany({
take: input.limit || 5,
where: {
OR: [
selectParams,
{
title: {
contains: input.input,
mode: 'insensitive',
},
},
],
AND: {
...selectParams,
OR: [
{
archived: false,
Expand Down
Loading