mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
feat: migrate templates and documents to envelope model
This commit is contained in:
28
packages/trpc/server/document-router/share-document.ts
Normal file
28
packages/trpc/server/document-router/share-document.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { createOrGetShareLink } from '@documenso/lib/server-only/share/create-or-get-share-link';
|
||||
|
||||
import { procedure } from '../trpc';
|
||||
import { ZShareDocumentRequestSchema, ZShareDocumentResponseSchema } from './share-document.types';
|
||||
|
||||
// Note: This is an unauthenticated route.
|
||||
export const shareDocumentRoute = procedure
|
||||
.input(ZShareDocumentRequestSchema)
|
||||
.output(ZShareDocumentResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { documentId, token } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
documentId,
|
||||
},
|
||||
});
|
||||
|
||||
if (token) {
|
||||
return await createOrGetShareLink({ documentId, token });
|
||||
}
|
||||
|
||||
if (!ctx.user?.id) {
|
||||
throw new Error('You must either provide a token or be logged in to create a sharing link.');
|
||||
}
|
||||
|
||||
return await createOrGetShareLink({ documentId, userId: ctx.user.id });
|
||||
});
|
||||
Reference in New Issue
Block a user