mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
33 lines
818 B
TypeScript
33 lines
818 B
TypeScript
import { EnvelopeType } from '@prisma/client';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
|
|
|
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.ALL]: 0,
|
|
};
|
|
|
|
counts.forEach((stat) => {
|
|
stats[stat.status] = stat._count._all;
|
|
|
|
stats.ALL += stat._count._all;
|
|
});
|
|
|
|
return stats;
|
|
};
|