chore: extract shared audit log query logic

This commit is contained in:
Ephraim Atta-Duncan
2025-11-22 23:24:40 +00:00
parent e7affea053
commit fc513800ae
6 changed files with 154 additions and 223 deletions

View File

@ -12,34 +12,18 @@ export const findEnvelopeAuditLogsRoute = authenticatedProcedure
.input(ZFindEnvelopeAuditLogsRequestSchema)
.output(ZFindEnvelopeAuditLogsResponseSchema)
.query(async ({ input, ctx }) => {
const { teamId } = ctx;
const {
page,
perPage,
envelopeId,
cursor,
filterForRecentActivity,
eventTypes,
orderByColumn,
orderByDirection,
} = input;
const { orderByColumn, orderByDirection, ...auditLogParams } = input;
ctx.logger.info({
input: {
envelopeId,
envelopeId: input.envelopeId,
},
});
return await findEnvelopeAuditLogs({
...auditLogParams,
userId: ctx.user.id,
teamId,
page,
perPage,
envelopeId,
cursor,
filterForRecentActivity,
eventTypes,
teamId: ctx.teamId,
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
});
});

View File

@ -22,10 +22,6 @@ export const ZFindEnvelopeAuditLogsRequestSchema = ZFindSearchParamsSchema.exten
.describe('Envelope ID (e.g., envelope_xxx) or legacy document ID (e.g., 12345)'),
cursor: z.string().optional(),
filterForRecentActivity: z.boolean().optional(),
eventTypes: z
.array(z.string())
.optional()
.describe('Filter by specific event types (e.g., ["DOCUMENT_CREATED", "DOCUMENT_SENT"])'),
orderByColumn: z.enum(['createdAt', 'type']).optional(),
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
});