2024-01-31 12:40:37 +11:00
|
|
|
import { DateTime } from 'luxon';
|
2024-09-16 17:14:16 +03:00
|
|
|
import { match } from 'ts-pattern';
|
2024-01-31 12:40:37 +11:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
import type { PeriodSelectorValue } from '@documenso/lib/server-only/document/find-documents';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { prisma } from '@documenso/prisma';
|
2024-09-16 17:14:16 +03:00
|
|
|
import { TeamMemberRole } from '@documenso/prisma/client';
|
2024-01-31 12:40:37 +11:00
|
|
|
import type { Prisma, User } from '@documenso/prisma/client';
|
2023-12-06 05:41:51 +05:30
|
|
|
import { SigningStatus } from '@documenso/prisma/client';
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
import { DocumentVisibility } from '@documenso/prisma/client';
|
2023-08-24 16:50:40 +10:00
|
|
|
import { isExtendedDocumentStatus } from '@documenso/prisma/guards/is-extended-document-status';
|
|
|
|
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
2023-06-09 18:21:18 +10:00
|
|
|
|
|
|
|
|
export type GetStatsInput = {
|
2023-08-24 16:50:40 +10:00
|
|
|
user: User;
|
2024-02-06 16:16:10 +11:00
|
|
|
team?: Omit<GetTeamCountsOption, 'createdAt'>;
|
2024-01-31 12:40:37 +11:00
|
|
|
period?: PeriodSelectorValue;
|
2024-10-08 13:44:02 +03:00
|
|
|
search?: string;
|
2023-06-09 18:21:18 +10:00
|
|
|
};
|
|
|
|
|
|
2024-10-08 13:44:02 +03:00
|
|
|
export const getStats = async ({ user, period, search, ...options }: GetStatsInput) => {
|
2024-01-31 12:40:37 +11:00
|
|
|
let createdAt: Prisma.DocumentWhereInput['createdAt'];
|
|
|
|
|
|
|
|
|
|
if (period) {
|
|
|
|
|
const daysAgo = parseInt(period.replace(/d$/, ''), 10);
|
|
|
|
|
|
|
|
|
|
const startOfPeriod = DateTime.now().minus({ days: daysAgo }).startOf('day');
|
|
|
|
|
|
|
|
|
|
createdAt = {
|
|
|
|
|
gte: startOfPeriod.toJSDate(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
const [ownerCounts, notSignedCounts, hasSignedCounts] = await (options.team
|
2024-10-08 13:44:02 +03:00
|
|
|
? getTeamCounts({
|
|
|
|
|
...options.team,
|
|
|
|
|
createdAt,
|
|
|
|
|
currentUserEmail: user.email,
|
|
|
|
|
userId: user.id,
|
|
|
|
|
search,
|
|
|
|
|
})
|
|
|
|
|
: getCounts({ user, createdAt, search }));
|
2024-02-06 16:16:10 +11:00
|
|
|
|
|
|
|
|
const stats: Record<ExtendedDocumentStatus, number> = {
|
|
|
|
|
[ExtendedDocumentStatus.DRAFT]: 0,
|
|
|
|
|
[ExtendedDocumentStatus.PENDING]: 0,
|
|
|
|
|
[ExtendedDocumentStatus.COMPLETED]: 0,
|
|
|
|
|
[ExtendedDocumentStatus.INBOX]: 0,
|
|
|
|
|
[ExtendedDocumentStatus.ALL]: 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ownerCounts.forEach((stat) => {
|
|
|
|
|
stats[stat.status] = stat._count._all;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notSignedCounts.forEach((stat) => {
|
|
|
|
|
stats[ExtendedDocumentStatus.INBOX] += stat._count._all;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hasSignedCounts.forEach((stat) => {
|
|
|
|
|
if (stat.status === ExtendedDocumentStatus.COMPLETED) {
|
|
|
|
|
stats[ExtendedDocumentStatus.COMPLETED] += stat._count._all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stat.status === ExtendedDocumentStatus.PENDING) {
|
|
|
|
|
stats[ExtendedDocumentStatus.PENDING] += stat._count._all;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.keys(stats).forEach((key) => {
|
|
|
|
|
if (key !== ExtendedDocumentStatus.ALL && isExtendedDocumentStatus(key)) {
|
|
|
|
|
stats[ExtendedDocumentStatus.ALL] += stats[key];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type GetCountsOption = {
|
|
|
|
|
user: User;
|
|
|
|
|
createdAt: Prisma.DocumentWhereInput['createdAt'];
|
2024-10-08 13:44:02 +03:00
|
|
|
search?: string;
|
2024-02-06 16:16:10 +11:00
|
|
|
};
|
|
|
|
|
|
2024-10-08 13:44:02 +03:00
|
|
|
const getCounts = async ({ user, createdAt, search }: GetCountsOption) => {
|
|
|
|
|
const searchFilter: Prisma.DocumentWhereInput = {
|
|
|
|
|
OR: [
|
|
|
|
|
{ title: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
{ Recipient: { some: { name: { contains: search, mode: 'insensitive' } } } },
|
|
|
|
|
{ Recipient: { some: { email: { contains: search, mode: 'insensitive' } } } },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
return Promise.all([
|
2024-04-19 17:37:38 +07:00
|
|
|
// Owner counts.
|
2023-08-24 16:50:40 +10:00
|
|
|
prisma.document.groupBy({
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: {
|
|
|
|
|
userId: user.id,
|
2024-01-31 12:40:37 +11:00
|
|
|
createdAt,
|
2024-02-06 16:16:10 +11:00
|
|
|
teamId: null,
|
2023-12-06 05:41:51 +05:30
|
|
|
deletedAt: null,
|
2024-10-08 13:44:02 +03:00
|
|
|
AND: [searchFilter],
|
2023-08-24 16:50:40 +10:00
|
|
|
},
|
|
|
|
|
}),
|
2024-04-19 17:37:38 +07:00
|
|
|
// Not signed counts.
|
2023-08-24 16:50:40 +10:00
|
|
|
prisma.document.groupBy({
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: {
|
|
|
|
|
status: ExtendedDocumentStatus.PENDING,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: user.email,
|
|
|
|
|
signingStatus: SigningStatus.NOT_SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2023-08-24 16:50:40 +10:00
|
|
|
},
|
|
|
|
|
},
|
2024-01-31 12:40:37 +11:00
|
|
|
createdAt,
|
2024-10-08 13:44:02 +03:00
|
|
|
AND: [searchFilter],
|
2023-08-24 16:50:40 +10:00
|
|
|
},
|
|
|
|
|
}),
|
2024-04-19 17:37:38 +07:00
|
|
|
// Has signed counts.
|
2023-08-24 16:50:40 +10:00
|
|
|
prisma.document.groupBy({
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: {
|
2024-01-31 12:40:37 +11:00
|
|
|
createdAt,
|
2024-01-25 05:59:04 +05:30
|
|
|
User: {
|
|
|
|
|
email: {
|
|
|
|
|
not: user.email,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-06 05:41:51 +05:30
|
|
|
OR: [
|
|
|
|
|
{
|
|
|
|
|
status: ExtendedDocumentStatus.PENDING,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: user.email,
|
|
|
|
|
signingStatus: SigningStatus.SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2023-12-06 05:41:51 +05:30
|
|
|
},
|
|
|
|
|
},
|
2023-08-24 16:50:40 +10:00
|
|
|
},
|
2023-12-06 05:41:51 +05:30
|
|
|
{
|
|
|
|
|
status: ExtendedDocumentStatus.COMPLETED,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: user.email,
|
|
|
|
|
signingStatus: SigningStatus.SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2023-12-06 05:41:51 +05:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-10-08 13:44:02 +03:00
|
|
|
AND: [searchFilter],
|
2023-08-24 16:50:40 +10:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]);
|
2024-02-06 16:16:10 +11:00
|
|
|
};
|
2023-06-09 18:21:18 +10:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
type GetTeamCountsOption = {
|
|
|
|
|
teamId: number;
|
|
|
|
|
teamEmail?: string;
|
|
|
|
|
senderIds?: number[];
|
2024-09-16 17:14:16 +03:00
|
|
|
currentUserEmail: string;
|
|
|
|
|
userId: number;
|
2024-02-06 16:16:10 +11:00
|
|
|
createdAt: Prisma.DocumentWhereInput['createdAt'];
|
2024-09-16 17:14:16 +03:00
|
|
|
currentTeamMemberRole?: TeamMemberRole;
|
2024-10-08 13:44:02 +03:00
|
|
|
search?: string;
|
2024-02-06 16:16:10 +11:00
|
|
|
};
|
2023-06-09 18:21:18 +10:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|
|
|
|
const { createdAt, teamId, teamEmail } = options;
|
2023-06-09 18:21:18 +10:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
const senderIds = options.senderIds ?? [];
|
2023-08-24 16:50:40 +10:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
const userIdWhereClause: Prisma.DocumentWhereInput['userId'] =
|
|
|
|
|
senderIds.length > 0
|
|
|
|
|
? {
|
|
|
|
|
in: senderIds,
|
|
|
|
|
}
|
|
|
|
|
: undefined;
|
2023-08-24 16:50:40 +10:00
|
|
|
|
2024-10-08 13:44:02 +03:00
|
|
|
const searchFilter: Prisma.DocumentWhereInput = {
|
|
|
|
|
OR: [
|
|
|
|
|
{ title: { contains: options.search, mode: 'insensitive' } },
|
|
|
|
|
{ Recipient: { some: { name: { contains: options.search, mode: 'insensitive' } } } },
|
|
|
|
|
{ Recipient: { some: { email: { contains: options.search, mode: 'insensitive' } } } },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
let ownerCountsWhereInput: Prisma.DocumentWhereInput = {
|
|
|
|
|
userId: userIdWhereClause,
|
|
|
|
|
createdAt,
|
|
|
|
|
teamId,
|
|
|
|
|
deletedAt: null,
|
|
|
|
|
};
|
2023-08-24 16:50:40 +10:00
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
let notSignedCountsGroupByArgs = null;
|
|
|
|
|
let hasSignedCountsGroupByArgs = null;
|
2023-08-24 16:50:40 +10:00
|
|
|
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
const visibilityFiltersWhereInput: Prisma.DocumentWhereInput = {
|
|
|
|
|
AND: [
|
|
|
|
|
{ deletedAt: null },
|
2024-09-16 17:14:16 +03:00
|
|
|
{
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
OR: [
|
|
|
|
|
match(options.currentTeamMemberRole)
|
|
|
|
|
.with(TeamMemberRole.ADMIN, () => ({
|
|
|
|
|
visibility: {
|
|
|
|
|
in: [
|
|
|
|
|
DocumentVisibility.EVERYONE,
|
|
|
|
|
DocumentVisibility.MANAGER_AND_ABOVE,
|
|
|
|
|
DocumentVisibility.ADMIN,
|
|
|
|
|
],
|
2024-09-16 17:14:16 +03:00
|
|
|
},
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
}))
|
|
|
|
|
.with(TeamMemberRole.MANAGER, () => ({
|
|
|
|
|
visibility: {
|
|
|
|
|
in: [DocumentVisibility.EVERYONE, DocumentVisibility.MANAGER_AND_ABOVE],
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
.otherwise(() => ({
|
|
|
|
|
visibility: {
|
|
|
|
|
equals: DocumentVisibility.EVERYONE,
|
|
|
|
|
},
|
|
|
|
|
})),
|
|
|
|
|
{
|
|
|
|
|
OR: [
|
|
|
|
|
{ userId: options.userId },
|
|
|
|
|
{ Recipient: { some: { email: options.currentUserEmail } } },
|
|
|
|
|
],
|
2024-09-16 17:14:16 +03:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ownerCountsWhereInput = {
|
|
|
|
|
...ownerCountsWhereInput,
|
|
|
|
|
...visibilityFiltersWhereInput,
|
2024-10-08 13:44:02 +03:00
|
|
|
...searchFilter,
|
2024-09-16 17:14:16 +03:00
|
|
|
};
|
|
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
if (teamEmail) {
|
|
|
|
|
ownerCountsWhereInput = {
|
|
|
|
|
userId: userIdWhereClause,
|
|
|
|
|
createdAt,
|
|
|
|
|
OR: [
|
|
|
|
|
{
|
|
|
|
|
teamId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
User: {
|
|
|
|
|
email: teamEmail,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
deletedAt: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
notSignedCountsGroupByArgs = {
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: {
|
|
|
|
|
userId: userIdWhereClause,
|
|
|
|
|
createdAt,
|
|
|
|
|
status: ExtendedDocumentStatus.PENDING,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: teamEmail,
|
|
|
|
|
signingStatus: SigningStatus.NOT_SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2024-02-06 16:16:10 +11:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
deletedAt: null,
|
|
|
|
|
},
|
|
|
|
|
} satisfies Prisma.DocumentGroupByArgs;
|
|
|
|
|
|
|
|
|
|
hasSignedCountsGroupByArgs = {
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: {
|
|
|
|
|
userId: userIdWhereClause,
|
|
|
|
|
createdAt,
|
|
|
|
|
OR: [
|
|
|
|
|
{
|
|
|
|
|
status: ExtendedDocumentStatus.PENDING,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: teamEmail,
|
|
|
|
|
signingStatus: SigningStatus.SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2024-02-06 16:16:10 +11:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
deletedAt: null,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
status: ExtendedDocumentStatus.COMPLETED,
|
|
|
|
|
Recipient: {
|
|
|
|
|
some: {
|
|
|
|
|
email: teamEmail,
|
|
|
|
|
signingStatus: SigningStatus.SIGNED,
|
2024-04-19 17:37:38 +07:00
|
|
|
documentDeletedAt: null,
|
2024-02-06 16:16:10 +11:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
deletedAt: null,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
} satisfies Prisma.DocumentGroupByArgs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
|
prisma.document.groupBy({
|
|
|
|
|
by: ['status'],
|
|
|
|
|
_count: {
|
|
|
|
|
_all: true,
|
|
|
|
|
},
|
|
|
|
|
where: ownerCountsWhereInput,
|
|
|
|
|
}),
|
|
|
|
|
notSignedCountsGroupByArgs ? prisma.document.groupBy(notSignedCountsGroupByArgs) : [],
|
|
|
|
|
hasSignedCountsGroupByArgs ? prisma.document.groupBy(hasSignedCountsGroupByArgs) : [],
|
|
|
|
|
]);
|
2023-06-09 18:21:18 +10:00
|
|
|
};
|