mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 17:21:41 +10:00
fix: additional backwards compat
This commit is contained in:
@ -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)),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user