fix: docs
This commit is contained in:
@@ -197,21 +197,23 @@ export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
if (!monitor) { set.status = 404; return { error: "Not found" }; }
|
||||
|
||||
const limit = Math.min(Number(query.limit) || 100, 1000);
|
||||
const skip = Math.max(0, Math.floor(Number(query.skip) || 0));
|
||||
const filter = query.filter; // "up", "down", "events", or undefined/all
|
||||
const before = query.before; // cursor: ISO timestamp for pagination
|
||||
const before = query.before ? Number(query.before) * 1000 : null; // unix timestamp (seconds) -> ms
|
||||
|
||||
const cursorClause = before ? sql`AND checked_at < ${new Date(before)}` : sql``;
|
||||
const offsetClause = skip > 0 ? sql`OFFSET ${skip}` : sql``;
|
||||
|
||||
if (filter === "up") {
|
||||
return sql`
|
||||
SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = true ${cursorClause}
|
||||
ORDER BY checked_at DESC LIMIT ${limit}
|
||||
ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause}
|
||||
`;
|
||||
}
|
||||
if (filter === "down") {
|
||||
return sql`
|
||||
SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = false ${cursorClause}
|
||||
ORDER BY checked_at DESC LIMIT ${limit}
|
||||
ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause}
|
||||
`;
|
||||
}
|
||||
if (filter === "events") {
|
||||
@@ -222,12 +224,12 @@ export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
) t
|
||||
WHERE prev_up IS NULL OR up != prev_up
|
||||
${before ? sql`AND checked_at < ${new Date(before)}` : sql``}
|
||||
ORDER BY checked_at DESC LIMIT ${limit}
|
||||
ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause}
|
||||
`;
|
||||
}
|
||||
|
||||
return sql`
|
||||
SELECT * FROM pings WHERE monitor_id = ${params.id} ${cursorClause}
|
||||
ORDER BY checked_at DESC LIMIT ${limit}
|
||||
ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause}
|
||||
`;
|
||||
}, { detail: { summary: "Get ping history", tags: ["monitors"] } });
|
||||
|
||||
Reference in New Issue
Block a user