fix: create audit log router

This commit is contained in:
Ephraim Atta-Duncan
2025-01-20 03:42:52 +00:00
parent cc3995ce74
commit de31769415
2 changed files with 31 additions and 18 deletions

View File

@ -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;
}),
});

View File

@ -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.'),