diff --git a/packages/services/evolution-service/src/analytics/adapters/inbound/audit.controller.ts b/packages/services/evolution-service/src/analytics/adapters/inbound/audit.controller.ts index 0d6c1ff..1207ff4 100644 --- a/packages/services/evolution-service/src/analytics/adapters/inbound/audit.controller.ts +++ b/packages/services/evolution-service/src/analytics/adapters/inbound/audit.controller.ts @@ -76,23 +76,59 @@ export class AuditController { } /** - * GET /audit/logs/:id - * Get single audit log detail + * GET /audit/logs/actions + * Get list of available action types + * NOTE: This must be defined BEFORE logs/:id to avoid route collision */ - @Get('logs/:id') - async getAuditLogDetail( + @Get('logs/actions') + async getActionTypes( @Headers('authorization') auth: string, - @Param('id') id: string, - ): Promise { + ): Promise<{ actions: string[] }> { await this.verifyAdmin(auth); - const log = await this.auditLogService.getLog(id); + // Common action types + return { + actions: [ + 'CREATE', + 'UPDATE', + 'DELETE', + 'LOGIN', + 'LOGOUT', + 'PAYMENT', + 'REFUND', + 'EXPORT', + 'IMPORT', + 'DAILY_STATS_AGGREGATION', + 'MONTHLY_REPORT_GENERATION', + ], + }; + } - if (!log) { - throw new NotFoundException('Audit log not found'); - } + /** + * GET /audit/logs/entity-types + * Get list of entity types + * NOTE: This must be defined BEFORE logs/:id to avoid route collision + */ + @Get('logs/entity-types') + async getEntityTypes( + @Headers('authorization') auth: string, + ): Promise<{ entityTypes: string[] }> { + await this.verifyAdmin(auth); - return log; + return { + entityTypes: [ + 'User', + 'Conversation', + 'Message', + 'Order', + 'Payment', + 'Admin', + 'KnowledgeArticle', + 'Experience', + 'DailyStatistics', + 'MonthlyFinancialReport', + ], + }; } /** @@ -130,56 +166,23 @@ export class AuditController { } /** - * GET /audit/logs/actions - * Get list of available action types + * GET /audit/logs/:id + * Get single audit log detail + * NOTE: This must be defined LAST to avoid matching "actions", "entity-types", etc. as :id */ - @Get('logs/actions') - async getActionTypes( + @Get('logs/:id') + async getAuditLogDetail( @Headers('authorization') auth: string, - ): Promise<{ actions: string[] }> { + @Param('id') id: string, + ): Promise { await this.verifyAdmin(auth); - // Common action types - return { - actions: [ - 'CREATE', - 'UPDATE', - 'DELETE', - 'LOGIN', - 'LOGOUT', - 'PAYMENT', - 'REFUND', - 'EXPORT', - 'IMPORT', - 'DAILY_STATS_AGGREGATION', - 'MONTHLY_REPORT_GENERATION', - ], - }; - } + const log = await this.auditLogService.getLog(id); - /** - * GET /audit/logs/entity-types - * Get list of entity types - */ - @Get('logs/entity-types') - async getEntityTypes( - @Headers('authorization') auth: string, - ): Promise<{ entityTypes: string[] }> { - await this.verifyAdmin(auth); + if (!log) { + throw new NotFoundException('Audit log not found'); + } - return { - entityTypes: [ - 'User', - 'Conversation', - 'Message', - 'Order', - 'Payment', - 'Admin', - 'KnowledgeArticle', - 'Experience', - 'DailyStatistics', - 'MonthlyFinancialReport', - ], - }; + return log; } }