mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +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,7 +1,10 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import { buildTeamWhereQuery } from '../../utils/teams';
|
||||
import { mapSecondaryIdToTemplateId } from '../../utils/envelope';
|
||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||
|
||||
export type ToggleTemplateDirectLinkOptions = {
|
||||
templateId: number;
|
||||
@ -16,24 +19,31 @@ export const toggleTemplateDirectLink = async ({
|
||||
teamId,
|
||||
enabled,
|
||||
}: ToggleTemplateDirectLinkOptions) => {
|
||||
const template = await prisma.template.findFirst({
|
||||
where: {
|
||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||
type: EnvelopeType.TEMPLATE,
|
||||
id: {
|
||||
type: 'templateId',
|
||||
id: templateId,
|
||||
team: buildTeamWhereQuery({ teamId, userId }),
|
||||
},
|
||||
userId,
|
||||
teamId,
|
||||
});
|
||||
|
||||
const envelope = await prisma.envelope.findFirst({
|
||||
where: envelopeWhereInput,
|
||||
include: {
|
||||
recipients: true,
|
||||
directLink: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!template) {
|
||||
if (!envelope) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Template not found',
|
||||
});
|
||||
}
|
||||
|
||||
const { directLink } = template;
|
||||
const { directLink } = envelope;
|
||||
|
||||
if (!directLink) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
@ -41,13 +51,23 @@ export const toggleTemplateDirectLink = async ({
|
||||
});
|
||||
}
|
||||
|
||||
return await prisma.templateDirectLink.update({
|
||||
const updatedDirectLink = await prisma.templateDirectLink.update({
|
||||
where: {
|
||||
id: directLink.id,
|
||||
},
|
||||
data: {
|
||||
templateId: template.id,
|
||||
envelopeId: envelope.id,
|
||||
enabled,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
id: updatedDirectLink.id,
|
||||
token: updatedDirectLink.token,
|
||||
createdAt: updatedDirectLink.createdAt,
|
||||
enabled: updatedDirectLink.enabled,
|
||||
directTemplateRecipientId: updatedDirectLink.directTemplateRecipientId,
|
||||
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
envelopeId: envelope.id,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user