Implement recent checks API endpoint for dashboard

- Replace placeholder implementation with real database query
- Add cross-project checks retrieval for authenticated users
- Include detailed check information with hops, timing, and metadata
- Add proper database joins across checks → projects → organizations → memberships
- Format response to match frontend expectations
- Rebuild API with updated implementation

Fixes dashboard checks history display - now shows real tracking data instead of empty placeholder
This commit is contained in:
Andrei
2025-08-23 20:05:33 +00:00
parent 634636a03e
commit 67fe4f9c00
5 changed files with 174 additions and 16 deletions

View File

@@ -350,25 +350,71 @@ router.get('/checks/recent',
async (req: AuthenticatedRequest, res) => {
try {
const { limit = 20 } = req.query;
const userId = req.user!.id;
// TODO: Implement cross-project recent checks in future phases
// For Phase 2, return checks from anonymous project as placeholder
const checks = await redirectTracker.listChecks(
'anonymous-project',
Number(limit),
0
);
// Get all checks for the user across all their projects
const checks = await prisma.check.findMany({
where: {
project: {
organization: {
memberships: {
some: {
userId: userId
}
}
}
}
},
include: {
project: {
select: {
name: true
}
},
hops: {
orderBy: {
hopIndex: 'asc'
}
}
},
orderBy: {
startedAt: 'desc'
},
take: Number(limit)
});
// Format the checks to match the expected response format
const formattedChecks = checks.map(check => ({
id: check.id,
inputUrl: check.inputUrl,
finalUrl: check.finalUrl,
method: check.method,
status: check.status,
startedAt: check.startedAt,
finishedAt: check.finishedAt,
totalTimeMs: check.totalTimeMs,
redirectCount: check.hops.length,
projectName: check.project.name,
hops: check.hops.map(hop => ({
hopIndex: hop.hopIndex,
url: hop.url,
statusCode: hop.statusCode,
redirectType: hop.redirectType,
latencyMs: hop.latencyMs,
contentType: hop.contentType
}))
}));
res.json({
success: true,
status: 200,
data: {
checks,
message: 'Cross-project recent checks will be implemented in a future phase'
checks: formattedChecks
},
meta: {
version: 'v2',
userId: req.user!.id,
userId: userId,
total: formattedChecks.length
}
});