mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
fix: filter document stats by folder (#2083)
This pull request refactors the filtering logic in the `getTeamCounts` function within `get-stats.ts` to improve consistency and maintainability. The main change is the consolidation of multiple filter conditions into a single `AND` clause, which now includes search filters, folder filters, and visibility filters. This ensures that all relevant filters are applied in a unified way for document count queries.
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import { EnvelopeType, TeamMemberRole } from '@prisma/client';
|
|
||||||
import type { Prisma, User } from '@prisma/client';
|
import type { Prisma, User } from '@prisma/client';
|
||||||
import { SigningStatus } from '@prisma/client';
|
import { DocumentVisibility, EnvelopeType, SigningStatus, TeamMemberRole } from '@prisma/client';
|
||||||
import { DocumentVisibility } from '@prisma/client';
|
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
@@ -215,13 +213,14 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rootPageFilter = folderId === undefined ? { folderId: null } : {};
|
||||||
|
|
||||||
let ownerCountsWhereInput: Prisma.EnvelopeWhereInput = {
|
let ownerCountsWhereInput: Prisma.EnvelopeWhereInput = {
|
||||||
type: EnvelopeType.DOCUMENT,
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
teamId,
|
teamId,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
folderId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let notSignedCountsGroupByArgs = null;
|
let notSignedCountsGroupByArgs = null;
|
||||||
@@ -265,8 +264,16 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
|
|
||||||
ownerCountsWhereInput = {
|
ownerCountsWhereInput = {
|
||||||
...ownerCountsWhereInput,
|
...ownerCountsWhereInput,
|
||||||
...visibilityFiltersWhereInput,
|
AND: [
|
||||||
...searchFilter,
|
...(Array.isArray(visibilityFiltersWhereInput.AND)
|
||||||
|
? visibilityFiltersWhereInput.AND
|
||||||
|
: visibilityFiltersWhereInput.AND
|
||||||
|
? [visibilityFiltersWhereInput.AND]
|
||||||
|
: []),
|
||||||
|
searchFilter,
|
||||||
|
rootPageFilter,
|
||||||
|
folderId ? { folderId } : {},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (teamEmail) {
|
if (teamEmail) {
|
||||||
@@ -285,6 +292,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
|
AND: [searchFilter, rootPageFilter, folderId ? { folderId } : {}],
|
||||||
};
|
};
|
||||||
|
|
||||||
notSignedCountsGroupByArgs = {
|
notSignedCountsGroupByArgs = {
|
||||||
@@ -296,7 +304,6 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
type: EnvelopeType.DOCUMENT,
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
folderId,
|
|
||||||
status: ExtendedDocumentStatus.PENDING,
|
status: ExtendedDocumentStatus.PENDING,
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
@@ -306,6 +313,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
|
AND: [searchFilter, rootPageFilter, folderId ? { folderId } : {}],
|
||||||
},
|
},
|
||||||
} satisfies Prisma.EnvelopeGroupByArgs;
|
} satisfies Prisma.EnvelopeGroupByArgs;
|
||||||
|
|
||||||
@@ -318,7 +326,6 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
type: EnvelopeType.DOCUMENT,
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
folderId,
|
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
status: ExtendedDocumentStatus.PENDING,
|
status: ExtendedDocumentStatus.PENDING,
|
||||||
@@ -342,6 +349,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
AND: [searchFilter, rootPageFilter, folderId ? { folderId } : {}],
|
||||||
},
|
},
|
||||||
} satisfies Prisma.EnvelopeGroupByArgs;
|
} satisfies Prisma.EnvelopeGroupByArgs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user