feat: migrate templates and documents to envelope model

This commit is contained in:
David Nguyen
2025-09-11 18:23:38 +10:00
parent eec2307634
commit bf89bc781b
234 changed files with 8677 additions and 6054 deletions

View File

@ -1,14 +1,22 @@
import type { EnvelopeType } from '@prisma/client';
import { prisma } from '@documenso/prisma';
export type GetEntireDocumentOptions = {
id: number;
import { AppError, AppErrorCode } from '../../errors/app-error';
import type { EnvelopeIdOptions } from '../../utils/envelope';
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
export type unsafeGetEntireEnvelopeOptions = {
id: EnvelopeIdOptions;
type: EnvelopeType;
};
export const getEntireDocument = async ({ id }: GetEntireDocumentOptions) => {
const document = await prisma.document.findFirstOrThrow({
where: {
id,
},
/**
* An unauthenticated function that returns the whole envelope
*/
export const unsafeGetEntireEnvelope = async ({ id, type }: unsafeGetEntireEnvelopeOptions) => {
const envelope = await prisma.envelope.findFirst({
where: unsafeBuildEnvelopeIdQuery(id, type),
include: {
documentMeta: true,
user: {
@ -30,5 +38,11 @@ export const getEntireDocument = async ({ id }: GetEntireDocumentOptions) => {
},
});
return document;
if (!envelope) {
throw new AppError(AppErrorCode.NOT_FOUND, {
message: 'Envelope not found',
});
}
return envelope;
};