mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
fix: additional backwards compat
This commit is contained in:
@ -40,6 +40,7 @@ export const getDocumentWithDetailsById = async ({
|
||||
fields: envelope.fields.map((field) => ({
|
||||
...field,
|
||||
documentId: legacyDocumentId,
|
||||
templateId: null,
|
||||
})),
|
||||
user: {
|
||||
id: envelope.userId,
|
||||
@ -50,6 +51,16 @@ export const getDocumentWithDetailsById = async ({
|
||||
id: envelope.teamId,
|
||||
url: envelope.team.url,
|
||||
},
|
||||
recipients: envelope.recipients,
|
||||
recipients: envelope.recipients.map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: legacyDocumentId,
|
||||
templateId: null,
|
||||
})),
|
||||
documentDataId: firstDocumentData.id,
|
||||
documentMeta: {
|
||||
...envelope.documentMeta,
|
||||
documentId: legacyDocumentId,
|
||||
password: null,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -265,6 +265,8 @@ export const createEnvelope = async ({
|
||||
},
|
||||
});
|
||||
|
||||
const firstEnvelopeItem = envelope.envelopeItems[0];
|
||||
|
||||
await Promise.all(
|
||||
(data.recipients || []).map(async (recipient) => {
|
||||
const recipientAuthOptions = createRecipientAuthOptions({
|
||||
@ -272,44 +274,37 @@ export const createEnvelope = async ({
|
||||
actionAuth: recipient.actionAuth ?? [],
|
||||
});
|
||||
|
||||
// Todo: Envelopes - Allow fields.
|
||||
// const recipientFieldsToCreate = (recipient.fields || []).map((field) => {
|
||||
// let envelopeItemId = envelope.envelopeItems[0].id;?
|
||||
const recipientFieldsToCreate = (recipient.fields || []).map((field) => {
|
||||
let envelopeItemId = firstEnvelopeItem.id;
|
||||
|
||||
// const foundEnvelopeItem = envelope.envelopeItems.find(
|
||||
// (item) => item.documentDataId === field.documentDataId,
|
||||
// );
|
||||
if (field.documentDataId) {
|
||||
const foundEnvelopeItem = envelope.envelopeItems.find(
|
||||
(item) => item.documentDataId === field.documentDataId,
|
||||
);
|
||||
|
||||
// if (field.documentDataId && !foundEnvelopeItem) {
|
||||
// throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
// message: 'Envelope item not found',
|
||||
// });
|
||||
// }
|
||||
if (!foundEnvelopeItem) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Document data not found',
|
||||
});
|
||||
}
|
||||
|
||||
// if (foundEnvelopeItem) {
|
||||
// envelopeItemId = foundEnvelopeItem.id;
|
||||
// }
|
||||
envelopeItemId = foundEnvelopeItem.id;
|
||||
}
|
||||
|
||||
// if (!envelopeItemId) {
|
||||
// throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
// message: 'Envelope item not found',
|
||||
// });
|
||||
// }
|
||||
|
||||
// return {
|
||||
// envelopeId: envelope.id,
|
||||
// envelopeItemId,
|
||||
// type: field.type,
|
||||
// page: field.page,
|
||||
// positionX: field.positionX,
|
||||
// positionY: field.positionY,
|
||||
// width: field.width,
|
||||
// height: field.height,
|
||||
// customText: '',
|
||||
// inserted: false,
|
||||
// fieldMeta: field.fieldMeta || undefined,
|
||||
// };
|
||||
// });
|
||||
return {
|
||||
envelopeId: envelope.id,
|
||||
envelopeItemId,
|
||||
type: field.type,
|
||||
page: field.page,
|
||||
positionX: field.positionX,
|
||||
positionY: field.positionY,
|
||||
width: field.width,
|
||||
height: field.height,
|
||||
customText: '',
|
||||
inserted: false,
|
||||
fieldMeta: field.fieldMeta || undefined,
|
||||
};
|
||||
});
|
||||
|
||||
await tx.recipient.create({
|
||||
data: {
|
||||
@ -323,11 +318,11 @@ export const createEnvelope = async ({
|
||||
signingStatus:
|
||||
recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED,
|
||||
authOptions: recipientAuthOptions,
|
||||
// fields: {
|
||||
// createMany: {
|
||||
// data: recipientFieldsToCreate,
|
||||
// },
|
||||
// },
|
||||
fields: {
|
||||
createMany: {
|
||||
data: recipientFieldsToCreate,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
@ -116,9 +116,14 @@ const ZEnvelopeForSigningResponse = z.object({
|
||||
signingOrder: true,
|
||||
rejectionReason: true,
|
||||
}).extend({
|
||||
fields: ZFieldSchema.extend({
|
||||
signature: SignatureSchema.nullish(),
|
||||
}).array(),
|
||||
fields: ZFieldSchema.omit({
|
||||
documentId: true,
|
||||
templateId: true,
|
||||
})
|
||||
.extend({
|
||||
signature: SignatureSchema.nullish(),
|
||||
})
|
||||
.array(),
|
||||
}),
|
||||
recipientSignature: SignatureSchema.pick({
|
||||
signatureImageAsBase64: true,
|
||||
|
||||
@ -8,6 +8,7 @@ import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -162,6 +163,6 @@ export const createEnvelopeFields = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
fields: createdFields,
|
||||
fields: createdFields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||
};
|
||||
};
|
||||
|
||||
@ -3,6 +3,7 @@ import type { EnvelopeType } from '@prisma/client';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { buildTeamWhereQuery } from '../../utils/teams';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -56,5 +57,5 @@ export const getFieldById = async ({
|
||||
});
|
||||
}
|
||||
|
||||
return field;
|
||||
return mapFieldToLegacyField(field, envelope);
|
||||
};
|
||||
|
||||
@ -25,6 +25,7 @@ import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -345,7 +346,9 @@ export const setFieldsForDocument = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
fields: [...filteredFields, ...persistedFields],
|
||||
fields: [...filteredFields, ...persistedFields].map((field) =>
|
||||
mapFieldToLegacyField(field, envelope),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export type SetFieldsForTemplateOptions = {
|
||||
@ -240,6 +241,8 @@ export const setFieldsForTemplate = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
fields: [...filteredFields, ...persistedFields],
|
||||
fields: [...filteredFields, ...persistedFields].map((field) =>
|
||||
mapFieldToLegacyField(field, envelope),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -146,6 +147,6 @@ export const updateDocumentFields = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
fields: updatedFields,
|
||||
fields: updatedFields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||
};
|
||||
};
|
||||
|
||||
@ -4,6 +4,7 @@ import type { TFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -110,6 +111,6 @@ export const updateTemplateFields = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
fields: updatedFields,
|
||||
fields: updatedFields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||
};
|
||||
};
|
||||
|
||||
@ -12,6 +12,7 @@ import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { mapRecipientToLegacyRecipient } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export interface CreateDocumentRecipientsOptions {
|
||||
@ -133,6 +134,8 @@ export const createDocumentRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: createdRecipients,
|
||||
recipients: createdRecipients.map((recipient) =>
|
||||
mapRecipientToLegacyRecipient(recipient, envelope),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,6 +8,7 @@ import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { mapRecipientToLegacyRecipient } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export interface CreateTemplateRecipientsOptions {
|
||||
@ -107,6 +108,8 @@ export const createTemplateRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: createdRecipients,
|
||||
recipients: createdRecipients.map((recipient) =>
|
||||
mapRecipientToLegacyRecipient(recipient, template),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
@ -48,14 +47,16 @@ export const getRecipientById = async ({
|
||||
});
|
||||
}
|
||||
|
||||
const legacyId = match(type)
|
||||
.with(EnvelopeType.DOCUMENT, () => ({
|
||||
documentId: mapSecondaryIdToDocumentId(recipient.envelope.secondaryId),
|
||||
}))
|
||||
.with(EnvelopeType.TEMPLATE, () => ({
|
||||
templateId: mapSecondaryIdToTemplateId(recipient.envelope.secondaryId),
|
||||
}))
|
||||
.exhaustive();
|
||||
const legacyId = {
|
||||
documentId:
|
||||
type === EnvelopeType.DOCUMENT
|
||||
? mapSecondaryIdToDocumentId(recipient.envelope.secondaryId)
|
||||
: null,
|
||||
templateId:
|
||||
type === EnvelopeType.TEMPLATE
|
||||
? mapSecondaryIdToTemplateId(recipient.envelope.secondaryId)
|
||||
: null,
|
||||
};
|
||||
|
||||
// Backwards compatibility mapping.
|
||||
return {
|
||||
|
||||
@ -27,7 +27,7 @@ import { getI18nInstance } from '../../client-only/providers/i18n-server';
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||
import { canRecipientBeModified } from '../../utils/recipients';
|
||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||
import { getEmailContext } from '../email/get-email-context';
|
||||
@ -344,7 +344,11 @@ export const setDocumentRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: [...filteredRecipients, ...persistedRecipients],
|
||||
recipients: [...filteredRecipients, ...persistedRecipients].map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||
templateId: null,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
} from '../../types/document-auth';
|
||||
import { nanoid } from '../../universal/id';
|
||||
import { createRecipientAuthOptions } from '../../utils/document-auth';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { type EnvelopeIdOptions, mapSecondaryIdToTemplateId } from '../../utils/envelope';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export type SetTemplateRecipientsOptions = {
|
||||
@ -211,6 +211,10 @@ export const setTemplateRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: [...filteredRecipients, ...persistedRecipients],
|
||||
recipients: [...filteredRecipients, ...persistedRecipients].map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: null,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@ -16,7 +16,8 @@ import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||
import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { canRecipientBeModified } from '../../utils/recipients';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
@ -185,7 +186,12 @@ export const updateDocumentRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: updatedRecipients,
|
||||
recipients: updatedRecipients.map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||
templateId: null,
|
||||
fields: recipient.fields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { mapSecondaryIdToTemplateId } from '../../utils/envelope';
|
||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export interface UpdateTemplateRecipientsOptions {
|
||||
@ -156,6 +158,11 @@ export const updateTemplateRecipients = async ({
|
||||
});
|
||||
|
||||
return {
|
||||
recipients: updatedRecipients,
|
||||
recipients: updatedRecipients.map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: null,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
fields: recipient.fields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@ -48,10 +48,12 @@ export const getTemplateByDirectLinkToken = async ({
|
||||
|
||||
const recipientsWithMappedFields = envelope.recipients.map((recipient) => ({
|
||||
...recipient,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
documentId: null,
|
||||
fields: recipient.fields.map((field) => ({
|
||||
...field,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
documentId: undefined,
|
||||
documentId: null,
|
||||
})),
|
||||
}));
|
||||
|
||||
@ -71,6 +73,7 @@ export const getTemplateByDirectLinkToken = async ({
|
||||
publicTitle: envelope.publicTitle,
|
||||
publicDescription: envelope.publicDescription,
|
||||
folderId: envelope.folderId,
|
||||
templateDocumentDataId: firstDocumentData.id,
|
||||
templateDocumentData: {
|
||||
...firstDocumentData,
|
||||
envelopeItemId: envelope.envelopeItems[0].id,
|
||||
@ -79,7 +82,10 @@ export const getTemplateByDirectLinkToken = async ({
|
||||
...directLink,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
},
|
||||
templateMeta: envelope.documentMeta,
|
||||
templateMeta: {
|
||||
...envelope.documentMeta,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
},
|
||||
recipients: recipientsWithMappedFields,
|
||||
fields: recipientsWithMappedFields.flatMap((recipient) => recipient.fields),
|
||||
};
|
||||
|
||||
@ -68,13 +68,23 @@ export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOpt
|
||||
...rest,
|
||||
envelopeId: envelope.id,
|
||||
type: envelope.templateType,
|
||||
templateDocumentDataId: firstTemplateDocumentData.id,
|
||||
templateDocumentData: {
|
||||
...firstTemplateDocumentData,
|
||||
envelopeItemId: envelope.envelopeItems[0].id,
|
||||
},
|
||||
templateMeta: envelope.documentMeta,
|
||||
templateMeta: {
|
||||
...envelope.documentMeta,
|
||||
templateId: legacyTemplateId,
|
||||
},
|
||||
fields: envelope.fields.map((field) => ({
|
||||
...field,
|
||||
documentId: null,
|
||||
templateId: legacyTemplateId,
|
||||
})),
|
||||
recipients: envelope.recipients.map((recipient) => ({
|
||||
...recipient,
|
||||
documentId: null,
|
||||
templateId: legacyTemplateId,
|
||||
})),
|
||||
directLink: envelope.directLink
|
||||
|
||||
Reference in New Issue
Block a user