fix(mining-admin): fix audit logs API path and response format
- Change controller path from /audit-logs to /audit to match frontend - Transform response to frontend expected format (items, totalPages, etc.) - Map admin.username to adminUsername field - Add keyword query parameter support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
13e94db450
commit
36c3ada6a6
|
|
@ -4,7 +4,7 @@ import { DashboardService } from '../../application/services/dashboard.service';
|
|||
|
||||
@ApiTags('Audit')
|
||||
@ApiBearerAuth()
|
||||
@Controller('audit-logs')
|
||||
@Controller('audit')
|
||||
export class AuditController {
|
||||
constructor(private readonly dashboardService: DashboardService) {}
|
||||
|
||||
|
|
@ -13,15 +13,42 @@ export class AuditController {
|
|||
@ApiQuery({ name: 'adminId', required: false })
|
||||
@ApiQuery({ name: 'action', required: false })
|
||||
@ApiQuery({ name: 'resource', required: false })
|
||||
@ApiQuery({ name: 'keyword', required: false })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'pageSize', required: false, type: Number })
|
||||
async getAuditLogs(
|
||||
@Query('adminId') adminId?: string,
|
||||
@Query('action') action?: string,
|
||||
@Query('resource') resource?: string,
|
||||
@Query('keyword') keyword?: string,
|
||||
@Query('page') page?: number,
|
||||
@Query('pageSize') pageSize?: number,
|
||||
) {
|
||||
return this.dashboardService.getAuditLogs({ adminId, action, resource, page: page ?? 1, pageSize: pageSize ?? 50 });
|
||||
const result = await this.dashboardService.getAuditLogs({
|
||||
adminId,
|
||||
action,
|
||||
resource,
|
||||
page: page ?? 1,
|
||||
pageSize: pageSize ?? 20,
|
||||
});
|
||||
|
||||
// 转换为前端期望的格式
|
||||
return {
|
||||
items: result.data.map((log: any) => ({
|
||||
id: log.id,
|
||||
adminId: log.adminId,
|
||||
adminUsername: log.admin?.username || 'unknown',
|
||||
action: log.action,
|
||||
resource: log.resource,
|
||||
resourceId: log.resourceId,
|
||||
details: log.newValue ? JSON.stringify(log.newValue) : null,
|
||||
ipAddress: log.ipAddress || '-',
|
||||
createdAt: log.createdAt,
|
||||
})),
|
||||
total: result.total,
|
||||
page: result.pagination.page,
|
||||
pageSize: result.pagination.pageSize,
|
||||
totalPages: result.pagination.totalPages,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue