feat: filter by audit log event type

This commit is contained in:
Ephraim Atta-Duncan
2025-11-22 01:24:13 +00:00
parent 1a577e55a9
commit e7affea053
5 changed files with 25 additions and 3 deletions

View File

@ -20,6 +20,7 @@ export interface FindDocumentAuditLogsOptions {
};
cursor?: string;
filterForRecentActivity?: boolean;
eventTypes?: string[];
}
export const findDocumentAuditLogs = async ({
@ -31,6 +32,7 @@ export const findDocumentAuditLogs = async ({
orderBy,
cursor,
filterForRecentActivity,
eventTypes,
}: FindDocumentAuditLogsOptions) => {
const orderByColumn = orderBy?.column ?? 'createdAt';
const orderByDirection = orderBy?.direction ?? 'desc';
@ -57,7 +59,12 @@ export const findDocumentAuditLogs = async ({
envelopeId: envelope.id,
};
// Filter events down to what we consider recent activity.
if (eventTypes && eventTypes.length > 0) {
whereClause.type = {
in: eventTypes,
};
}
if (filterForRecentActivity) {
whereClause.OR = [
{
@ -130,6 +137,7 @@ export interface FindEnvelopeAuditLogsOptions {
};
cursor?: string;
filterForRecentActivity?: boolean;
eventTypes?: string[];
}
export const findEnvelopeAuditLogs = async ({
@ -141,11 +149,11 @@ export const findEnvelopeAuditLogs = async ({
orderBy,
cursor,
filterForRecentActivity,
eventTypes,
}: FindEnvelopeAuditLogsOptions) => {
const orderByColumn = orderBy?.column ?? 'createdAt';
const orderByDirection = orderBy?.direction ?? 'desc';
// Auto-detect ID type: if it's a numeric string, treat as documentId
const isNumericId = /^\d+$/.test(envelopeId);
const { envelopeWhereInput } = await getEnvelopeWhereInput({
@ -175,7 +183,12 @@ export const findEnvelopeAuditLogs = async ({
envelopeId: envelope.id,
};
// Filter events down to what we consider recent activity.
if (eventTypes && eventTypes.length > 0) {
whereClause.type = {
in: eventTypes,
};
}
if (filterForRecentActivity) {
whereClause.OR = [
{

View File

@ -18,6 +18,7 @@ export const findDocumentAuditLogsRoute = authenticatedProcedure
documentId,
cursor,
filterForRecentActivity,
eventTypes,
orderByColumn,
orderByDirection,
} = input;
@ -36,6 +37,7 @@ export const findDocumentAuditLogsRoute = authenticatedProcedure
documentId,
cursor,
filterForRecentActivity,
eventTypes,
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
});
});

View File

@ -7,6 +7,7 @@ export const ZFindDocumentAuditLogsRequestSchema = ZFindSearchParamsSchema.exten
documentId: z.number().min(1),
cursor: z.string().optional(),
filterForRecentActivity: z.boolean().optional(),
eventTypes: z.array(z.string()).optional(),
orderByColumn: z.enum(['createdAt', 'type']).optional(),
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
});

View File

@ -20,6 +20,7 @@ export const findEnvelopeAuditLogsRoute = authenticatedProcedure
envelopeId,
cursor,
filterForRecentActivity,
eventTypes,
orderByColumn,
orderByDirection,
} = input;
@ -38,6 +39,7 @@ export const findEnvelopeAuditLogsRoute = authenticatedProcedure
envelopeId,
cursor,
filterForRecentActivity,
eventTypes,
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
});
});

View File

@ -22,6 +22,10 @@ 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'),
});