mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
4f346d3c2d
Adds a CANCELLED envelope status that privileged members (owner or team admin/manager) can move a pending document into. Sending recipient notifications via a background job while retaining the document in the dashboard as proof of distribution. Includes a dedicated Cancelled tab, single and bulk cancel actions, the ENVELOPE_CANCELLED mutability guard, and e2e coverage for permissions and visibility.
33 lines
860 B
TypeScript
33 lines
860 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'>, number> = {
|
|
[ExtendedDocumentStatus.DRAFT]: 0,
|
|
[ExtendedDocumentStatus.PENDING]: 0,
|
|
[ExtendedDocumentStatus.COMPLETED]: 0,
|
|
[ExtendedDocumentStatus.REJECTED]: 0,
|
|
[ExtendedDocumentStatus.CANCELLED]: 0,
|
|
[ExtendedDocumentStatus.ALL]: 0,
|
|
};
|
|
|
|
counts.forEach((stat) => {
|
|
stats[stat.status] = stat._count._all;
|
|
|
|
stats.ALL += stat._count._all;
|
|
});
|
|
|
|
return stats;
|
|
};
|