mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { procedure } from '../trpc';
|
|
import {
|
|
ZGetDocumentInternalUrlForQRCodeInput,
|
|
ZGetDocumentInternalUrlForQRCodeOutput,
|
|
} from './get-document-internal-url-for-qr-code.types';
|
|
|
|
export const getDocumentInternalUrlForQRCodeRoute = procedure
|
|
.input(ZGetDocumentInternalUrlForQRCodeInput)
|
|
.output(ZGetDocumentInternalUrlForQRCodeOutput)
|
|
.query(async ({ input, ctx }) => {
|
|
const { documentId } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
documentId,
|
|
},
|
|
});
|
|
|
|
if (!ctx.user) {
|
|
return null;
|
|
}
|
|
|
|
const document = await prisma.document.findFirst({
|
|
where: {
|
|
OR: [
|
|
{
|
|
id: documentId,
|
|
userId: ctx.user.id,
|
|
},
|
|
{
|
|
id: documentId,
|
|
team: buildTeamWhereQuery({ teamId: undefined, userId: ctx.user.id }),
|
|
},
|
|
],
|
|
},
|
|
include: {
|
|
team: true,
|
|
},
|
|
});
|
|
|
|
if (!document) {
|
|
return null;
|
|
}
|
|
|
|
return `${NEXT_PUBLIC_WEBAPP_URL()}/t/${document.team.url}/documents/${document.id}`;
|
|
});
|