mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: migrate templates and documents to envelope model
This commit is contained in:
@ -1,10 +1,19 @@
|
||||
import type { Document, DocumentMeta, OrganisationGlobalSettings } from '@prisma/client';
|
||||
import type {
|
||||
DocumentMeta,
|
||||
Envelope,
|
||||
OrganisationGlobalSettings,
|
||||
Recipient,
|
||||
Team,
|
||||
User,
|
||||
} from '@prisma/client';
|
||||
import { DocumentDistributionMethod, DocumentSigningOrder, DocumentStatus } from '@prisma/client';
|
||||
|
||||
import { DEFAULT_DOCUMENT_TIME_ZONE } from '../constants/time-zones';
|
||||
import type { TDocumentLite, TDocumentMany } from '../types/document';
|
||||
import { DEFAULT_DOCUMENT_EMAIL_SETTINGS } from '../types/document-email';
|
||||
import { mapSecondaryIdToDocumentId } from './envelope';
|
||||
|
||||
export const isDocumentCompleted = (document: Pick<Document, 'status'> | DocumentStatus) => {
|
||||
export const isDocumentCompleted = (document: Pick<Envelope, 'status'> | DocumentStatus) => {
|
||||
const status = typeof document === 'string' ? document : document.status;
|
||||
|
||||
return status === DocumentStatus.COMPLETED || status === DocumentStatus.REJECTED;
|
||||
@ -36,7 +45,6 @@ export const extractDerivedDocumentMeta = (
|
||||
dateFormat: meta.dateFormat || settings.documentDateFormat,
|
||||
message: meta.message || null,
|
||||
subject: meta.subject || null,
|
||||
password: meta.password || null,
|
||||
redirectUrl: meta.redirectUrl || null,
|
||||
|
||||
signingOrder: meta.signingOrder || DocumentSigningOrder.PARALLEL,
|
||||
@ -53,5 +61,81 @@ export const extractDerivedDocumentMeta = (
|
||||
emailReplyTo: meta.emailReplyTo ?? settings.emailReplyTo,
|
||||
emailSettings:
|
||||
meta.emailSettings || settings.emailDocumentSettings || DEFAULT_DOCUMENT_EMAIL_SETTINGS,
|
||||
} satisfies Omit<DocumentMeta, 'id' | 'documentId' | 'templateId'>;
|
||||
} satisfies Omit<DocumentMeta, 'id'>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Map an envelope to a legacy document lite response entity.
|
||||
*
|
||||
* Do not use spread operator here to avoid unexpected behavior.
|
||||
*/
|
||||
export const mapEnvelopeToDocumentLite = (envelope: Envelope): TDocumentLite => {
|
||||
const documentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||
|
||||
return {
|
||||
id: documentId, // Use legacy ID.
|
||||
visibility: envelope.visibility,
|
||||
status: envelope.status,
|
||||
source: envelope.source,
|
||||
externalId: envelope.externalId,
|
||||
userId: envelope.userId,
|
||||
authOptions: envelope.authOptions,
|
||||
formValues: envelope.formValues,
|
||||
title: envelope.title,
|
||||
createdAt: envelope.createdAt,
|
||||
updatedAt: envelope.updatedAt,
|
||||
completedAt: envelope.completedAt,
|
||||
deletedAt: envelope.deletedAt,
|
||||
teamId: envelope.teamId,
|
||||
folderId: envelope.folderId,
|
||||
useLegacyFieldInsertion: envelope.useLegacyFieldInsertion,
|
||||
templateId: envelope.templateId,
|
||||
};
|
||||
};
|
||||
|
||||
type MapEnvelopeToDocumentManyOptions = Envelope & {
|
||||
user: Pick<User, 'id' | 'name' | 'email'>;
|
||||
team: Pick<Team, 'id' | 'url'>;
|
||||
recipients: Recipient[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Map an envelope to a legacy document many response entity.
|
||||
*
|
||||
* Do not use spread operator here to avoid unexpected behavior.
|
||||
*/
|
||||
export const mapEnvelopesToDocumentMany = (
|
||||
envelope: MapEnvelopeToDocumentManyOptions,
|
||||
): TDocumentMany => {
|
||||
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||
|
||||
return {
|
||||
id: legacyDocumentId, // Use legacy ID.
|
||||
visibility: envelope.visibility,
|
||||
status: envelope.status,
|
||||
source: envelope.source,
|
||||
externalId: envelope.externalId,
|
||||
userId: envelope.userId,
|
||||
authOptions: envelope.authOptions,
|
||||
formValues: envelope.formValues,
|
||||
title: envelope.title,
|
||||
createdAt: envelope.createdAt,
|
||||
updatedAt: envelope.updatedAt,
|
||||
completedAt: envelope.completedAt,
|
||||
deletedAt: envelope.deletedAt,
|
||||
teamId: envelope.teamId,
|
||||
folderId: envelope.folderId,
|
||||
useLegacyFieldInsertion: envelope.useLegacyFieldInsertion,
|
||||
templateId: envelope.templateId,
|
||||
user: {
|
||||
id: envelope.userId,
|
||||
name: envelope.user.name,
|
||||
email: envelope.user.email,
|
||||
},
|
||||
team: {
|
||||
id: envelope.teamId,
|
||||
url: envelope.team.url,
|
||||
},
|
||||
recipients: envelope.recipients,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user