feat: add envelopes api

This commit is contained in:
David Nguyen
2025-10-28 12:13:26 +11:00
parent e13b9f7c84
commit f6bdb34b56
50 changed files with 1002 additions and 701 deletions

View File

@ -1,8 +1,10 @@
import { EnvelopeType } from '@prisma/client';
import { match } from 'ts-pattern';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
import { prisma } from '@documenso/prisma';
import { authenticatedProcedure } from '../trpc';
import {
@ -11,12 +13,19 @@ import {
} from './delete-envelope.types';
export const deleteEnvelopeRoute = authenticatedProcedure
// .meta(deleteEnvelopeMeta)
.meta({
openapi: {
method: 'POST',
path: '/envelope/delete',
summary: 'Delete envelope',
tags: ['Envelope'],
},
})
.input(ZDeleteEnvelopeRequestSchema)
.output(ZDeleteEnvelopeResponseSchema)
.mutation(async ({ input, ctx }) => {
const { teamId } = ctx;
const { envelopeId, envelopeType } = input;
const { envelopeId } = input;
ctx.logger.info({
input: {
@ -24,7 +33,22 @@ export const deleteEnvelopeRoute = authenticatedProcedure
},
});
await match(envelopeType)
const unsafeEnvelope = await prisma.envelope.findUnique({
where: {
id: envelopeId,
},
select: {
type: true,
},
});
if (!unsafeEnvelope) {
throw new AppError(AppErrorCode.NOT_FOUND, {
message: 'Envelope not found',
});
}
await match(unsafeEnvelope.type)
.with(EnvelopeType.DOCUMENT, async () =>
deleteDocument({
userId: ctx.user.id,