mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
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.
This commit is contained in:
@ -5,10 +5,20 @@ import {
|
||||
DIRECT_TEMPLATE_RECIPIENT_EMAIL,
|
||||
DIRECT_TEMPLATE_RECIPIENT_NAME,
|
||||
} from '@documenso/lib/constants/direct-templates';
|
||||
import { incrementTemplateId } from '@documenso/lib/server-only/envelope/increment-id';
|
||||
import { prefixedId } from '@documenso/lib/universal/id';
|
||||
|
||||
import { prisma } from '..';
|
||||
import type { Prisma, User } from '../client';
|
||||
import { DocumentDataType, ReadStatus, RecipientRole, SendStatus, SigningStatus } from '../client';
|
||||
import {
|
||||
DocumentDataType,
|
||||
DocumentSource,
|
||||
EnvelopeType,
|
||||
ReadStatus,
|
||||
RecipientRole,
|
||||
SendStatus,
|
||||
SigningStatus,
|
||||
} from '../client';
|
||||
|
||||
const examplePdf = fs
|
||||
.readFileSync(path.join(__dirname, '../../../assets/example.pdf'))
|
||||
@ -18,12 +28,12 @@ type SeedTemplateOptions = {
|
||||
title?: string;
|
||||
userId: number;
|
||||
teamId: number;
|
||||
createTemplateOptions?: Partial<Prisma.TemplateCreateInput>;
|
||||
createTemplateOptions?: Partial<Prisma.EnvelopeUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
type CreateTemplateOptions = {
|
||||
key?: string | number;
|
||||
createTemplateOptions?: Partial<Prisma.TemplateUncheckedCreateInput>;
|
||||
createTemplateOptions?: Partial<Prisma.EnvelopeUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
export const seedBlankTemplate = async (
|
||||
@ -41,14 +51,40 @@ export const seedBlankTemplate = async (
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.template.create({
|
||||
const templateId = await incrementTemplateId();
|
||||
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
return await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: templateId.formattedTemplateId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title: `[TEST] Template ${key}`,
|
||||
teamId,
|
||||
templateDocumentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Template ${key}`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: owner.id,
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
...createTemplateOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -63,19 +99,31 @@ export const seedTemplate = async (options: SeedTemplateOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.template.create({
|
||||
const templateId = await incrementTemplateId();
|
||||
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
return await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: templateId.formattedTemplateId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title,
|
||||
templateDocumentData: {
|
||||
connect: {
|
||||
id: documentData.id,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
userId,
|
||||
teamId,
|
||||
recipients: {
|
||||
create: {
|
||||
email: 'recipient.1@documenso.com',
|
||||
@ -87,9 +135,11 @@ export const seedTemplate = async (options: SeedTemplateOptions) => {
|
||||
role: RecipientRole.SIGNER,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
connect: {
|
||||
id: teamId,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -107,19 +157,31 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
const template = await prisma.template.create({
|
||||
const templateId = await incrementTemplateId();
|
||||
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
const template = await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: templateId.formattedTemplateId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title,
|
||||
templateDocumentData: {
|
||||
connect: {
|
||||
id: documentData.id,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
userId,
|
||||
teamId,
|
||||
recipients: {
|
||||
create: {
|
||||
email: DIRECT_TEMPLATE_RECIPIENT_EMAIL,
|
||||
@ -127,11 +189,6 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
token: Math.random().toString().slice(2, 7),
|
||||
},
|
||||
},
|
||||
team: {
|
||||
connect: {
|
||||
id: teamId,
|
||||
},
|
||||
},
|
||||
...options.createTemplateOptions,
|
||||
},
|
||||
include: {
|
||||
@ -150,14 +207,14 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
|
||||
await prisma.templateDirectLink.create({
|
||||
data: {
|
||||
templateId: template.id,
|
||||
envelopeId: template.id,
|
||||
enabled: true,
|
||||
token: Math.random().toString(),
|
||||
directTemplateRecipientId: directTemplateRecpient.id,
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.template.findFirstOrThrow({
|
||||
return await prisma.envelope.findFirstOrThrow({
|
||||
where: {
|
||||
id: template.id,
|
||||
},
|
||||
@ -166,6 +223,11 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
fields: true,
|
||||
recipients: true,
|
||||
team: true,
|
||||
envelopeItems: {
|
||||
select: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user