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:
57
apps/api/dist/routes/tracking.routes.js
vendored
57
apps/api/dist/routes/tracking.routes.js
vendored
@@ -264,17 +264,66 @@ router.get('/projects/:projectId/checks', auth_middleware_1.requireAuth, async (
|
||||
router.get('/checks/recent', auth_middleware_1.requireAuth, async (req, res) => {
|
||||
try {
|
||||
const { limit = 20 } = req.query;
|
||||
const checks = await redirectTracker.listChecks('anonymous-project', Number(limit), 0);
|
||||
const userId = req.user.id;
|
||||
const checks = await prisma_1.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)
|
||||
});
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user