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

Incorrect goals filtering on dashboard #1537

Merged
merged 1 commit into from
Aug 15, 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
63 changes: 58 additions & 5 deletions trpc/router/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ export const project = router({
];
};

const requestSchemaWithoutOwner = requestSchema({ withOwner: false });
const projectIds = await prisma.project.findMany({
where: {
OR: [
...requestSchemaWithoutOwner,
{
parent: {
some: {
OR: requestSchemaWithoutOwner,
},
},
},
],
},
select: {
id: true,
},
});
const projectIdsArray = projectIds.map(({ id }) => id);

const nonArchived = {
archived: false,
};

const res = await prisma.project
.findMany({
orderBy: {
Expand All @@ -168,24 +192,53 @@ export const project = router({
goals: {
// all goals with filters
where: {
AND: [input ? { ...goalsFilter(input, activityId).where } : {}],
AND: [
input ? { ...goalsFilter(input, activityId).where } : {},
{
OR: [
...requestSchema({ withOwner: true }),
{
projectId: {
in: projectIdsArray,
},
},
],
},
nonArchived,
],
},
include: goalDeepQuery,
},
_count: {
select: {
// all goals without filters to count the total goals
goals: {
where: {
archived: false,
},
where: nonArchived,
},
},
},
},
where: {
// all projects where the user is a participant / watcher / issuer / stargizer
OR: requestSchema({ withOwner: false }),
OR: [
{
id: {
in: projectIdsArray,
},
},
{
goals: {
some: {
AND: [
{
OR: requestSchema({ withOwner: true }),
},
nonArchived,
],
},
},
},
],
},
})
.then((res) => ({
Expand Down
Loading