Files
documenso/packages/trpc/server/document-router/get-inbox-count.ts
David Nguyen 7f09ba72f4 feat: add envelopes (#2025)
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.
2025-10-14 21:56:36 +11:00

37 lines
924 B
TypeScript

import { DocumentStatus, EnvelopeType, RecipientRole } from '@prisma/client';
import { prisma } from '@documenso/prisma';
import { authenticatedProcedure } from '../trpc';
import { ZGetInboxCountRequestSchema, ZGetInboxCountResponseSchema } from './get-inbox-count.types';
export const getInboxCountRoute = authenticatedProcedure
.input(ZGetInboxCountRequestSchema)
.output(ZGetInboxCountResponseSchema)
.query(async ({ input, ctx }) => {
const { readStatus } = input ?? {};
const userEmail = ctx.user.email;
const count = await prisma.recipient.count({
where: {
email: userEmail,
readStatus,
role: {
not: RecipientRole.CC,
},
envelope: {
type: EnvelopeType.DOCUMENT,
status: {
not: DocumentStatus.DRAFT,
},
deletedAt: null,
},
},
});
return {
count,
};
});