chore: remove unnecessary constant extraction and defensive optional chaining

This commit is contained in:
ephraimduncan
2026-03-04 17:08:10 +00:00
parent 77e463e850
commit 5ce4b59f52
9 changed files with 171 additions and 164 deletions
@@ -23,7 +23,6 @@ export const getDocumentByAccessToken = async ({ token }: GetDocumentByAccessTok
type: EnvelopeType.DOCUMENT,
qrToken: token,
},
// Do not provide extra information that is not needed.
select: {
id: true,
secondaryId: true,
@@ -96,10 +95,13 @@ export const getDocumentByAccessToken = async ({ token }: GetDocumentByAccessTok
});
}
const firstDocumentData = result.envelopeItems[0].documentData;
const firstEnvelopeItem = result.envelopeItems[0];
if (!firstDocumentData) {
throw new Error('Missing document data');
if (!firstEnvelopeItem?.documentData) {
throw new AppError(AppErrorCode.NOT_FOUND, {
message: 'Missing document data for QR token',
statusCode: 404,
});
}
return {
@@ -109,6 +111,6 @@ export const getDocumentByAccessToken = async ({ token }: GetDocumentByAccessTok
completedAt: result.completedAt,
envelopeItems: result.envelopeItems,
recipientCount: result._count.recipients,
documentTeamUrl: result.team?.url ?? '',
documentTeamUrl: result.team.url,
};
};