mirror of
https://github.com/documenso/documenso.git
synced 2026-07-13 14:35:47 +10:00
e98b37bb10
Add a Rejected tab and an Expired pseudo-status tab to the documents list, and an orthogonal hasExpiredRecipients boolean to the public v2 document and envelope find APIs. - Add shared hasExpiredRecipient EXISTS predicate (expiresAt in the past, NOT_SIGNED, role != CC) to find-documents, get-stats and find-envelopes - Surface REJECTED in the documents tabs (backend already wired) - Add EXPIRED extended status: where-clause branches, stats count (excluded from ALL since it overlaps PENDING), status display (TimerOff/orange), tabs, and empty-state copy - Expose hasExpiredRecipients on GET /document and /envelope using an enum-transform schema to avoid the coerce "false" -> true footgun - Document that redistributing renews expired signing links - Add e2e coverage for the expired filter on both endpoints
32 lines
829 B
TypeScript
32 lines
829 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
|
import { EnvelopeType } from '@prisma/client';
|
|
|
|
export const getDocumentStats = async () => {
|
|
const counts = await prisma.envelope.groupBy({
|
|
where: {
|
|
type: EnvelopeType.DOCUMENT,
|
|
},
|
|
by: ['status'],
|
|
_count: {
|
|
_all: true,
|
|
},
|
|
});
|
|
|
|
const stats: Record<Exclude<ExtendedDocumentStatus, 'INBOX' | 'EXPIRED'>, number> = {
|
|
[ExtendedDocumentStatus.DRAFT]: 0,
|
|
[ExtendedDocumentStatus.PENDING]: 0,
|
|
[ExtendedDocumentStatus.COMPLETED]: 0,
|
|
[ExtendedDocumentStatus.REJECTED]: 0,
|
|
[ExtendedDocumentStatus.ALL]: 0,
|
|
};
|
|
|
|
counts.forEach((stat) => {
|
|
stats[stat.status] = stat._count._all;
|
|
|
|
stats.ALL += stat._count._all;
|
|
});
|
|
|
|
return stats;
|
|
};
|