-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat: add initial AuditLogService and /audit-logs API endpoint #22578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@ParagGhatage is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce a basic audit logging system for team or organization user activities. New type definitions for audit log actions and events are added. An Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope functional code changes were found. All changes are directly related to implementing the audit logging functionality as described in the linked issue. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details:
|
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/17/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add community label" took an action on this PR • (07/17/25)1 label was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (6)
apps/api/v1/lib/audit-log.service.ts (1)
9-9
: Fix typo in comment.The comment contains a typo: "Expty" should be "Empty".
- // Returning Expty array for now + // Returning Empty array for nowapps/api/v1/lib/helpers/audit-log.ts (1)
4-6
: Consider function naming convention and utility.The function name
EmitAuditLogEvent
uses PascalCase, which is typically reserved for classes/constructors in JavaScript/TypeScript. Consider using camelCase. Also, evaluate if this wrapper function adds sufficient value or if direct service calls would be more appropriate.-export async function EmitAuditLogEvent(event: AuditLogEvent) { +export async function emitAuditLogEvent(event: AuditLogEvent) { await AuditLogService.logEvent(event); }Alternatively, consider whether this wrapper is necessary or if calling
AuditLogService.logEvent
directly would be more straightforward.apps/api/v1/pages/api/audit-logs/_get.ts (2)
19-19
: Remove unnecessary optional chaining.The optional chaining operator (
?.
) is unnecessary sinceAuditLogService.getEvents
is a defined method. This could indicate uncertainty about the API or be a remnant from development.- const events: AuditLogEvent[] = await AuditLogService.getEvents?.(filter); + const events: AuditLogEvent[] = await AuditLogService.getEvents(filter);
18-26
: Consider more specific error handling.While the current error handling is functional, you might consider logging the original error for debugging purposes while still providing a clean response to the client.
try { const events: AuditLogEvent[] = await AuditLogService.getEvents(filter); return res.status(200).json({ events }); } catch (error) { + console.error("Error fetching audit logs:", error); throw new HttpError({ statusCode: 500, message: "Failed to fetch audit logs", }); }
apps/api/v1/pages/api/audit-logs/_post.ts (1)
10-16
: Consider more robust type validation.While the current validation checks for object presence, consider adding more specific type validation for the request body to ensure it matches the expected structure more closely.
const body = req.body as Partial<AuditLogEvent>; - if (!body || typeof body !== "object") { + if (!body || typeof body !== "object" || Array.isArray(body)) { throw new HttpError({ statusCode: 400, message: "Invalid/Missing JSON body", }); }apps/api/v1/lib/types.ts (1)
149-150
: Consider improving comment formatting and expanding action types.The comment format should be consistent with the rest of the file. Also, consider if the current action types cover all necessary team audit scenarios.
-//Audit Logs for Teams +// Audit Logs for TeamsAdditionally, you might want to consider adding more specific actions like "EDIT", "INVITE", "REMOVE_MEMBER", etc., based on your team management requirements.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/api/v1/lib/audit-log.service.ts
(1 hunks)apps/api/v1/lib/helpers/audit-log.ts
(1 hunks)apps/api/v1/lib/types.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/_get.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/_post.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/index.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
apps/api/v1/lib/audit-log.service.ts (2)
packages/trpc/server/routers/publicViewer/procedures/event.ts (1)
event
(8-12)apps/api/v1/lib/types.ts (1)
AuditLogEvent
(152-159)
apps/api/v1/pages/api/audit-logs/index.ts (2)
apps/api/v1/lib/helpers/withMiddleware.ts (1)
withMiddleware
(54-54)packages/lib/server/defaultHandler.ts (1)
defaultHandler
(8-24)
apps/api/v1/lib/helpers/audit-log.ts (2)
apps/api/v1/lib/types.ts (1)
AuditLogEvent
(152-159)apps/api/v1/lib/audit-log.service.ts (1)
AuditLogService
(3-12)
apps/api/v1/pages/api/audit-logs/_post.ts (3)
apps/api/v1/lib/types.ts (1)
AuditLogEvent
(152-159)apps/api/v1/lib/audit-log.service.ts (1)
AuditLogService
(3-12)packages/lib/server/defaultResponder.ts (1)
defaultResponder
(11-42)
🪛 Biome (1.9.4)
apps/api/v1/pages/api/audit-logs/_post.ts
[error] 33-33: The catch clause that only rethrows the original error is useless.
An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.
(lint/complexity/noUselessCatch)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Install dependencies / Yarn install & cache
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Security Check
🔇 Additional comments (3)
apps/api/v1/pages/api/audit-logs/index.ts (1)
5-10
: Clean API route implementation.The implementation follows established patterns with proper middleware integration and HTTP method delegation. The structure is clean and maintainable.
apps/api/v1/pages/api/audit-logs/_get.ts (1)
12-16
: Well-implemented query parameter filtering.The type checking and filtering logic for query parameters is well-implemented, ensuring only string values are passed to the service while filtering out undefined values.
apps/api/v1/pages/api/audit-logs/_post.ts (1)
18-27
: Well-implemented field validation.The validation logic for required fields is thorough and provides clear error messages. The approach of iterating through required fields and checking each one is clean and maintainable.
async logEvent(event: AuditLogEvent): Promise<void> { | ||
console.log("Audit Log Event:", event); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider production-ready logging implementation.
Console logging is not suitable for production environments. Consider implementing proper structured logging with log levels, error handling, and persistence.
- async logEvent(event: AuditLogEvent): Promise<void> {
- console.log("Audit Log Event:", event);
- },
+ async logEvent(event: AuditLogEvent): Promise<void> {
+ try {
+ // TODO: Implement proper logging mechanism (database, external service, etc.)
+ console.log("Audit Log Event:", event);
+
+ // Future implementation might include:
+ // - Database persistence
+ // - External audit service integration
+ // - Structured logging with proper log levels
+ } catch (error) {
+ console.error("Failed to log audit event:", error);
+ // Consider whether to throw or handle gracefully
+ }
+ },
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async logEvent(event: AuditLogEvent): Promise<void> { | |
console.log("Audit Log Event:", event); | |
}, | |
async logEvent(event: AuditLogEvent): Promise<void> { | |
try { | |
// TODO: Implement proper logging mechanism (database, external service, etc.) | |
console.log("Audit Log Event:", event); | |
// Future implementation might include: | |
// - Database persistence | |
// - External audit service integration | |
// - Structured logging with proper log levels | |
} catch (error) { | |
console.error("Failed to log audit event:", error); | |
// Consider whether to throw or handle gracefully | |
} | |
}, |
🤖 Prompt for AI Agents
In apps/api/v1/lib/audit-log.service.ts around lines 4 to 6, replace the
console.log statement with a production-ready logging solution. Integrate a
structured logger that supports log levels (e.g., info, error), handles errors
gracefully, and persists logs to a file or external logging service. Ensure the
logger formats the event data clearly and can be configured for different
environments.
async getEvents(filter?: any): Promise<AuditLogEvent[]> { | ||
// Returning Expty array for now | ||
return []; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve type safety for filter parameter.
The filter
parameter is typed as any
, which reduces type safety. Consider defining a proper filter interface or use a more specific type.
+interface AuditLogFilter {
+ orgId?: string;
+ userId?: string;
+ action?: string;
+ [key: string]: any;
+}
+
- async getEvents(filter?: any): Promise<AuditLogEvent[]> {
+ async getEvents(filter?: AuditLogFilter): Promise<AuditLogEvent[]> {
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async getEvents(filter?: any): Promise<AuditLogEvent[]> { | |
// Returning Expty array for now | |
return []; | |
}, | |
interface AuditLogFilter { | |
orgId?: string; | |
userId?: string; | |
action?: string; | |
[key: string]: any; | |
} | |
async getEvents(filter?: AuditLogFilter): Promise<AuditLogEvent[]> { | |
// Returning Expty array for now | |
return []; | |
}, |
🤖 Prompt for AI Agents
In apps/api/v1/lib/audit-log.service.ts around lines 8 to 11, the filter
parameter in the getEvents method is typed as any, which reduces type safety.
Define a specific interface or type that describes the expected structure of the
filter object and update the method signature to use this type instead of any to
improve type safety and code clarity.
export async function EmitAuditLogEvent(event: AuditLogEvent) { | ||
await AuditLogService.logEvent(event); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling to the wrapper function.
The wrapper function should handle potential errors from the underlying service call, especially since audit logging failures shouldn't typically break the main application flow.
-export async function EmitAuditLogEvent(event: AuditLogEvent) {
- await AuditLogService.logEvent(event);
-}
+export async function EmitAuditLogEvent(event: AuditLogEvent) {
+ try {
+ await AuditLogService.logEvent(event);
+ } catch (error) {
+ console.error("Failed to emit audit log event:", error);
+ // Consider whether to throw or handle gracefully based on requirements
+ }
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export async function EmitAuditLogEvent(event: AuditLogEvent) { | |
await AuditLogService.logEvent(event); | |
} | |
export async function EmitAuditLogEvent(event: AuditLogEvent) { | |
try { | |
await AuditLogService.logEvent(event); | |
} catch (error) { | |
console.error("Failed to emit audit log event:", error); | |
// Consider whether to throw or handle gracefully based on requirements | |
} | |
} |
🤖 Prompt for AI Agents
In apps/api/v1/lib/helpers/audit-log.ts around lines 4 to 6, the
EmitAuditLogEvent function lacks error handling for the awaited
AuditLogService.logEvent call. Wrap the await call in a try-catch block to catch
any errors thrown by logEvent, and handle them gracefully, such as logging the
error without rethrowing, to prevent audit logging failures from affecting the
main application flow.
try { | ||
await AuditLogService.logEvent(body as AuditLogEvent); | ||
return res.status(201).json({ ok: true }); | ||
} catch (error: unknown) { | ||
throw error; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unnecessary try/catch clause.
The try/catch block that only rethrows the original error is unnecessary and can be confusing. The defaultResponder
wrapper already handles error catching and response formatting.
- try {
- await AuditLogService.logEvent(body as AuditLogEvent);
- return res.status(201).json({ ok: true });
- } catch (error: unknown) {
- throw error;
- }
+ await AuditLogService.logEvent(body as AuditLogEvent);
+ return res.status(201).json({ ok: true });
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
try { | |
await AuditLogService.logEvent(body as AuditLogEvent); | |
return res.status(201).json({ ok: true }); | |
} catch (error: unknown) { | |
throw error; | |
} | |
await AuditLogService.logEvent(body as AuditLogEvent); | |
return res.status(201).json({ ok: true }); |
🧰 Tools
🪛 Biome (1.9.4)
[error] 33-33: The catch clause that only rethrows the original error is useless.
An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.
(lint/complexity/noUselessCatch)
🤖 Prompt for AI Agents
In apps/api/v1/pages/api/audit-logs/_post.ts around lines 29 to 34, remove the
try/catch block that only rethrows the error because it is redundant. The
defaultResponder wrapper already manages error catching and response formatting,
so simply call AuditLogService.logEvent and return the success response without
the try/catch.
export interface AuditLogEvent { | ||
timestamp: string; | ||
userId: string; | ||
orgId: string; | ||
action: AuditLogAction; | ||
resource: string; | ||
details: Record<string, any>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address interface inconsistencies and improve type safety.
The AuditLogEvent
interface has several concerns:
- Missing fields: The PR objectives mention
id
,teamId
, anddescription
fields that are not present in this interface. - Type safety: The
details
field usesRecord<string, any>
which reduces type safety. - Field naming: Consider using
resourceId
instead ofresource
for clarity.
export interface AuditLogEvent {
+ id: string;
timestamp: string;
userId: string;
orgId: string;
+ teamId?: string;
action: AuditLogAction;
- resource: string;
+ resourceId: string;
+ resourceType: string;
+ description?: string;
- details: Record<string, any>;
+ details: Record<string, unknown>;
}
The details
field should use unknown
instead of any
for better type safety, or consider defining specific detail types for different actions.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export interface AuditLogEvent { | |
timestamp: string; | |
userId: string; | |
orgId: string; | |
action: AuditLogAction; | |
resource: string; | |
details: Record<string, any>; | |
} | |
export interface AuditLogEvent { | |
id: string; | |
timestamp: string; | |
userId: string; | |
orgId: string; | |
teamId?: string; | |
action: AuditLogAction; | |
resourceId: string; | |
resourceType: string; | |
description?: string; | |
details: Record<string, unknown>; | |
} |
🤖 Prompt for AI Agents
In apps/api/v1/lib/types.ts around lines 152 to 159, update the AuditLogEvent
interface to include the missing fields id, teamId, and description as specified
in the PR objectives. Rename the resource field to resourceId for clearer
semantics. Replace the details field type from Record<string, any> to
Record<string, unknown> to improve type safety, or alternatively define specific
types for details based on different AuditLogAction values to enforce stricter
typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
apps/api/v1/lib/helpers/audit-log.ts (1)
4-6
: Consider using camelCase for function names and add error handling documentation.The function name
EmitAuditLogEvent
uses PascalCase, which is unconventional for function names in JavaScript/TypeScript. Consider renaming toemitAuditLogEvent
to follow standard naming conventions.Additionally, since this function doesn't handle errors from
AuditLogService.logEvent
, consider documenting that errors will propagate to the caller.-export async function EmitAuditLogEvent(event: AuditLogEvent) { +/** + * Emits an audit log event. Errors from the underlying service will propagate to the caller. + */ +export async function emitAuditLogEvent(event: AuditLogEvent) { await AuditLogService.logEvent(event); }apps/api/v1/lib/audit-log.service.ts (1)
8-11
: Fix typo in comment.There's a typo in the comment on line 9.
- // Returning Expty array for now + // Returning Empty array for nowapps/api/v1/pages/api/audit-logs/_get.ts (2)
19-19
: Remove unnecessary optional chaining.The optional chaining operator (
?.
) is unnecessary here sincegetEvents
is a defined method on theAuditLogService
object.- const events: AuditLogEvent[] = await AuditLogService.getEvents?.(filter); + const events: AuditLogEvent[] = await AuditLogService.getEvents(filter);
18-26
: Consider improving error handling to preserve error details.The current error handling catches all errors and throws a generic 500 error, which might mask important error details useful for debugging. Consider either removing the try-catch block to let
defaultResponder
handle errors, or preserving the original error details.Option 1 - Remove try-catch and let defaultResponder handle errors:
- try { - const events: AuditLogEvent[] = await AuditLogService.getEvents?.(filter); - return res.status(200).json({ events }); - } catch (error) { - throw new HttpError({ - statusCode: 500, - message: "Failed to fetch audit logs", - }); - } + const events: AuditLogEvent[] = await AuditLogService.getEvents(filter); + return res.status(200).json({ events });Option 2 - Preserve original error details:
} catch (error) { + console.error("Failed to fetch audit logs:", error); throw new HttpError({ statusCode: 500, - message: "Failed to fetch audit logs", + message: `Failed to fetch audit logs: ${error instanceof Error ? error.message : 'Unknown error'}`, }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/api/v1/lib/audit-log.service.ts
(1 hunks)apps/api/v1/lib/helpers/audit-log.ts
(1 hunks)apps/api/v1/lib/types.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/_get.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/_post.ts
(1 hunks)apps/api/v1/pages/api/audit-logs/index.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
apps/api/v1/pages/api/audit-logs/index.ts (2)
apps/api/v1/lib/helpers/withMiddleware.ts (1)
withMiddleware
(54-54)packages/lib/server/defaultHandler.ts (1)
defaultHandler
(8-24)
apps/api/v1/lib/audit-log.service.ts (2)
packages/trpc/server/routers/publicViewer/procedures/event.ts (1)
event
(8-12)apps/api/v1/lib/types.ts (1)
AuditLogEvent
(152-159)
apps/api/v1/pages/api/audit-logs/_get.ts (3)
apps/api/v1/lib/types.ts (1)
AuditLogEvent
(152-159)apps/api/v1/lib/audit-log.service.ts (1)
AuditLogService
(3-12)packages/lib/server/defaultResponder.ts (1)
defaultResponder
(11-42)
🪛 Biome (1.9.4)
apps/api/v1/pages/api/audit-logs/_post.ts
[error] 33-33: The catch clause that only rethrows the original error is useless.
An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.
(lint/complexity/noUselessCatch)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Linters / lint
- GitHub Check: Tests / Unit
- GitHub Check: Type check / check-types
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Security Check
🔇 Additional comments (6)
apps/api/v1/pages/api/audit-logs/index.ts (1)
5-10
: LGTM! Well-structured API route setup.The implementation follows good practices:
- Uses dynamic imports for code splitting
- Separates concerns with middleware wrapper
- Delegates to method-specific handlers
- Leverages the existing
defaultHandler
patternapps/api/v1/lib/audit-log.service.ts (1)
4-6
: LGTM! Appropriate placeholder implementation for initial development.The console logging approach is suitable for the initial audit log system setup. This aligns with the PR objectives to establish the foundational components.
apps/api/v1/pages/api/audit-logs/_post.ts (2)
10-16
: LGTM! Proper request body validation.The validation correctly checks for the presence and type of the request body, with appropriate error handling using HTTP 400 status codes.
18-27
: LGTM! Comprehensive field validation with clear error messages.The dynamic field validation approach is maintainable and provides clear feedback about missing required fields.
apps/api/v1/pages/api/audit-logs/_get.ts (1)
10-16
: LGTM! Proper query parameter handling.The implementation correctly handles Next.js query parameters, which can be strings or arrays, and builds an appropriate filter object with type safety.
apps/api/v1/lib/types.ts (1)
150-150
: LGTM! Well-defined audit action types.The string literal union type provides good type safety and covers the essential actions for a calendar/booking system audit log.
try { | ||
await AuditLogService.logEvent(body as AuditLogEvent); | ||
return res.status(201).json({ ok: true }); | ||
} catch (error: unknown) { | ||
throw error; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unnecessary try-catch block.
The catch clause only rethrows the original error without adding any value. Since the defaultResponder
wrapper already handles errors appropriately, this try-catch block is unnecessary.
- try {
- await AuditLogService.logEvent(body as AuditLogEvent);
- return res.status(201).json({ ok: true });
- } catch (error: unknown) {
- throw error;
- }
+ await AuditLogService.logEvent(body as AuditLogEvent);
+ return res.status(201).json({ ok: true });
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
try { | |
await AuditLogService.logEvent(body as AuditLogEvent); | |
return res.status(201).json({ ok: true }); | |
} catch (error: unknown) { | |
throw error; | |
} | |
} | |
await AuditLogService.logEvent(body as AuditLogEvent); | |
return res.status(201).json({ ok: true }); | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 33-33: The catch clause that only rethrows the original error is useless.
An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.
(lint/complexity/noUselessCatch)
🤖 Prompt for AI Agents
In apps/api/v1/pages/api/audit-logs/_post.ts around lines 29 to 35, remove the
try-catch block that wraps the call to AuditLogService.logEvent because the
catch block only rethrows the error without any additional handling. Since error
handling is already managed by the defaultResponder wrapper, simply call
AuditLogService.logEvent and return the response without the try-catch.
export interface AuditLogEvent { | ||
timestamp: string; | ||
userId: string; | ||
orgId: string; | ||
action: AuditLogAction; | ||
resource: string; | ||
details: Record<string, any>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interface definition needs alignment with PR objectives.
The interface is missing several fields mentioned in the PR objectives and has some type considerations:
- Missing fields: The PR objectives mention
id
,teamId
, anddescription
fields that are not present in the interface. - Timestamp type: Consider using
Date
type or specifying the string format (e.g., ISO 8601). - Optional properties: Consider making some fields optional (e.g.,
orgId
,details
) for flexibility.
Apply this diff to align with PR objectives:
export interface AuditLogEvent {
+ id: string;
- timestamp: string;
+ timestamp: Date;
userId: string;
- orgId: string;
+ orgId?: string;
+ teamId?: string;
action: AuditLogAction;
resource: string;
+ description?: string;
- details: Record<string, any>;
+ details?: Record<string, any>;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export interface AuditLogEvent { | |
timestamp: string; | |
userId: string; | |
orgId: string; | |
action: AuditLogAction; | |
resource: string; | |
details: Record<string, any>; | |
} | |
export interface AuditLogEvent { | |
id: string; | |
timestamp: Date; | |
userId: string; | |
orgId?: string; | |
teamId?: string; | |
action: AuditLogAction; | |
resource: string; | |
description?: string; | |
details?: Record<string, any>; | |
} |
🤖 Prompt for AI Agents
In apps/api/v1/lib/types.ts around lines 152 to 159, the AuditLogEvent interface
is missing the id, teamId, and description fields as required by the PR
objectives. Update the interface to include these fields, change the timestamp
type to Date or specify its string format explicitly, and make orgId and details
optional properties to increase flexibility.
17027df
to
f3c7256
Compare
5cc3e5d
to
7d2b2af
Compare
7d2b2af
to
df5db16
Compare
…m createInstantBooking method
This PR is being marked as stale due to inactivity. |
What does this PR do?
This PR introduces the initial groundwork for an Audit Log system.
Changes Introduced:
logEvent
that logs actions/events to the Console (For now).getEvents
function for future listing of audit events.AuditLogEvent
interface with fields:id
,orgId
,teamId
,userId
,action
,description
,timestamp
.Visual Demo
Since this is just a backend utility setup and there is no UI impact, no video/image is provided. Future commits will demonstrate visual changes (if any).
Overall flow:
Implementation till now:
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
getEvents
returns the dummy mocked data (for now).Test Config