mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 05:32:12 +10:00
feat: filter by audit log event type
This commit is contained in:
@ -20,6 +20,7 @@ export interface FindDocumentAuditLogsOptions {
|
|||||||
};
|
};
|
||||||
cursor?: string;
|
cursor?: string;
|
||||||
filterForRecentActivity?: boolean;
|
filterForRecentActivity?: boolean;
|
||||||
|
eventTypes?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findDocumentAuditLogs = async ({
|
export const findDocumentAuditLogs = async ({
|
||||||
@ -31,6 +32,7 @@ export const findDocumentAuditLogs = async ({
|
|||||||
orderBy,
|
orderBy,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
}: FindDocumentAuditLogsOptions) => {
|
}: FindDocumentAuditLogsOptions) => {
|
||||||
const orderByColumn = orderBy?.column ?? 'createdAt';
|
const orderByColumn = orderBy?.column ?? 'createdAt';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
@ -57,7 +59,12 @@ export const findDocumentAuditLogs = async ({
|
|||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter events down to what we consider recent activity.
|
if (eventTypes && eventTypes.length > 0) {
|
||||||
|
whereClause.type = {
|
||||||
|
in: eventTypes,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (filterForRecentActivity) {
|
if (filterForRecentActivity) {
|
||||||
whereClause.OR = [
|
whereClause.OR = [
|
||||||
{
|
{
|
||||||
@ -130,6 +137,7 @@ export interface FindEnvelopeAuditLogsOptions {
|
|||||||
};
|
};
|
||||||
cursor?: string;
|
cursor?: string;
|
||||||
filterForRecentActivity?: boolean;
|
filterForRecentActivity?: boolean;
|
||||||
|
eventTypes?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findEnvelopeAuditLogs = async ({
|
export const findEnvelopeAuditLogs = async ({
|
||||||
@ -141,11 +149,11 @@ export const findEnvelopeAuditLogs = async ({
|
|||||||
orderBy,
|
orderBy,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
}: FindEnvelopeAuditLogsOptions) => {
|
}: FindEnvelopeAuditLogsOptions) => {
|
||||||
const orderByColumn = orderBy?.column ?? 'createdAt';
|
const orderByColumn = orderBy?.column ?? 'createdAt';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
|
|
||||||
// Auto-detect ID type: if it's a numeric string, treat as documentId
|
|
||||||
const isNumericId = /^\d+$/.test(envelopeId);
|
const isNumericId = /^\d+$/.test(envelopeId);
|
||||||
|
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
@ -175,7 +183,12 @@ export const findEnvelopeAuditLogs = async ({
|
|||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter events down to what we consider recent activity.
|
if (eventTypes && eventTypes.length > 0) {
|
||||||
|
whereClause.type = {
|
||||||
|
in: eventTypes,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (filterForRecentActivity) {
|
if (filterForRecentActivity) {
|
||||||
whereClause.OR = [
|
whereClause.OR = [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export const findDocumentAuditLogsRoute = authenticatedProcedure
|
|||||||
documentId,
|
documentId,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
orderByColumn,
|
orderByColumn,
|
||||||
orderByDirection,
|
orderByDirection,
|
||||||
} = input;
|
} = input;
|
||||||
@ -36,6 +37,7 @@ export const findDocumentAuditLogsRoute = authenticatedProcedure
|
|||||||
documentId,
|
documentId,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
|
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export const ZFindDocumentAuditLogsRequestSchema = ZFindSearchParamsSchema.exten
|
|||||||
documentId: z.number().min(1),
|
documentId: z.number().min(1),
|
||||||
cursor: z.string().optional(),
|
cursor: z.string().optional(),
|
||||||
filterForRecentActivity: z.boolean().optional(),
|
filterForRecentActivity: z.boolean().optional(),
|
||||||
|
eventTypes: z.array(z.string()).optional(),
|
||||||
orderByColumn: z.enum(['createdAt', 'type']).optional(),
|
orderByColumn: z.enum(['createdAt', 'type']).optional(),
|
||||||
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
|
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,6 +20,7 @@ export const findEnvelopeAuditLogsRoute = authenticatedProcedure
|
|||||||
envelopeId,
|
envelopeId,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
orderByColumn,
|
orderByColumn,
|
||||||
orderByDirection,
|
orderByDirection,
|
||||||
} = input;
|
} = input;
|
||||||
@ -38,6 +39,7 @@ export const findEnvelopeAuditLogsRoute = authenticatedProcedure
|
|||||||
envelopeId,
|
envelopeId,
|
||||||
cursor,
|
cursor,
|
||||||
filterForRecentActivity,
|
filterForRecentActivity,
|
||||||
|
eventTypes,
|
||||||
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
|
orderBy: orderByColumn ? { column: orderByColumn, direction: orderByDirection } : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -22,6 +22,10 @@ export const ZFindEnvelopeAuditLogsRequestSchema = ZFindSearchParamsSchema.exten
|
|||||||
.describe('Envelope ID (e.g., envelope_xxx) or legacy document ID (e.g., 12345)'),
|
.describe('Envelope ID (e.g., envelope_xxx) or legacy document ID (e.g., 12345)'),
|
||||||
cursor: z.string().optional(),
|
cursor: z.string().optional(),
|
||||||
filterForRecentActivity: z.boolean().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(),
|
orderByColumn: z.enum(['createdAt', 'type']).optional(),
|
||||||
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
|
orderByDirection: z.enum(['asc', 'desc']).default('desc'),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user