mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +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:
@ -1,17 +1,19 @@
|
||||
import type { Document, Team, User } from '@prisma/client';
|
||||
import type { Team, User } from '@prisma/client';
|
||||
import { nanoid } from 'nanoid';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { createDocument } from '@documenso/lib/server-only/document/create-document';
|
||||
import { createTemplate } from '@documenso/lib/server-only/template/create-template';
|
||||
import { createEnvelope } from '@documenso/lib/server-only/envelope/create-envelope';
|
||||
import { incrementDocumentId } from '@documenso/lib/server-only/envelope/increment-id';
|
||||
import { prefixedId } from '@documenso/lib/universal/id';
|
||||
|
||||
import { prisma } from '..';
|
||||
import {
|
||||
DocumentDataType,
|
||||
DocumentSource,
|
||||
DocumentStatus,
|
||||
EnvelopeType,
|
||||
FieldType,
|
||||
Prisma,
|
||||
ReadStatus,
|
||||
@ -30,7 +32,7 @@ type DocumentToSeed = {
|
||||
teamId: number;
|
||||
recipients: (User | string)[];
|
||||
type: DocumentStatus;
|
||||
documentOptions?: Partial<Prisma.DocumentUncheckedCreateInput>;
|
||||
documentOptions?: Partial<Prisma.EnvelopeUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
export const seedDocuments = async (documents: DocumentToSeed[]) => {
|
||||
@ -75,27 +77,37 @@ export const seedBlankDocument = async (
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.document.create({
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
return await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
documentMetaId: documentMeta.id,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
teamId,
|
||||
title: `[TEST] Document ${key} - Draft`,
|
||||
status: DocumentStatus.DRAFT,
|
||||
documentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Document ${key} - Draft`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: owner.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const unseedDocument = async (documentId: number) => {
|
||||
await prisma.document.delete({
|
||||
where: {
|
||||
id: documentId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
const documentData = await prisma.documentData.create({
|
||||
data: {
|
||||
@ -120,11 +132,20 @@ export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
|
||||
const ownerUser = organisation.owner;
|
||||
|
||||
const document = await createDocument({
|
||||
const document = await createEnvelope({
|
||||
userId: ownerUser.id,
|
||||
teamId: team.id,
|
||||
title: `[TEST] Document ${nanoid(8)} - Draft`,
|
||||
documentDataId: documentData.id,
|
||||
internalVersion: 1,
|
||||
data: {
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
title: `[TEST] Document ${nanoid(8)} - Draft`,
|
||||
envelopeItems: [
|
||||
{
|
||||
title: `[TEST] Document ${nanoid(8)} - Draft`,
|
||||
documentDataId: documentData.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
normalizePdf: true,
|
||||
requestMetadata: {
|
||||
auth: null,
|
||||
@ -133,7 +154,7 @@ export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.document.update({
|
||||
await prisma.envelope.update({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -151,11 +172,7 @@ export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
fields: {
|
||||
create: {
|
||||
page: 1,
|
||||
@ -166,13 +183,14 @@ export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
positionY: new Prisma.Decimal(1),
|
||||
width: new Prisma.Decimal(5),
|
||||
height: new Prisma.Decimal(5),
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
envelopeItemId: document.envelopeItems[0].id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.document.findFirstOrThrow({
|
||||
return await prisma.envelope.findFirstOrThrow({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -206,13 +224,24 @@ export const seedTeamTemplateWithMeta = async (team: Team) => {
|
||||
|
||||
const ownerUser = organisation.owner;
|
||||
|
||||
const template = await createTemplate({
|
||||
const template = await createEnvelope({
|
||||
internalVersion: 1,
|
||||
data: {
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title: `[TEST] Template ${nanoid(8)} - Draft`,
|
||||
envelopeItems: [
|
||||
{
|
||||
documentDataId: documentData.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
userId: ownerUser.id,
|
||||
teamId: team.id,
|
||||
templateDocumentDataId: documentData.id,
|
||||
requestMetadata: {
|
||||
auth: null,
|
||||
requestMetadata: {},
|
||||
source: 'app',
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.recipient.create({
|
||||
@ -224,11 +253,7 @@ export const seedTeamTemplateWithMeta = async (team: Team) => {
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
template: {
|
||||
connect: {
|
||||
id: template.id,
|
||||
},
|
||||
},
|
||||
envelopeId: template.id,
|
||||
fields: {
|
||||
create: {
|
||||
page: 1,
|
||||
@ -239,13 +264,14 @@ export const seedTeamTemplateWithMeta = async (team: Team) => {
|
||||
positionY: new Prisma.Decimal(1),
|
||||
width: new Prisma.Decimal(5),
|
||||
height: new Prisma.Decimal(5),
|
||||
templateId: template.id,
|
||||
envelopeId: template.id,
|
||||
envelopeItemId: template.envelopeItems[0].id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.document.findFirstOrThrow({
|
||||
return await prisma.envelope.findFirstOrThrow({
|
||||
where: {
|
||||
id: template.id,
|
||||
},
|
||||
@ -271,16 +297,41 @@ export const seedDraftDocument = async (
|
||||
},
|
||||
});
|
||||
|
||||
const document = await prisma.document.create({
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
const document = await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
documentMetaId: documentMeta.id,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
teamId,
|
||||
title: `[TEST] Document ${key} - Draft`,
|
||||
status: DocumentStatus.DRAFT,
|
||||
documentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Document ${key} - Draft`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -296,22 +347,19 @@ export const seedDraftDocument = async (
|
||||
sendStatus: SendStatus.NOT_SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
fields: {
|
||||
create: {
|
||||
page: 1,
|
||||
type: FieldType.NAME,
|
||||
inserted: true,
|
||||
inserted: false,
|
||||
customText: name,
|
||||
positionX: new Prisma.Decimal(1),
|
||||
positionY: new Prisma.Decimal(1),
|
||||
width: new Prisma.Decimal(1),
|
||||
height: new Prisma.Decimal(1),
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
envelopeItemId: document.envelopeItems[0].id,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -323,7 +371,7 @@ export const seedDraftDocument = async (
|
||||
|
||||
type CreateDocumentOptions = {
|
||||
key?: string | number;
|
||||
createDocumentOptions?: Partial<Prisma.DocumentUncheckedCreateInput>;
|
||||
createDocumentOptions?: Partial<Prisma.EnvelopeUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
export const seedPendingDocument = async (
|
||||
@ -342,16 +390,37 @@ export const seedPendingDocument = async (
|
||||
},
|
||||
});
|
||||
|
||||
const document = await prisma.document.create({
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
const document = await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
documentMetaId: documentMeta.id,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
teamId,
|
||||
title: `[TEST] Document ${key} - Pending`,
|
||||
status: DocumentStatus.PENDING,
|
||||
documentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Document ${key} - Pending`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -367,11 +436,7 @@ export const seedPendingDocument = async (
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
fields: {
|
||||
create: {
|
||||
page: 1,
|
||||
@ -382,19 +447,25 @@ export const seedPendingDocument = async (
|
||||
positionY: new Prisma.Decimal(1),
|
||||
width: new Prisma.Decimal(1),
|
||||
height: new Prisma.Decimal(1),
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
envelopeItemId: document.envelopeItems[0].id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return prisma.document.findFirstOrThrow({
|
||||
return prisma.envelope.findFirstOrThrow({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
include: {
|
||||
recipients: true,
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -408,9 +479,9 @@ export const seedPendingDocumentNoFields = async ({
|
||||
owner: User;
|
||||
recipients: (User | string)[];
|
||||
teamId: number;
|
||||
updateDocumentOptions?: Partial<Prisma.DocumentUncheckedUpdateInput>;
|
||||
updateDocumentOptions?: Partial<Prisma.EnvelopeUncheckedUpdateInput>;
|
||||
}) => {
|
||||
const document: Document = await seedBlankDocument(owner, teamId);
|
||||
const document = await seedBlankDocument(owner, teamId);
|
||||
|
||||
for (const recipient of recipients) {
|
||||
const email = typeof recipient === 'string' ? recipient : recipient.email;
|
||||
@ -425,18 +496,14 @@ export const seedPendingDocumentNoFields = async ({
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const createdRecipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
},
|
||||
include: {
|
||||
fields: true,
|
||||
@ -444,7 +511,7 @@ export const seedPendingDocumentNoFields = async ({
|
||||
});
|
||||
|
||||
const latestDocument = updateDocumentOptions
|
||||
? await prisma.document.update({
|
||||
? await prisma.envelope.update({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -468,12 +535,18 @@ export const seedPendingDocumentWithFullFields = async ({
|
||||
}: {
|
||||
owner: User;
|
||||
recipients: (User | string)[];
|
||||
recipientsCreateOptions?: Partial<Prisma.RecipientCreateInput>[];
|
||||
updateDocumentOptions?: Partial<Prisma.DocumentUncheckedUpdateInput>;
|
||||
recipientsCreateOptions?: Partial<Prisma.RecipientUncheckedCreateInput>[];
|
||||
updateDocumentOptions?: Partial<Prisma.EnvelopeUncheckedUpdateInput>;
|
||||
fields?: FieldType[];
|
||||
teamId: number;
|
||||
}) => {
|
||||
const document: Document = await seedBlankDocument(owner, teamId);
|
||||
const document = await seedBlankDocument(owner, teamId);
|
||||
|
||||
const firstItem = await prisma.envelopeItem.findFirstOrThrow({
|
||||
where: {
|
||||
envelopeId: document.id,
|
||||
},
|
||||
});
|
||||
|
||||
for (const [recipientIndex, recipient] of recipients.entries()) {
|
||||
const email = typeof recipient === 'string' ? recipient : recipient.email;
|
||||
@ -488,11 +561,7 @@ export const seedPendingDocumentWithFullFields = async ({
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
fields: {
|
||||
createMany: {
|
||||
data: fields.map((fieldType, fieldIndex) => ({
|
||||
@ -504,7 +573,8 @@ export const seedPendingDocumentWithFullFields = async ({
|
||||
positionY: new Prisma.Decimal((fieldIndex + 1) * 5),
|
||||
width: new Prisma.Decimal(5),
|
||||
height: new Prisma.Decimal(5),
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
envelopeItemId: firstItem.id,
|
||||
})),
|
||||
},
|
||||
},
|
||||
@ -515,14 +585,14 @@ export const seedPendingDocumentWithFullFields = async ({
|
||||
|
||||
const createdRecipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
},
|
||||
include: {
|
||||
fields: true,
|
||||
},
|
||||
});
|
||||
|
||||
const latestDocument = await prisma.document.update({
|
||||
const latestDocument = await prisma.envelope.update({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -557,16 +627,37 @@ export const seedCompletedDocument = async (
|
||||
},
|
||||
});
|
||||
|
||||
const document = await prisma.document.create({
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
const document = await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
documentMetaId: documentMeta.id,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
teamId,
|
||||
title: `[TEST] Document ${key} - Completed`,
|
||||
status: DocumentStatus.COMPLETED,
|
||||
documentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Document ${key} - Completed`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -582,11 +673,7 @@ export const seedCompletedDocument = async (
|
||||
sendStatus: SendStatus.SENT,
|
||||
signingStatus: SigningStatus.SIGNED,
|
||||
signedAt: new Date(),
|
||||
document: {
|
||||
connect: {
|
||||
id: document.id,
|
||||
},
|
||||
},
|
||||
envelopeId: document.id,
|
||||
fields: {
|
||||
create: {
|
||||
page: 1,
|
||||
@ -597,7 +684,8 @@ export const seedCompletedDocument = async (
|
||||
positionY: new Prisma.Decimal(1),
|
||||
width: new Prisma.Decimal(1),
|
||||
height: new Prisma.Decimal(1),
|
||||
documentId: document.id,
|
||||
envelopeId: document.id,
|
||||
envelopeItemId: document.envelopeItems[0].id,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { incrementDocumentId } from '@documenso/lib/server-only/envelope/increment-id';
|
||||
import { prefixedId } from '@documenso/lib/universal/id';
|
||||
|
||||
import { prisma } from '..';
|
||||
import { DocumentDataType, DocumentSource } from '../client';
|
||||
import { DocumentDataType, DocumentSource, EnvelopeType } from '../client';
|
||||
import { seedPendingDocument } from './documents';
|
||||
import { seedDirectTemplate, seedTemplate } from './templates';
|
||||
import { seedUser } from './users';
|
||||
@ -52,11 +55,29 @@ export const seedDatabase = async () => {
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
const documentData = await createDocumentData({ documentData: examplePdf });
|
||||
|
||||
await prisma.document.create({
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
documentMetaId: documentMeta.id,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
title: `Example Document ${i}`,
|
||||
documentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `Example Document ${i}`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: exampleUser.user.id,
|
||||
teamId: exampleUser.team.id,
|
||||
recipients: {
|
||||
@ -73,11 +94,29 @@ export const seedDatabase = async () => {
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
const documentData = await createDocumentData({ documentData: examplePdf });
|
||||
|
||||
await prisma.document.create({
|
||||
const documentId = await incrementDocumentId();
|
||||
|
||||
const documentMeta = await prisma.documentMeta.create({
|
||||
data: {},
|
||||
});
|
||||
|
||||
await prisma.envelope.create({
|
||||
data: {
|
||||
id: prefixedId('envelope'),
|
||||
secondaryId: documentId.formattedDocumentId,
|
||||
internalVersion: 1,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
source: DocumentSource.DOCUMENT,
|
||||
title: `Document ${i}`,
|
||||
documentDataId: documentData.id,
|
||||
documentMetaId: documentMeta.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `Document ${i}`,
|
||||
documentDataId: documentData.id,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
userId: adminUser.user.id,
|
||||
teamId: adminUser.team.id,
|
||||
recipients: {
|
||||
|
||||
@ -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