fix: remediate dashboard API integration review blockers (#459)
- Fix race condition: guard useEffect when workspaceId is null, prevent infinite loading state by setting isLoading=false on null workspace - Fix TypeScript strict typing: @Workspace() returns string|undefined, controller now matches with BadRequestException guard - Narrow details DTO type from unknown to Record<string, unknown>|null - Add error state UI for API fetch failures - Add error-path test with static mock import pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Controller, Get, UseGuards } from "@nestjs/common";
|
||||
import { Controller, Get, UseGuards, BadRequestException } from "@nestjs/common";
|
||||
import { DashboardService } from "./dashboard.service";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
import { WorkspaceGuard, PermissionGuard } from "../common/guards";
|
||||
import { Workspace, Permission, RequirePermission } from "../common/decorators";
|
||||
import type { DashboardSummaryDto } from "./dto";
|
||||
|
||||
/**
|
||||
* Controller for dashboard endpoints.
|
||||
@@ -25,7 +26,10 @@ export class DashboardController {
|
||||
*/
|
||||
@Get("summary")
|
||||
@RequirePermission(Permission.WORKSPACE_ANY)
|
||||
async getSummary(@Workspace() workspaceId: string) {
|
||||
async getSummary(@Workspace() workspaceId: string | undefined): Promise<DashboardSummaryDto> {
|
||||
if (!workspaceId) {
|
||||
throw new BadRequestException("Workspace context required");
|
||||
}
|
||||
return this.dashboardService.getSummary(workspaceId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export class DashboardService {
|
||||
action: row.action,
|
||||
entityType: row.entityType,
|
||||
entityId: row.entityId,
|
||||
details: row.details,
|
||||
details: row.details as Record<string, unknown> | null,
|
||||
userId: row.userId,
|
||||
createdAt: row.createdAt.toISOString(),
|
||||
}));
|
||||
|
||||
@@ -17,7 +17,7 @@ export class RecentActivityDto {
|
||||
action!: string;
|
||||
entityType!: string;
|
||||
entityId!: string;
|
||||
details!: unknown;
|
||||
details!: Record<string, unknown> | null;
|
||||
userId!: string;
|
||||
createdAt!: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user