Files
sign/packages/lib/server-only/admin/get-documents-stats.ts

27 lines
673 B
TypeScript
Raw Normal View History

2023-09-08 11:28:50 +03:00
import { prisma } from '@documenso/prisma';
2023-09-12 07:25:44 +00:00
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
2023-09-08 11:28:50 +03:00
2023-09-12 07:25:44 +00:00
export const getDocumentStats = async () => {
const counts = await prisma.document.groupBy({
by: ['status'],
_count: {
_all: true,
},
});
const stats: Record<Exclude<ExtendedDocumentStatus, 'INBOX'>, number> = {
[ExtendedDocumentStatus.DRAFT]: 0,
[ExtendedDocumentStatus.PENDING]: 0,
[ExtendedDocumentStatus.COMPLETED]: 0,
[ExtendedDocumentStatus.ALL]: 0,
};
counts.forEach((stat) => {
stats[stat.status] = stat._count._all;
stats.ALL += stat._count._all;
});
return stats;
2023-09-08 11:28:50 +03:00
};