mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 02:01:33 +10:00
feat: migrate templates and documents to envelope model
This commit is contained in:
@ -64,8 +64,7 @@ model User {
|
||||
twoFactorBackupCodes String?
|
||||
|
||||
folders Folder[]
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
|
||||
verificationTokens VerificationToken[]
|
||||
apiTokens ApiToken[]
|
||||
@ -354,8 +353,7 @@ model Folder {
|
||||
pinned Boolean @default(false)
|
||||
parentId String?
|
||||
parent Folder? @relation("FolderToFolder", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
subfolders Folder[] @relation("FolderToFolder")
|
||||
@ -368,53 +366,82 @@ model Folder {
|
||||
@@index([type])
|
||||
}
|
||||
|
||||
/// @zod.import(["import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';", "import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';"])
|
||||
model Document {
|
||||
id Int @id @default(autoincrement())
|
||||
qrToken String? /// @zod.string.describe("The token for viewing the document using the QR code on the certificate.")
|
||||
externalId String? /// @zod.string.describe("A custom external ID you can use to identify the document.")
|
||||
enum EnvelopeType {
|
||||
DOCUMENT
|
||||
TEMPLATE
|
||||
}
|
||||
|
||||
model Envelope {
|
||||
id String @id // document_asdfasdfsadf template_123asdf
|
||||
secondaryId String @unique // document_456456456 template_45465465
|
||||
externalId String? /// @zod.string.describe("A custom external ID you can use to identify the document.")
|
||||
|
||||
type EnvelopeType
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
completedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
|
||||
title String
|
||||
status DocumentStatus @default(DRAFT)
|
||||
source DocumentSource
|
||||
qrToken String? /// @zod.string.describe("The token for viewing the document using the QR code on the certificate.")
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
|
||||
envelopeItems EnvelopeItem[]
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
shareLinks DocumentShareLink[]
|
||||
auditLogs DocumentAuditLog[]
|
||||
|
||||
// Envelope settings
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
formValues Json? /// [DocumentFormValues] @zod.custom.use(ZDocumentFormValuesSchema)
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
|
||||
// Template specific fields.
|
||||
templateType TemplateType @default(PRIVATE)
|
||||
publicTitle String @default("")
|
||||
publicDescription String @default("")
|
||||
directLink TemplateDirectLink?
|
||||
templateId Int? // Todo: Migrate from templateId -> This @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
// Relations
|
||||
userId Int /// @zod.number.describe("The ID of the user that created this document.")
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
teamId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
formValues Json? /// [DocumentFormValues] @zod.custom.use(ZDocumentFormValuesSchema)
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
title String
|
||||
status DocumentStatus @default(DRAFT)
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
shareLinks DocumentShareLink[]
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
|
||||
documentMetaId String @unique
|
||||
documentMeta DocumentMeta @relation(fields: [documentMetaId], references: [id])
|
||||
}
|
||||
|
||||
/// @zod.import(["import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';", "import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';"])
|
||||
model EnvelopeItem {
|
||||
id String @id
|
||||
|
||||
title String
|
||||
|
||||
documentDataId String
|
||||
documentMeta DocumentMeta?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
completedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
templateId Int?
|
||||
source DocumentSource
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
envelopeId String
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: SetNull)
|
||||
|
||||
auditLogs DocumentAuditLog[]
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
field Field[]
|
||||
|
||||
@@unique([documentDataId])
|
||||
@@index([userId])
|
||||
@@index([status])
|
||||
@@index([folderId])
|
||||
}
|
||||
|
||||
model DocumentAuditLog {
|
||||
id String @id @default(cuid())
|
||||
documentId Int
|
||||
envelopeId String
|
||||
createdAt DateTime @default(now())
|
||||
type String
|
||||
data Json
|
||||
@ -426,7 +453,7 @@ model DocumentAuditLog {
|
||||
userAgent String?
|
||||
ipAddress String?
|
||||
|
||||
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum DocumentDataType {
|
||||
@ -441,12 +468,11 @@ enum DocumentSigningOrder {
|
||||
}
|
||||
|
||||
model DocumentData {
|
||||
id String @id @default(cuid())
|
||||
type DocumentDataType
|
||||
data String
|
||||
initialData String
|
||||
document Document?
|
||||
template Template?
|
||||
id String @id @default(cuid())
|
||||
type DocumentDataType
|
||||
data String
|
||||
initialData String
|
||||
envelopeItem EnvelopeItem?
|
||||
}
|
||||
|
||||
enum DocumentDistributionMethod {
|
||||
@ -460,7 +486,6 @@ model DocumentMeta {
|
||||
subject String?
|
||||
message String?
|
||||
timezone String? @default("Etc/UTC") @db.Text
|
||||
password String?
|
||||
dateFormat String? @default("yyyy-MM-dd hh:mm a") @db.Text
|
||||
redirectUrl String?
|
||||
signingOrder DocumentSigningOrder @default(PARALLEL)
|
||||
@ -477,11 +502,7 @@ model DocumentMeta {
|
||||
emailReplyTo String?
|
||||
emailId String?
|
||||
|
||||
documentId Int? @unique
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
|
||||
templateId Int? @unique
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope?
|
||||
}
|
||||
|
||||
enum ReadStatus {
|
||||
@ -511,8 +532,7 @@ enum RecipientRole {
|
||||
/// @zod.import(["import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';"])
|
||||
model Recipient {
|
||||
id Int @id @default(autoincrement())
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
envelopeId String
|
||||
email String @db.VarChar(255)
|
||||
name String @default("") @db.VarChar(255)
|
||||
token String
|
||||
@ -526,13 +546,11 @@ model Recipient {
|
||||
readStatus ReadStatus @default(NOT_OPENED)
|
||||
signingStatus SigningStatus @default(NOT_SIGNED)
|
||||
sendStatus SendStatus @default(NOT_SENT)
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
fields Field[]
|
||||
signatures Signature[]
|
||||
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@index([envelopeId])
|
||||
@@index([token])
|
||||
}
|
||||
|
||||
@ -552,27 +570,26 @@ enum FieldType {
|
||||
|
||||
/// @zod.import(["import { ZFieldMetaNotOptionalSchema } from '@documenso/lib/types/field-meta';"])
|
||||
model Field {
|
||||
id Int @id @default(autoincrement())
|
||||
secondaryId String @unique @default(cuid())
|
||||
documentId Int?
|
||||
templateId Int?
|
||||
recipientId Int
|
||||
type FieldType
|
||||
page Int /// @zod.number.describe("The page number of the field on the document. Starts from 1.")
|
||||
positionX Decimal @default(0)
|
||||
positionY Decimal @default(0)
|
||||
width Decimal @default(-1)
|
||||
height Decimal @default(-1)
|
||||
customText String
|
||||
inserted Boolean
|
||||
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
recipient Recipient @relation(fields: [recipientId], references: [id], onDelete: Cascade)
|
||||
signature Signature?
|
||||
fieldMeta Json? /// [FieldMeta] @zod.custom.use(ZFieldMetaNotOptionalSchema)
|
||||
id Int @id @default(autoincrement())
|
||||
secondaryId String @unique @default(cuid())
|
||||
envelopeId String
|
||||
envelopeItemId String
|
||||
recipientId Int
|
||||
type FieldType
|
||||
page Int /// @zod.number.describe("The page number of the field on the document. Starts from 1.")
|
||||
positionX Decimal @default(0)
|
||||
positionY Decimal @default(0)
|
||||
width Decimal @default(-1)
|
||||
height Decimal @default(-1)
|
||||
customText String
|
||||
inserted Boolean
|
||||
envelopeItem EnvelopeItem @relation(fields: [envelopeItemId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
recipient Recipient @relation(fields: [recipientId], references: [id], onDelete: Cascade)
|
||||
signature Signature?
|
||||
fieldMeta Json? /// [FieldMeta] @zod.custom.use(ZFieldMetaNotOptionalSchema)
|
||||
|
||||
@@index([documentId])
|
||||
@@index([templateId])
|
||||
@@index([envelopeId])
|
||||
@@index([recipientId])
|
||||
}
|
||||
|
||||
@ -594,13 +611,13 @@ model DocumentShareLink {
|
||||
id Int @id @default(autoincrement())
|
||||
email String
|
||||
slug String @unique
|
||||
documentId Int
|
||||
envelopeId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([documentId, email])
|
||||
@@unique([envelopeId, email])
|
||||
}
|
||||
|
||||
enum OrganisationType {
|
||||
@ -814,8 +831,7 @@ model Team {
|
||||
|
||||
profile TeamProfile?
|
||||
|
||||
documents Document[]
|
||||
templates Template[]
|
||||
envelopes Envelope[]
|
||||
folders Folder[]
|
||||
apiTokens ApiToken[]
|
||||
webhooks Webhook[]
|
||||
@ -853,53 +869,16 @@ enum TemplateType {
|
||||
PRIVATE
|
||||
}
|
||||
|
||||
/// @zod.import(["import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';"])
|
||||
model Template {
|
||||
id Int @id @default(autoincrement())
|
||||
externalId String?
|
||||
type TemplateType @default(PRIVATE)
|
||||
title String
|
||||
visibility DocumentVisibility @default(EVERYONE)
|
||||
authOptions Json? /// [DocumentAuthOptions] @zod.custom.use(ZDocumentAuthOptionsSchema)
|
||||
templateMeta DocumentMeta?
|
||||
templateDocumentDataId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
publicTitle String @default("")
|
||||
publicDescription String @default("")
|
||||
|
||||
useLegacyFieldInsertion Boolean @default(false)
|
||||
|
||||
userId Int
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
teamId Int
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
|
||||
|
||||
recipients Recipient[]
|
||||
fields Field[]
|
||||
directLink TemplateDirectLink?
|
||||
documents Document[]
|
||||
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
folderId String?
|
||||
|
||||
@@unique([templateDocumentDataId])
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model TemplateDirectLink {
|
||||
id String @id @unique @default(cuid())
|
||||
templateId Int @unique
|
||||
envelopeId String @unique
|
||||
token String @unique
|
||||
createdAt DateTime @default(now())
|
||||
enabled Boolean
|
||||
|
||||
directTemplateRecipientId Int
|
||||
|
||||
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
envelope Envelope @relation(fields: [envelopeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model SiteSettings {
|
||||
@ -1026,3 +1005,8 @@ model OrganisationAuthenticationPortal {
|
||||
autoProvisionUsers Boolean @default(true)
|
||||
allowedDomains String[] @default([])
|
||||
}
|
||||
|
||||
model Counter {
|
||||
id String @id
|
||||
value Int
|
||||
}
|
||||
|
||||
@ -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,35 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
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 +130,19 @@ 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,
|
||||
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 +151,7 @@ export const seedTeamDocumentWithMeta = async (team: Team) => {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.document.update({
|
||||
await prisma.envelope.update({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -151,11 +169,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 +180,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 +221,23 @@ export const seedTeamTemplateWithMeta = async (team: Team) => {
|
||||
|
||||
const ownerUser = organisation.owner;
|
||||
|
||||
const template = await createTemplate({
|
||||
const template = await createEnvelope({
|
||||
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 +249,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 +260,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 +293,39 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -296,22 +341,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 +365,7 @@ export const seedDraftDocument = async (
|
||||
|
||||
type CreateDocumentOptions = {
|
||||
key?: string | number;
|
||||
createDocumentOptions?: Partial<Prisma.DocumentUncheckedCreateInput>;
|
||||
createDocumentOptions?: Partial<Prisma.EnvelopeUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
export const seedPendingDocument = async (
|
||||
@ -342,16 +384,35 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -367,11 +428,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 +439,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 +471,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 +488,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 +503,7 @@ export const seedPendingDocumentNoFields = async ({
|
||||
});
|
||||
|
||||
const latestDocument = updateDocumentOptions
|
||||
? await prisma.document.update({
|
||||
? await prisma.envelope.update({
|
||||
where: {
|
||||
id: document.id,
|
||||
},
|
||||
@ -468,12 +527,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 +553,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 +565,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 +577,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 +619,35 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
userId: sender.id,
|
||||
...createDocumentOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const recipient of recipients) {
|
||||
@ -582,11 +663,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 +674,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,27 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
userId: exampleUser.user.id,
|
||||
teamId: exampleUser.team.id,
|
||||
recipients: {
|
||||
@ -73,11 +92,27 @@ 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,
|
||||
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,
|
||||
},
|
||||
},
|
||||
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,38 @@ 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,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title: `[TEST] Template ${key}`,
|
||||
teamId,
|
||||
templateDocumentDataId: documentData.id,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title: `[TEST] Template ${key}`,
|
||||
documentDataId: documentData.id,
|
||||
},
|
||||
},
|
||||
userId: owner.id,
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
...createTemplateOptions,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -63,19 +97,29 @@ 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,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title,
|
||||
templateDocumentData: {
|
||||
connect: {
|
||||
id: documentData.id,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title,
|
||||
documentDataId: documentData.id,
|
||||
},
|
||||
},
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
userId,
|
||||
teamId,
|
||||
recipients: {
|
||||
create: {
|
||||
email: 'recipient.1@documenso.com',
|
||||
@ -87,9 +131,11 @@ export const seedTemplate = async (options: SeedTemplateOptions) => {
|
||||
role: RecipientRole.SIGNER,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
connect: {
|
||||
id: teamId,
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
include: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -107,19 +153,29 @@ 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,
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
title,
|
||||
templateDocumentData: {
|
||||
connect: {
|
||||
id: documentData.id,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
envelopeItems: {
|
||||
create: {
|
||||
id: prefixedId('envelope_item'),
|
||||
title,
|
||||
documentDataId: documentData.id,
|
||||
},
|
||||
},
|
||||
source: DocumentSource.TEMPLATE,
|
||||
documentMetaId: documentMeta.id,
|
||||
userId,
|
||||
teamId,
|
||||
recipients: {
|
||||
create: {
|
||||
email: DIRECT_TEMPLATE_RECIPIENT_EMAIL,
|
||||
@ -127,11 +183,6 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
token: Math.random().toString().slice(2, 7),
|
||||
},
|
||||
},
|
||||
team: {
|
||||
connect: {
|
||||
id: teamId,
|
||||
},
|
||||
},
|
||||
...options.createTemplateOptions,
|
||||
},
|
||||
include: {
|
||||
@ -150,14 +201,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 +217,11 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
|
||||
fields: true,
|
||||
recipients: true,
|
||||
team: true,
|
||||
envelopeItems: {
|
||||
select: {
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
53
packages/prisma/types/document-legacy-schema.ts
Normal file
53
packages/prisma/types/document-legacy-schema.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Legacy Document schema to confirm backwards API compatibility since
|
||||
* we migrated Documents to Envelopes.
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
|
||||
|
||||
import DocumentStatusSchema from '../generated/zod/inputTypeSchemas/DocumentStatusSchema';
|
||||
import DocumentVisibilitySchema from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
|
||||
|
||||
const DocumentSourceSchema = z.enum(['DOCUMENT', 'TEMPLATE', 'TEMPLATE_DIRECT_LINK']);
|
||||
|
||||
/////////////////////////////////////////
|
||||
// DOCUMENT SCHEMA
|
||||
/////////////////////////////////////////
|
||||
|
||||
export const LegacyDocumentSchema = z.object({
|
||||
visibility: DocumentVisibilitySchema,
|
||||
status: DocumentStatusSchema,
|
||||
source: DocumentSourceSchema,
|
||||
id: z.number(),
|
||||
qrToken: z
|
||||
.string()
|
||||
.describe('The token for viewing the document using the QR code on the certificate.')
|
||||
.nullable(),
|
||||
externalId: z
|
||||
.string()
|
||||
.describe('A custom external ID you can use to identify the document.')
|
||||
.nullable(),
|
||||
userId: z.number().describe('The ID of the user that created this document.'),
|
||||
teamId: z.number(),
|
||||
/**
|
||||
* [DocumentAuthOptions]
|
||||
*/
|
||||
authOptions: ZDocumentAuthOptionsSchema.nullable(),
|
||||
/**
|
||||
* [DocumentFormValues]
|
||||
*/
|
||||
formValues: ZDocumentFormValuesSchema.nullable(),
|
||||
title: z.string(),
|
||||
// documentDataId: z.string(), // Todo: Migration
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
completedAt: z.coerce.date().nullable(),
|
||||
deletedAt: z.coerce.date().nullable(),
|
||||
templateId: z.number().nullable(),
|
||||
useLegacyFieldInsertion: z.boolean(),
|
||||
folderId: z.string().nullable(),
|
||||
});
|
||||
|
||||
export type Document = z.infer<typeof LegacyDocumentSchema>;
|
||||
@ -1,10 +1,10 @@
|
||||
import type { Document, DocumentData, Recipient } from '@prisma/client';
|
||||
import type { DocumentData, Envelope, Recipient } from '@prisma/client';
|
||||
|
||||
export type DocumentWithRecipients = Document & {
|
||||
export type EnvelopeWithRecipients = Envelope & {
|
||||
recipients: Recipient[];
|
||||
};
|
||||
|
||||
export type DocumentWithRecipient = Document & {
|
||||
export type EnvelopeWithRecipient = Envelope & {
|
||||
recipients: Recipient[];
|
||||
documentData: DocumentData;
|
||||
};
|
||||
|
||||
35
packages/prisma/types/template-legacy-schema.ts
Normal file
35
packages/prisma/types/template-legacy-schema.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Legacy Template schema to confirm backwards API compatibility since
|
||||
* we removed the "Template" prisma schema model.
|
||||
*/
|
||||
import { TemplateType } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||
|
||||
import { DocumentVisibilitySchema } from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
|
||||
|
||||
export const TemplateTypeSchema = z.nativeEnum(TemplateType);
|
||||
|
||||
export const TemplateSchema = z.object({
|
||||
type: TemplateTypeSchema,
|
||||
visibility: DocumentVisibilitySchema,
|
||||
id: z.number(),
|
||||
externalId: z.string().nullable(),
|
||||
title: z.string(),
|
||||
/**
|
||||
* [DocumentAuthOptions]
|
||||
*/
|
||||
authOptions: ZDocumentAuthOptionsSchema.nullable(),
|
||||
// templateDocumentDataId: z.string(), // Todo: Migration - Removal.
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
publicTitle: z.string(),
|
||||
publicDescription: z.string(),
|
||||
useLegacyFieldInsertion: z.boolean(),
|
||||
userId: z.number(),
|
||||
teamId: z.number(),
|
||||
folderId: z.string().nullable(),
|
||||
});
|
||||
|
||||
export type Template = z.infer<typeof TemplateSchema>;
|
||||
Reference in New Issue
Block a user