feat: improve admin panel

This commit is contained in:
Mythie
2024-03-03 01:55:33 +11:00
parent 328d16483c
commit 73aae6f1e3
19 changed files with 824 additions and 169 deletions

View File

@ -0,0 +1,26 @@
import { prisma } from '@documenso/prisma';
export type GetEntireDocumentOptions = {
id: number;
};
export const getEntireDocument = async ({ id }: GetEntireDocumentOptions) => {
const document = await prisma.document.findFirstOrThrow({
where: {
id,
},
include: {
Recipient: {
include: {
Field: {
include: {
Signature: true,
},
},
},
},
},
});
return document;
};

View File

@ -0,0 +1,30 @@
import { prisma } from '@documenso/prisma';
import { SigningStatus } from '@documenso/prisma/client';
export type UpdateRecipientOptions = {
id: number;
name: string | undefined;
email: string | undefined;
};
export const updateRecipient = async ({ id, name, email }: UpdateRecipientOptions) => {
const recipient = await prisma.recipient.findFirstOrThrow({
where: {
id,
},
});
if (recipient.signingStatus === SigningStatus.SIGNED) {
throw new Error('Cannot update a recipient that has already signed.');
}
return await prisma.recipient.update({
where: {
id,
},
data: {
name,
email,
},
});
};

View File

@ -22,12 +22,14 @@ import { sendCompletedEmail } from './send-completed-email';
export type SealDocumentOptions = {
documentId: number;
sendEmail?: boolean;
isResealing?: boolean;
requestMetadata?: RequestMetadata;
};
export const sealDocument = async ({
documentId,
sendEmail = true,
isResealing = false,
requestMetadata,
}: SealDocumentOptions) => {
'use server';
@ -78,11 +80,20 @@ export const sealDocument = async ({
throw new Error(`Document ${document.id} has unsigned fields`);
}
if (isResealing) {
// If we're resealing we want to use the initial data for the document
// so we aren't placing fields on top of eachother.
documentData.data = documentData.initialData;
}
// !: Need to write the fields onto the document as a hard copy
const pdfData = await getFile(documentData);
const doc = await PDFDocument.load(pdfData);
// Flatten the form to stop annotation layers from appearing above documenso fields
doc.getForm().flatten();
for (const field of fields) {
await insertFieldInPDF(doc, field);
}
@ -134,7 +145,7 @@ export const sealDocument = async ({
});
});
if (sendEmail) {
if (sendEmail && !isResealing) {
await sendCompletedEmail({ documentId, requestMetadata });
}

View File

@ -4,20 +4,18 @@ import { DocumentStatus } from '@documenso/prisma/client';
import { deletedAccountServiceAccount } from './service-accounts/deleted-account';
export type DeleteUserOptions = {
email: string;
id: number;
};
export const deleteUser = async ({ email }: DeleteUserOptions) => {
export const deleteUser = async ({ id }: DeleteUserOptions) => {
const user = await prisma.user.findFirst({
where: {
email: {
contains: email,
},
id,
},
});
if (!user) {
throw new Error(`User with email ${email} not found`);
throw new Error(`User with ID ${id} not found`);
}
const serviceAccount = await deletedAccountServiceAccount();