mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: create sharing id for each recipient
This commit is contained in:
committed by
Mythie
parent
1bce169228
commit
ebcd7c78e4
@ -3,6 +3,7 @@ import { authRouter } from './auth-router/router';
|
||||
import { documentRouter } from './document-router/router';
|
||||
import { fieldRouter } from './field-router/router';
|
||||
import { profileRouter } from './profile-router/router';
|
||||
import { shareRouter } from './share-router/router';
|
||||
import { procedure, router } from './trpc';
|
||||
|
||||
export const appRouter = router({
|
||||
@ -11,7 +12,7 @@ export const appRouter = router({
|
||||
profile: profileRouter,
|
||||
document: documentRouter,
|
||||
field: fieldRouter,
|
||||
admin: adminRouter,
|
||||
share: shareRouter,
|
||||
});
|
||||
|
||||
export type AppRouter = typeof appRouter;
|
||||
|
||||
23
packages/trpc/server/share-router/router.ts
Normal file
23
packages/trpc/server/share-router/router.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
|
||||
import { createSharingId } from '@documenso/lib/server-only/share/create-share-id';
|
||||
|
||||
import { procedure, router } from '../trpc';
|
||||
import { ZShareLinkSchema } from './schema';
|
||||
|
||||
export const shareRouter = router({
|
||||
create: procedure.input(ZShareLinkSchema).mutation(async ({ input }) => {
|
||||
try {
|
||||
const { documentId, recipientId } = input;
|
||||
|
||||
return await createSharingId({ documentId, recipientId });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'We were unable to create a sharing link.',
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
8
packages/trpc/server/share-router/schema.ts
Normal file
8
packages/trpc/server/share-router/schema.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZShareLinkSchema = z.object({
|
||||
documentId: z.number(),
|
||||
recipientId: z.number(),
|
||||
});
|
||||
|
||||
export type ZShareLinkSchema = z.infer<typeof ZShareLinkSchema>;
|
||||
Reference in New Issue
Block a user