mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 17:51:49 +10:00
fix: self sign team documents
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -17,8 +17,5 @@
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,6 +313,7 @@ export const EditDocumentForm = ({
|
||||
if (hasSameOwnerAsRecipient) {
|
||||
await selfSignDocument({
|
||||
documentId: document.id,
|
||||
teamId: team?.id,
|
||||
});
|
||||
|
||||
router.push(`/sign/${recipients[0].token}`);
|
||||
|
||||
@ -12,12 +12,14 @@ import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
|
||||
export type SelfSignDocumentOptions = {
|
||||
documentId: number;
|
||||
userId: number;
|
||||
teamId?: number;
|
||||
requestMetadata?: RequestMetadata;
|
||||
};
|
||||
|
||||
export const selfSignDocument = async ({
|
||||
documentId,
|
||||
userId,
|
||||
teamId,
|
||||
requestMetadata,
|
||||
}: SelfSignDocumentOptions) => {
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
@ -31,11 +33,24 @@ export const selfSignDocument = async ({
|
||||
},
|
||||
});
|
||||
|
||||
const document = await prisma.document.findFirstOrThrow({
|
||||
const document = await prisma.document.findUnique({
|
||||
where: {
|
||||
id: documentId,
|
||||
userId,
|
||||
teamId: null,
|
||||
...(teamId
|
||||
? {
|
||||
team: {
|
||||
id: teamId,
|
||||
members: {
|
||||
some: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
userId,
|
||||
teamId: null,
|
||||
}),
|
||||
},
|
||||
include: {
|
||||
Recipient: {
|
||||
|
||||
@ -458,11 +458,12 @@ export const documentRouter = router({
|
||||
.input(ZSelfSignDocumentMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { documentId } = input;
|
||||
const { documentId, teamId } = input;
|
||||
|
||||
return await selfSignDocument({
|
||||
userId: ctx.user.id,
|
||||
documentId,
|
||||
teamId,
|
||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@ -172,6 +172,7 @@ export const ZSendDocumentMutationSchema = z.object({
|
||||
|
||||
export const ZSelfSignDocumentMutationSchema = z.object({
|
||||
documentId: z.number(),
|
||||
teamId: z.number().optional(),
|
||||
});
|
||||
|
||||
export const ZSetPasswordForDocumentMutationSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user