mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 03:32:14 +10:00
fix: create audit log router
This commit is contained in:
@ -31,6 +31,7 @@ import { DocumentDataType, DocumentStatus } from '@documenso/prisma/client';
|
|||||||
|
|
||||||
import { authenticatedProcedure, procedure, router } from '../trpc';
|
import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||||
import {
|
import {
|
||||||
|
ZCreateAuditLogMutationSchema,
|
||||||
ZCreateDocumentRequestSchema,
|
ZCreateDocumentRequestSchema,
|
||||||
ZCreateDocumentV2RequestSchema,
|
ZCreateDocumentV2RequestSchema,
|
||||||
ZCreateDocumentV2ResponseSchema,
|
ZCreateDocumentV2ResponseSchema,
|
||||||
@ -629,27 +630,29 @@ export const documentRouter = router({
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
createAuditLog: authenticatedProcedure
|
createAuditLog: authenticatedProcedure
|
||||||
.input(
|
.input(ZCreateAuditLogMutationSchema)
|
||||||
z.object({
|
|
||||||
documentId: z.number(),
|
|
||||||
type: z.literal('DOCUMENT_SIGNING_LINK_COPIED'),
|
|
||||||
data: z.object({
|
|
||||||
recipientEmail: z.string(),
|
|
||||||
recipientName: z.string(),
|
|
||||||
recipientId: z.number(),
|
|
||||||
recipientRole: z.string(),
|
|
||||||
isBulkCopy: z.boolean(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const { teamId } = ctx;
|
||||||
const { documentId, type, data } = input;
|
const { documentId, type, data } = input;
|
||||||
|
|
||||||
console.log('input', input);
|
const document = await getDocumentById({
|
||||||
console.log('copiedddd');
|
documentId,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
teamId,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
const auditLog = await prisma.documentAuditLog.create({
|
if (!document || (teamId && document.teamId !== teamId)) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: 'FORBIDDEN',
|
||||||
|
message: 'You do not have access to this document.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type,
|
type,
|
||||||
data,
|
data,
|
||||||
@ -658,7 +661,5 @@ export const documentRouter = router({
|
|||||||
metadata: ctx.metadata,
|
metadata: ctx.metadata,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
return auditLog;
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -326,6 +326,18 @@ export const ZDownloadCertificateMutationSchema = z.object({
|
|||||||
documentId: z.number(),
|
documentId: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const ZCreateAuditLogMutationSchema = z.object({
|
||||||
|
documentId: z.number(),
|
||||||
|
type: z.literal('DOCUMENT_SIGNING_LINK_COPIED'),
|
||||||
|
data: z.object({
|
||||||
|
recipientEmail: z.string(),
|
||||||
|
recipientName: z.string(),
|
||||||
|
recipientId: z.number(),
|
||||||
|
recipientRole: z.string(),
|
||||||
|
isBulkCopy: z.boolean(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
export const ZMoveDocumentToTeamSchema = z.object({
|
export const ZMoveDocumentToTeamSchema = z.object({
|
||||||
documentId: z.number().describe('The ID of the document to move to a team.'),
|
documentId: z.number().describe('The ID of the document to move to a team.'),
|
||||||
teamId: z.number().describe('The ID of the team to move the document to.'),
|
teamId: z.number().describe('The ID of the team to move the document to.'),
|
||||||
|
|||||||
Reference in New Issue
Block a user