feat: create sharing id for each recipient

This commit is contained in:
Ephraim Atta-Duncan
2023-08-29 18:23:52 +00:00
parent e8559cecd5
commit 874d919a6a
13 changed files with 163 additions and 68 deletions

View File

@ -1,4 +1,3 @@
import 'zod';
import { z } from 'zod';
export const ZSignUpMutationSchema = z.object({

View File

@ -2,6 +2,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({
@ -10,6 +11,7 @@ export const appRouter = router({
profile: profileRouter,
document: documentRouter,
field: fieldRouter,
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>;