mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +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 {
|
||||
ZCreateAuditLogMutationSchema,
|
||||
ZCreateDocumentRequestSchema,
|
||||
ZCreateDocumentV2RequestSchema,
|
||||
ZCreateDocumentV2ResponseSchema,
|
||||
@ -629,27 +630,29 @@ export const documentRouter = router({
|
||||
};
|
||||
}),
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
createAuditLog: authenticatedProcedure
|
||||
.input(
|
||||
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(),
|
||||
}),
|
||||
}),
|
||||
)
|
||||
.input(ZCreateAuditLogMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId } = ctx;
|
||||
const { documentId, type, data } = input;
|
||||
|
||||
console.log('input', input);
|
||||
console.log('copiedddd');
|
||||
const document = await getDocumentById({
|
||||
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({
|
||||
type,
|
||||
data,
|
||||
@ -658,7 +661,5 @@ export const documentRouter = router({
|
||||
metadata: ctx.metadata,
|
||||
}),
|
||||
});
|
||||
|
||||
return auditLog;
|
||||
}),
|
||||
});
|
||||
|
||||
@ -326,6 +326,18 @@ export const ZDownloadCertificateMutationSchema = z.object({
|
||||
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({
|
||||
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.'),
|
||||
|
||||
Reference in New Issue
Block a user