feat: create sharing id for each recipient

This commit is contained in:
Ephraim Atta-Duncan
2023-08-29 18:23:52 +00:00
committed by Mythie
parent 1bce169228
commit ebcd7c78e4
12 changed files with 170 additions and 102 deletions

View File

@ -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;

View 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.',
});
}
}),
});

View 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>;