Files
sign/packages/lib/server-only/user/get-next-inbox-document.ts

47 lines
984 B
TypeScript
Raw Normal View History

2024-10-10 20:23:32 +00:00
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
import { prisma } from '@documenso/prisma';
type GetNextInboxDocumentOptions = {
email: string | undefined;
};
export const getNextInboxDocument = async ({ email }: GetNextInboxDocumentOptions) => {
if (!email) {
throw new Error('User is required');
}
2024-10-11 18:43:09 +00:00
return await prisma.document.findMany({
2024-10-10 20:23:32 +00:00
where: {
2025-03-03 17:17:45 +00:00
recipients: {
2024-10-10 20:23:32 +00:00
some: {
email,
signingStatus: SigningStatus.NOT_SIGNED,
role: {
not: RecipientRole.CC,
},
},
},
status: { not: DocumentStatus.DRAFT },
deletedAt: null,
},
select: {
2024-10-11 18:43:09 +00:00
id: true,
2024-10-10 20:23:32 +00:00
createdAt: true,
title: true,
2024-10-11 18:43:09 +00:00
status: true,
2025-03-03 17:17:45 +00:00
recipients: {
2024-10-10 20:23:32 +00:00
where: {
email,
},
select: {
token: true,
2024-10-11 18:43:09 +00:00
role: true,
2024-10-10 20:23:32 +00:00
},
},
documentMeta: true,
},
orderBy: [{ createdAt: 'asc' }],
});
};