Skip to content

Commit

Permalink
chore: request returns last 5 created goals of the user if nthg is ty…
Browse files Browse the repository at this point in the history
…ping
  • Loading branch information
DenisVorop committed Jul 25, 2023
1 parent 1abcd38 commit a0c0055
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/components/CriteriaForm/CriteriaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const CriteriaForm: React.FC<CriteriaFormProps> = ({ onSubmit, goalId, va
setError={setError}
onSelect={handleSelectGoal}
titles={validityData.title}
isItemSelected={selectedGoalId != null}
isItemSelected={Boolean(selectedGoalId?.id)}
/>
)}
/>
Expand Down
84 changes: 46 additions & 38 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,60 @@ import { createLocaleDate } from '../../src/utils/dateTime';
import { addCalculatedProjectFields } from './project';

export const goal = router({
suggestions: protectedProcedure.input(suggestionsQueryScheme).query(async ({ input }) => {
const splittedInput = input.input.split('-');
let selectParams: Prisma.GoalFindManyArgs['where'] = {
title: {
contains: input.input,
mode: 'insensitive',
},
};

if (splittedInput.length === 2 && !Number.isNaN(+splittedInput[1])) {
const [projectId, scopedId] = splittedInput;
selectParams = {
AND: [
{
projectId: {
contains: projectId,
mode: 'insensitive',
},
},
{
scopeId: Number(scopedId),
},
],
suggestions: protectedProcedure
.input(suggestionsQueryScheme)
.query(async ({ ctx, input: { input, limit = 5 } }) => {
const { activityId } = ctx.session.user || {};

const splittedInput = input.split('-');
let selectParams: Prisma.GoalFindManyArgs['where'] = {
title: {
contains: input,
mode: 'insensitive',
},
};
}

return prisma.goal.findMany({
take: input.limit || 5,
where: {
AND: {
...selectParams,
OR: [
if (splittedInput.length === 2 && !Number.isNaN(+splittedInput[1])) {
const [projectId, scopedId] = splittedInput;
selectParams = {
AND: [
{
archived: false,
projectId: {
contains: projectId,
mode: 'insensitive',
},
},
{
archived: null,
scopeId: Number(scopedId),
},
],
};
}

return prisma.goal.findMany({
take: limit,
orderBy: {
createdAt: 'desc',
},
},
include: {
...goalDeepQuery,
},
});
}),
where: {
activityId: input.length ? { contains: '' } : activityId,
AND: {
...selectParams,
OR: [
{
archived: false,
},
{
archived: null,
},
],
},
},
include: {
...goalDeepQuery,
},
});
}),
getBatch: protectedProcedure
.input(
z.object({
Expand Down

0 comments on commit a0c0055

Please sign in to comment.