Files
sign/packages/lib/server-only/recipient/update-recipient.ts

43 lines
858 B
TypeScript
Raw Normal View History

import { prisma } from '@documenso/prisma';
2024-02-12 15:16:09 +11:00
import type { RecipientRole } from '@documenso/prisma/client';
export type UpdateRecipientOptions = {
documentId: number;
recipientId: number;
email?: string;
name?: string;
2024-02-12 15:16:09 +11:00
role?: RecipientRole;
};
export const updateRecipient = async ({
documentId,
recipientId,
email,
name,
2024-02-12 15:16:09 +11:00
role,
}: UpdateRecipientOptions) => {
const recipient = await prisma.recipient.findFirst({
where: {
id: recipientId,
documentId,
},
});
if (!recipient) {
throw new Error('Recipient not found');
}
const updatedRecipient = await prisma.recipient.update({
where: {
id: recipient.id,
},
data: {
email: email?.toLowerCase() ?? recipient.email,
name: name ?? recipient.name,
2024-02-12 15:16:09 +11:00
role: role ?? recipient.role,
},
});
return updatedRecipient;
};