mirror of
https://github.com/documenso/documenso.git
synced 2026-07-11 13:35:20 +10:00
f3f5903760
Merge origin/main into feat/document-file-conversion. Conflicts were format-only (Tailwind class ordering, single-line vs multi-line) plus two semantic merges: - files.helpers.ts: combine main's pending-PDF download path with the branch's original-source-file (DOCX/PNG/JPEG) download path - download-pdf.ts: combine main's versionToFilenameSuffix helper with the branch's server-provided Content-Disposition filename support
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
|
|
|
import { mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
|
|
|
export type GetDocumentByAccessTokenOptions = {
|
|
token: string;
|
|
};
|
|
|
|
export const getDocumentByAccessToken = async ({ token }: GetDocumentByAccessTokenOptions) => {
|
|
if (!token) {
|
|
throw new Error('Missing token');
|
|
}
|
|
|
|
const result = await prisma.envelope.findFirst({
|
|
where: {
|
|
type: EnvelopeType.DOCUMENT,
|
|
status: DocumentStatus.COMPLETED,
|
|
qrToken: token,
|
|
},
|
|
// Do not provide extra information that is not needed.
|
|
select: {
|
|
id: true,
|
|
secondaryId: true,
|
|
internalVersion: true,
|
|
title: true,
|
|
completedAt: true,
|
|
team: {
|
|
select: {
|
|
url: true,
|
|
},
|
|
},
|
|
envelopeItems: {
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
order: true,
|
|
documentDataId: true,
|
|
envelopeId: true,
|
|
documentData: {
|
|
select: {
|
|
id: true,
|
|
type: true,
|
|
data: true,
|
|
initialData: true,
|
|
originalMimeType: true,
|
|
originalData: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
_count: {
|
|
select: {
|
|
recipients: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!result) {
|
|
return null;
|
|
}
|
|
|
|
if (result.envelopeItems.length === 0) {
|
|
throw new Error('Completed envelope has no items');
|
|
}
|
|
|
|
const firstDocumentData = result.envelopeItems[0].documentData;
|
|
|
|
if (!firstDocumentData) {
|
|
throw new Error('Missing document data');
|
|
}
|
|
|
|
return {
|
|
id: mapSecondaryIdToDocumentId(result.secondaryId),
|
|
internalVersion: result.internalVersion,
|
|
title: result.title,
|
|
completedAt: result.completedAt,
|
|
envelopeItems: result.envelopeItems,
|
|
recipientCount: result._count.recipients,
|
|
documentTeamUrl: result.team.url,
|
|
};
|
|
};
|