mirror of
https://github.com/documenso/documenso.git
synced 2026-08-24 07:12:23 +10:00
34 lines
782 B
TypeScript
34 lines
782 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { EnvelopeType } from '@prisma/client';
|
|
|
|
import { mapDocumentIdToSecondaryId } from '../../utils/envelope';
|
|
import { getDictatableNextRecipient } from '../../utils/recipient-groups';
|
|
|
|
export const getNextPendingRecipient = async ({
|
|
documentId,
|
|
currentRecipientId,
|
|
}: {
|
|
documentId: number;
|
|
currentRecipientId: number;
|
|
}) => {
|
|
const recipients = await prisma.recipient.findMany({
|
|
where: {
|
|
envelope: {
|
|
type: EnvelopeType.DOCUMENT,
|
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
|
},
|
|
},
|
|
});
|
|
|
|
const nextRecipient = getDictatableNextRecipient({ recipients, currentRecipientId });
|
|
|
|
if (!nextRecipient) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
...nextRecipient,
|
|
token: '',
|
|
};
|
|
};
|